List of usage examples for java.util.concurrent.atomic AtomicInteger AtomicInteger
public AtomicInteger()
From source file:guru.qas.martini.annotation.MartiniAnnotationCallback.java
protected MartiniAnnotationCallback(Class<A> annotationClass, Class<C> annotationContainerClass, ConfigurableListableBeanFactory beanFactory) { this.annotationClass = annotationClass; this.annotationContainerClass = annotationContainerClass; this.beanFactory = beanFactory; this.atomicInteger = new AtomicInteger(); this.regularExpressions = Sets.newHashSet(); }
From source file:com.zaubersoftware.gnip4j.api.impl.XMLActivityStreamFeedProcessorTest.java
/** test */ @Test//from w ww .j a va 2 s. co m public final void test() throws IOException, ParseException { final InputStream is = getClass().getResourceAsStream("fanpage.xml"); try { final AtomicInteger i = new AtomicInteger(); final ObjectMapper mapper = JsonActivityFeedProcessor.getObjectMapper(); final FeedProcessor p = new XMLActivityStreamFeedProcessor<Activity>("foo", new DirectExecuteService(), new StreamNotificationAdapter<Activity>() { @Override public void notify(final Activity activity, final GnipStream stream) { i.incrementAndGet(); try { final byte[] data0 = mapper.writeValueAsBytes(activity); final Activity e = mapper.reader(Activity.class).readValue(data0); final byte[] data1 = mapper.writeValueAsBytes(e); assertArrayEquals(data0, data1); // test serialization final ObjectOutputStream os = new ObjectOutputStream(new ByteArrayOutputStream()); os.writeObject(activity); os.close(); } catch (final Exception e) { throw new RuntimeException(e); } } }, new ActivityUnmarshaller("hola")); p.process(is); assertEquals(23, i.get()); } finally { IOUtils.closeQuietly(is); } }
From source file:oz.hadoop.yarn.api.core.LocalApplicationLaunchTests.java
@Test //(timeout=10000) public void validateWithReplyListener() throws Exception { final AtomicInteger repliesCounter = new AtomicInteger(); YarnApplication<DataProcessor> yarnApplication = YarnAssembly .forApplicationContainer(SimpleEchoContainer.class).containerCount(2).memory(512) .withApplicationMaster().maxAttempts(2).priority(2).build("sample-yarn-application"); yarnApplication.registerReplyListener(new ContainerReplyListener() { @Override// w ww. java 2 s .c om public void onReply(ByteBuffer replyData) { repliesCounter.incrementAndGet(); } }); DataProcessor dataProcessor = yarnApplication.launch(); assertEquals(2, dataProcessor.containers()); for (int i = 0; i < 2; i++) { for (int j = 0; j < dataProcessor.containers(); j++) { dataProcessor.process(ByteBuffer.wrap(("Hello Yarn!-" + i).getBytes())); } } assertTrue(yarnApplication.isRunning()); yarnApplication.shutDown(); assertEquals(repliesCounter.get(), dataProcessor.completedSinceStart()); assertFalse(yarnApplication.isRunning()); }
From source file:com.evilisn.ScheduledTasks.java
@Scheduled(fixedRate = 10 * 60000) public void scheduledCheckOCSP() throws InterruptedException { log.info("fetching certs"); ArrayList<Cert> certs = (ArrayList<Cert>) getCerts(); log.info(String.format("[%d] certs to be checked.", certs.size())); Date now = new Date(); long startTime = now.getTime(); System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", "50"); AtomicInteger c_REVOKED = new AtomicInteger(); AtomicInteger c_GOOD = new AtomicInteger(); AtomicInteger c_UNKNOWN = new AtomicInteger(); AtomicInteger c_VALID = new AtomicInteger(); AtomicInteger c_EXPIRED = new AtomicInteger(); certs.parallelStream().forEach(o -> { try {//from w w w .j av a 2 s .c o m if (o.getClient_cert().getNotAfter().after(now)) { OCSP.RevocationStatus.CertStatus resp = OCSP.check(o.getClient_cert(), o.getIssuer_cert()) .getCertStatus(); log.info(String.format("Serial Number [%20s]| OCSP Status:[%s]", o.getClient_cert().getSerialNumber(), resp.toString())); c_VALID.getAndIncrement(); if (resp == OCSP.RevocationStatus.CertStatus.GOOD) c_GOOD.getAndIncrement(); if (resp == OCSP.RevocationStatus.CertStatus.UNKNOWN) c_UNKNOWN.getAndIncrement(); if (resp == OCSP.RevocationStatus.CertStatus.REVOKED) c_REVOKED.getAndIncrement(); } else { //expired. c_EXPIRED.getAndIncrement(); } } catch (IOException e) { e.printStackTrace(); } catch (CertPathValidatorException e) { e.printStackTrace(); } }); long endTime = System.currentTimeMillis(); log.info("ALL " + certs.size() + " certificates processed in " + (endTime - startTime) / 100 + " seconds, with " + c_VALID.get() + " valid certs, " + c_EXPIRED + " expired certs, among which " + c_GOOD.get() + " is GOOD, " + c_REVOKED.get() + " is revoked, and " + c_UNKNOWN.get() + " is KNOWN."); }
From source file:fr.aliasource.webmail.common.message.AttachmentManager.java
public AttachmentManager(IAccount account) { this.account = account; attachIdAllocator = new AtomicInteger(); new File(getAttachDir()).mkdirs(); this.previewer = new AttachmentsPreviewManager(account, this); }
From source file:cf.spring.servicebroker.TestBroker.java
@Bean
AtomicInteger counter() {
return new AtomicInteger();
}
From source file:org.apache.servicemix.jbi.cluster.engine.ReconnectTest.java
public void testLoadInOnly() throws Exception { createRoute(Transacted.Jms, true, false, false); final int nbThreads = 10; final int nbExchanges = 10; final ReadWriteLock lock = new ReentrantReadWriteLock(); final CountDownLatch latch = new CountDownLatch(nbThreads); final AtomicInteger id = new AtomicInteger(); lock.writeLock().lock();//from www . ja v a2 s .co m for (int i = 0; i < nbThreads; i++) { new Thread() { public void run() { Channel client = null; try { client = nmr1.createChannel(); lock.readLock().lock(); for (int i = 0; i < nbExchanges; i++) { Exchange exchange = client.createExchange(Pattern.InOnly); exchange.getIn() .setBody(new StringSource("<hello id='" + id.getAndIncrement() + "'/>")); exchange.setTarget(nmr1.getEndpointRegistry() .lookup(ServiceHelper.createMap(Endpoint.NAME, PROXY_ENDPOINT_NAME))); client.sendSync(exchange); assertEquals(Status.Done, exchange.getStatus()); } } catch (Exception e) { e.printStackTrace(); } finally { lock.readLock().unlock(); latch.countDown(); if (client != null) { client.close(); } } } }.start(); } long t0, t1; cluster2.pause(); t0 = System.currentTimeMillis(); lock.writeLock().unlock(); latch.await(); broker.stop(); cluster2.resume(); Thread.sleep(500); broker = createBroker(false); receiver.assertExchangesReceived(nbThreads * nbExchanges, TIMEOUT); //Thread.sleep(500); //receiver.assertExchangesReceived(nbThreads * nbExchanges, TIMEOUT); t1 = System.currentTimeMillis(); System.err.println("Elapsed time: " + (t1 - t0) + " ms"); System.err.println("Throuput: " + (nbThreads * nbExchanges * 1000 / (t1 - t0)) + " messages/sec"); }
From source file:edu.umd.umiacs.clip.tools.math.StatisticalTests.java
private static Triple<Double, Double, Double> pRecPrecF1(int pos, int tpboth, int tp0only, int tp1only, int fpboth, int fp0only, int fp1only) { double delta_f1 = Math.abs(f1(tp0only + tpboth, fp0only + fpboth, pos - (tp0only + tpboth)) - f1(tp1only + tpboth, fp1only + fpboth, pos - (tp1only + tpboth))); double delta_rec = Math.abs( rec(tp0only + tpboth, pos - (tp0only + tpboth)) - rec(tp1only + tpboth, pos - (tp1only + tpboth))); double delta_prec = Math .abs(prec(tp0only + tpboth, fp0only + fpboth) - prec(tp1only + tpboth, fp1only + fpboth)); AtomicInteger nc_f1 = new AtomicInteger(); AtomicInteger nc_rec = new AtomicInteger(); AtomicInteger nc_prec = new AtomicInteger(); range(0, NT).forEach(j -> {//from w w w. j a v a2s. c om int tp[] = nextPair(tp0only, tp1only, tpboth); int fp[] = nextPair(fp0only, fp1only, fpboth); if (Math.abs(f1(tp[0], fp[0], pos - tp[0]) - f1(tp[1], fp[1], pos - tp[1])) > delta_f1) { nc_f1.incrementAndGet(); } if (Math.abs(rec(tp[0], pos - tp[0]) - rec(tp[1], pos - tp[1])) > delta_rec) { nc_rec.incrementAndGet(); } if (Math.abs(prec(tp[0], fp[0]) - prec(tp[1], fp[1])) > delta_prec) { nc_prec.incrementAndGet(); } }); return Triple.of((nc_rec.get() + 1.) / (NT + 1), (nc_prec.get() + 1.) / (NT + 1), (nc_f1.get() + 1.) / (NT + 1)); }
From source file:me.smoe.adar.utils.cam.o.CAMApplication.java
private void go(int cases, boolean buildScore) throws Exception { if (buildScore) { statistics.run();/*from w w w . j a v a 2 s.c o m*/ } Map<Long, String> cams = new HashMap<>(); for (CAM cam : camRepository.findAll()) { cams.put(cam.getId(), cam.getName()); } AtomicInteger succ = new AtomicInteger(); AtomicInteger fail = new AtomicInteger(); AtomicInteger wrong = new AtomicInteger(); AtomicInteger index = new AtomicInteger(); Page<CAMProduct> products = camProductRepository .findAll(new PageRequest(0, cases, new Sort(Direction.DESC, "id"))); int total = products.getSize(); for (CAMProduct product : products) { THREADPOOLEXECUTOR.execute(() -> { try { Long ca = caMatcher.matcher(product.getName(), product.getBrand(), product.getCategory(), product.getDesc(), 10000); // Long ca = me.smoe.adar.utils.cam.n.matcher.CAMatcher.matcher(product.getCategory(), 20); if (product.getCao().equals(ca)) { System.err.println( String.format("[CAM] Index: %s Id: %s Cao: %s Can: %s", index.incrementAndGet(), product.getId(), cams.get(product.getCao()), cams.get(ca))); } else if (ca != null && cams.get(product.getCao()).equals(cams.get(ca))) { System.err.println( String.format("[CAM] Index: %s Id: %s Cao: %s Can: %s", index.incrementAndGet(), product.getId(), cams.get(product.getCao()), cams.get(ca))); } else if (ca != null) { System.out.println( String.format("[CAM] Index: %s Id: %s Cao: %s Can: %s", index.incrementAndGet(), product.getId(), cams.get(product.getCao()), cams.get(ca))); } else { // System.out.println(String.format("[CAM] Index: %s Id: %s Cao: %s Can: %s", index.incrementAndGet(), product.getId(), cams.get(product.getCao()), cams.get(ca))); } if (ca == null) { fail.incrementAndGet(); return; } if (product.getCao().equals(ca)) { succ.incrementAndGet(); } else if (ca != null && cams.get(product.getCao()).equals(cams.get(ca))) { succ.incrementAndGet(); } else { wrong.incrementAndGet(); } } catch (Exception e) { e.printStackTrace(); } }); } while (!THREADPOOLEXECUTOR.getQueue().isEmpty()) { TimeUnit.SECONDS.sleep(1); } TimeUnit.SECONDS.sleep(2); System.out.println(); System.out.println("[CAM] : " + total); System.out.println("[CAM] ?: " + new BigDecimal(succ.get()).divide(new BigDecimal(total), 4, RoundingMode.HALF_UP) .multiply(new BigDecimal(100)).setScale(2, RoundingMode.HALF_UP) + "%"); System.out.println("[CAM] : " + new BigDecimal(fail.get()).divide(new BigDecimal(total), 4, RoundingMode.HALF_UP) .multiply(new BigDecimal(100)).setScale(2, RoundingMode.HALF_UP) + "%"); System.out.println("[CAM] : " + new BigDecimal(wrong.get()).divide(new BigDecimal(total), 4, RoundingMode.HALF_UP) .multiply(new BigDecimal(100)).setScale(2, RoundingMode.HALF_UP) + "%"); System.exit(0); }
From source file:org.zenoss.zep.dao.impl.DaoUtilsTest.java
@Test public void testDeadlockRetryOtherException() throws Exception { final AtomicInteger i = new AtomicInteger(); try {/*from ww w .j av a 2 s. c o m*/ DaoUtils.deadlockRetry(new Callable<Integer>() { @Override public Integer call() throws Exception { i.incrementAndGet(); throw new RuntimeException("Bad exception - no retry"); } }); fail("Should have thrown an exception after first retry"); } catch (RuntimeException e) { assertEquals(1, i.get()); assertEquals("Bad exception - no retry", e.getMessage()); } }