List of usage examples for java.util.concurrent.atomic AtomicInteger incrementAndGet
public final int incrementAndGet()
From source file:org.zenoss.zep.dao.impl.DaoUtilsTest.java
@Test public void testDeadlockRetryAllFailed() throws Exception { final AtomicInteger i = new AtomicInteger(); try {/*from www . j a va 2 s . co m*/ DaoUtils.deadlockRetry(new Callable<Integer>() { @Override public Integer call() throws Exception { throw new DeadlockLoserDataAccessException(String.valueOf(i.incrementAndGet()), null); } }); fail("Should have thrown an exception after 5 retries"); } catch (DeadlockLoserDataAccessException e) { assertEquals("5", e.getMessage()); } }
From source file:com.walmart.gatling.commons.ReportExecutor.java
private void runJob(Master.GenerateReport job) { TaskEvent taskEvent = job.reportJob.taskEvent; CommandLine cmdLine = new CommandLine(agentConfig.getJob().getCommand()); Map<String, Object> map = new HashMap<>(); map.put("path", new File(agentConfig.getJob().getJobArtifact(taskEvent.getJobName()))); cmdLine.addArgument("${path}"); //parameters come from the task event for (Pair<String, String> pair : taskEvent.getParameters()) { cmdLine.addArgument(pair.getValue()); }// w w w. j a v a 2 s.c o m String dir = agentConfig.getJob().getLogDirectory() + "reports/" + job.reportJob.trackingId + "/"; cmdLine.addArgument(dir); cmdLine.setSubstitutionMap(map); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValues(agentConfig.getJob().getExitValues()); ExecuteWatchdog watchdog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT); executor.setWatchdog(watchdog); executor.setWorkingDirectory(new File(agentConfig.getJob().getPath())); FileOutputStream outFile = null; FileOutputStream errorFile = null; try { List<String> resultFiles = new ArrayList<>(job.results.size()); //download all files adn /*int i=0; for (Worker.Result result : job.results) { String destFile = dir + i++ + ".log"; resultFiles.add(destFile); DownloadFile.downloadFile(result.metrics,destFile); }*/ AtomicInteger index = new AtomicInteger(); job.results.parallelStream().forEach(result -> { String destFile = dir + index.incrementAndGet() + ".log"; resultFiles.add(destFile); DownloadFile.downloadFile(result.metrics, destFile); }); String outPath = agentConfig.getJob().getOutPath(taskEvent.getJobName(), job.reportJob.trackingId); String errPath = agentConfig.getJob().getErrorPath(taskEvent.getJobName(), job.reportJob.trackingId); //create the std and err files outFile = FileUtils.openOutputStream(new File(outPath)); errorFile = FileUtils.openOutputStream(new File(errPath)); PumpStreamHandler psh = new PumpStreamHandler(new ExecLogHandler(outFile), new ExecLogHandler(errorFile)); executor.setStreamHandler(psh); System.out.println(cmdLine); int exitResult = executor.execute(cmdLine); ReportResult result; if (executor.isFailure(exitResult)) { result = new ReportResult(dir, job.reportJob, false); log.info("Report Executor Failed, result: " + job.toString()); } else { result = new ReportResult(job.reportJob.getHtml(), job.reportJob, true); log.info("Report Executor Completed, result: " + result.toString()); } for (String resultFile : resultFiles) { FileUtils.deleteQuietly(new File(resultFile)); } getSender().tell(result, getSelf()); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); } finally { IOUtils.closeQuietly(outFile); IOUtils.closeQuietly(errorFile); } }
From source file:net.sf.sessionAnalysis.SessionVisitorSessionLengthNumActionsStatistics.java
public void handleSession(Session session) { final int curLength = session.getSessionLengthNumActions(); AtomicInteger curFrequency = sessionLengthHistogram.get(curLength); if (curFrequency == null) { // session length not observed before curFrequency = new AtomicInteger(0); sessionLengthHistogram.put(curLength, curFrequency); }/* w w w . j a v a2 s .com*/ curFrequency.incrementAndGet(); }
From source file:strat.mining.multipool.stats.service.impl.RequestStatsLoggingServiceImpl.java
@Override public void currencyTicker(String exchangePlace, String currencyCode) { nbCurrencyTicker.incrementAndGet();/*from w ww.ja va2 s .co m*/ Map<String, AtomicInteger> currencies = currencyTickerRequest.get(exchangePlace); if (currencies == null) { currencies = Collections.synchronizedMap(new HashMap<String, AtomicInteger>()); currencyTickerRequest.put(exchangePlace, currencies); } AtomicInteger currencyCounter = currencies.get(currencyCode); if (currencyCounter == null) { currencyCounter = new AtomicInteger(0); currencies.put(currencyCode, currencyCounter); } currencyCounter.incrementAndGet(); }
From source file:net.sf.sessionAnalysis.SessionVisitorSessionLengthNanosStatistics.java
public void handleSession(Session session) { final long curLength = session.getSessionLengthNanos(); AtomicInteger curFrequency = sessionLengthHistogram.get(curLength); if (curFrequency == null) { // session length not observed before curFrequency = new AtomicInteger(0); sessionLengthHistogram.put(curLength, curFrequency); }//from w w w .j ava 2s . c o m curFrequency.incrementAndGet(); }
From source file:ufo.remote.calls.benchmark.client.caller.vertx.VertxClusterTester.java
@Override protected void startTest(final TesterResult result) { EventBus bus = vertx.eventBus();//from w ww . ja va 2s. c o m CountDownLatch latch = new CountDownLatch(result.totalCalls); AtomicInteger failures = new AtomicInteger(0); for (int i = 0; i < result.totalCalls; i++) { bus.send("echo", result.message, (AsyncResult<Message<String>> response) -> { if (response.failed()) { failures.incrementAndGet(); } if (logger.isDebugEnabled()) { logger.debug("Received [{}]", response.result().body()); } latch.countDown(); }); } try { latch.await(); } catch (InterruptedException e) { throw new RuntimeException(e); } result.failures = failures.get(); }
From source file:com.b5m.plugin.spout.MetaTestSpout.java
public MetaTestSpout(String url, String topic, String group) { this.url = url; this.topic = topic; this.group = group; MessageHelper helper = new MessageHelper(this.url); final AtomicInteger counter = new AtomicInteger(0); helper.Subscription(topic, group, new MessageListenerTemplate<Object>() { @Override/* w w w . j a va2 s . c o m*/ public void recieveData(Message Message, Object data) { counter.incrementAndGet(); clq.add(data); System.out.println("--->" + data); } }); }
From source file:ome.security.auth.LoginAttemptListener.java
public void onApplicationEvent(LoginAttemptMessage lam) { if (lam.success == null) { return; // EARLY EXIT. }/*from w w w .j a v a2 s . c o m*/ if (!counts.containsKey(lam.user)) { counts.putIfAbsent(lam.user, new AtomicInteger(0)); } AtomicInteger ai = counts.get(lam.user); if (lam.success) { int previous = ai.getAndSet(0); if (previous > 0) { log.info(String.format("Resetting failed login count of %s for %s", previous, lam.user)); } } else { int value = ai.incrementAndGet(); if (value > throttleCount) { log.warn( String.format("%s failed logins for %s. Throttling for %s", value, lam.user, throttleTime)); if (throttleTime > 0) { try { Thread.sleep(throttleTime); // TODO something nicer } catch (InterruptedException e) { log.debug("Interrupt while throttling for " + lam.user); } } } } }
From source file:org.jtheque.undo.UndoServiceTest.java
@Test @DirtiesContext/*from ww w .j a v a 2 s . c o m*/ public void listenerRemoved() { final AtomicInteger counter = new AtomicInteger(0); StateListener listener = new StateListener() { @Override public void stateChanged(String undoName, boolean canUndo, String redoName, boolean canRedo) { counter.incrementAndGet(); } }; undoService.addStateListener(listener); undoService.addEdit(new TestEdit(new AtomicInteger(0), new AtomicInteger(0))); undoService.removeStateListener(listener); undoService.addEdit(new TestEdit(new AtomicInteger(0), new AtomicInteger(0))); assertEquals(1, counter.intValue()); }
From source file:com.vladmihalcea.OptimisticLockingTest.java
@Test public void testRetries() throws InterruptedException { final Product product = productService.newProduct(); assertEquals(0, product.getVersion()); Product savedProduct = productService.updateName(product.getId(), "name"); assertEquals(1, savedProduct.getVersion()); final int threadsNumber = 10; final AtomicInteger atomicInteger = new AtomicInteger(); final CountDownLatch startLatch = new CountDownLatch(threadsNumber + 1); final CountDownLatch endLatch = new CountDownLatch(threadsNumber + 1); for (; atomicInteger.get() < threadsNumber; atomicInteger.incrementAndGet()) { final long index = (long) atomicInteger.get() * threadsNumber; LOGGER.info("Scheduling thread index {}", index); Thread testThread = new Thread(new Runnable() { @Override/*w ww.j a va 2 s. c o m*/ public void run() { try { startLatch.countDown(); startLatch.await(); productService.updateName(product.getId(), UUID.randomUUID().toString()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (Exception e) { LOGGER.error("Exception thrown!", e); } finally { endLatch.countDown(); } } }); testThread.start(); } startLatch.countDown(); LOGGER.info("Waiting for threads to be done"); endLatch.countDown(); endLatch.await(); LOGGER.info("Threads are done"); }