List of usage examples for java.util.concurrent.atomic AtomicInteger AtomicInteger
public AtomicInteger(int initialValue)
From source file:ufo.remote.calls.benchmark.client.caller.hornetq.HornetQTester.java
@Override protected void startTest(final TesterResult result) { ProducerTemplate producerTemplate = camelContext.createProducerTemplate(); producerTemplate.setExecutorService(Executors.newFixedThreadPool(20)); String url = HornetQApacheCamelConfig.JMS_NAME + ":queue:echo?deliveryPersistent=false&replyToDeliveryPersistent=false"; AtomicInteger failures = new AtomicInteger(0); CountDownLatch latch = new CountDownLatch(result.totalCalls); for (int i = 0; i < result.totalCalls; i++) { producerTemplate.asyncCallbackRequestBody(url, result.message, new Synchronization() { @Override//from w ww. j a v a2 s .c o m public void onFailure(final Exchange exchange) { failures.incrementAndGet(); latch.countDown(); } @Override public void onComplete(final Exchange exchange) { if (logger.isDebugEnabled()) { logger.debug("Received message [{}]", exchange.getIn().getBody()); } latch.countDown(); } }); } try { latch.await(); } catch (InterruptedException e) { throw new RuntimeException(e); } result.failures = failures.get(); }
From source file:ufo.remote.calls.benchmark.client.caller.activemq.ActiveMQTester.java
@Override protected void startTest(final TesterResult result) { ProducerTemplate producerTemplate = camelContext.createProducerTemplate(); producerTemplate.setExecutorService(Executors.newFixedThreadPool(20)); String url = ActiveMQApacheCamelConfig.JMS_NAME + ":queue:echo?deliveryPersistent=false&replyToDeliveryPersistent=false"; AtomicInteger failures = new AtomicInteger(0); CountDownLatch latch = new CountDownLatch(result.totalCalls); for (int i = 0; i < result.totalCalls; i++) { producerTemplate.asyncCallbackRequestBody(url, result.message, new Synchronization() { @Override//from w w w. j a v a 2 s . c o m public void onFailure(final Exchange exchange) { failures.incrementAndGet(); latch.countDown(); } @Override public void onComplete(final Exchange exchange) { if (logger.isDebugEnabled()) { logger.debug("Received message [{}]", exchange.getIn().getBody()); } latch.countDown(); } }); } try { latch.await(); } catch (InterruptedException e) { throw new RuntimeException(e); } result.failures = failures.get(); }
From source file:com.l2jfree.gameserver.idfactory.BitSetIDFactory.java
public void initialize() { try {//from w w w . j a v a 2 s .c o m _freeIds = new BitSet(PrimeFinder.nextPrime(100000)); _freeIds.clear(); _freeIdCount = new AtomicInteger(FREE_OBJECT_ID_SIZE); for (int usedObjectId : extractUsedObjectIDTable()) { int objectID = usedObjectId - FIRST_OID; if (objectID < 0) { // auction hack if (usedObjectId == 100100) { continue; } _log.warn("Object ID " + usedObjectId + " in DB is less than minimum ID of " + FIRST_OID); continue; } _freeIds.set(usedObjectId - FIRST_OID); _freeIdCount.decrementAndGet(); } _nextFreeId = new AtomicInteger(_freeIds.nextClearBit(0)); _initialized = true; } catch (Exception e) { _initialized = false; _log.fatal("BitSet ID Factory could not be initialized correctly", e); } }
From source file:io.watchcat.node.monitoring.threshold.MemoryUsageThresholds.java
public MemoryUsageThresholds() { usedMemoryMinorThreshold = new AtomicInteger(DEFAULT_MINOR_THRESHOLD); usedMemoryMajorThreshold = new AtomicInteger(DEFAULT_MAJOR_THRESHOLD); usedMemoryCriticalThreshold = new AtomicInteger(DEFAULT_CRITICAL_THRESHOLD); usedSwapMinorThreshold = new AtomicInteger(DEFAULT_MINOR_THRESHOLD); usedSwapMajorThreshold = new AtomicInteger(DEFAULT_MAJOR_THRESHOLD); usedSwapCriticalThreshold = new AtomicInteger(DEFAULT_CRITICAL_THRESHOLD); }
From source file:strat.mining.multipool.stats.persistence.dao.coinshift.impl.AddressDAOMongo.java
@PostConstruct private void initialize() { List<Address> addresses = mongoOperation.findAll(Address.class); int maxId = 0; if (CollectionUtils.isNotEmpty(addresses)) { for (Address address : addresses) { if (address.getId() > maxId) { maxId = address.getId(); }/*from w w w . j a v a 2 s . com*/ } } addressId = new AtomicInteger(maxId + 1); }
From source file:edu.cornell.med.icb.util.ProcessEstimator.java
/** * Create a process estimator for a specified number of totalUnits. * This will start the timer immediately. * @param totalUnitsVal the number of totalUnits this will estimate completeion for *///from w w w. ja va2s . com public ProcessEstimator(final int totalUnitsVal) { assert totalUnitsVal > 0; totalUnits = new AtomicInteger(totalUnitsVal); stopWatch = new StopWatch(); stopWatch.start(); unitsCompleted = new AtomicInteger(0); regressor = new LinearRegression(); }
From source file:org.jtheque.file.FileServiceTest.java
@Test public void exporters() { final AtomicInteger counter = new AtomicInteger(0); final Collection<String> datas = Arrays.asList("data1", "data2", "data3"); fileService.registerExporter("no-module", new Exporter<String>() { @Override/*from w ww .java2 s .c om*/ public boolean canExportTo(String fileType) { return "xml".equals(fileType); } @Override public void export(String path, Collection<String> exportedDatas) throws FileException { counter.incrementAndGet(); assertEquals("path", path); assertEquals(datas, exportedDatas); } }); try { fileService.exportDatas("no-module", "xml", "path", datas); } catch (FileException e) { fail("Exception during the export"); } assertEquals(1, counter.get()); }
From source file:edu.iu.lda.DocWord.java
public DocStore(List<String> input, int numThreads, Configuration configuration) { inputFiles = input;//from ww w . j av a 2 s . c o m vDocMap = new Int2ObjectOpenHashMap<DocWord>(); this.numThreads = numThreads; conf = configuration; idGenerator = new AtomicInteger(0); }
From source file:com.zaubersoftware.gnip4j.http.ReconnectionTest.java
/** test */ @Test //(timeout = 10000) public void testReConnection() throws Exception { // ignore framework warnings final Logger root = Logger.getRootLogger(); root.setLevel(Level.OFF);/*from www .jav a 2 s . c om*/ final AtomicInteger count = new AtomicInteger(0); final DefaultGnipStream stream = new DefaultGnipStream(new MockRemoteResourceProvider(), "test", 1, new MockExecutorService()); final StringBuilder out = new StringBuilder(); final StreamNotification n = new StreamNotification() { @Override public void notifyReConnectionError(final GnipException e) { out.append(String.format("ReConnectionError: %s\n", e.getMessage())); } @Override public void notifyReConnectionAttempt(final int attempt, final long waitTime) { out.append(String.format("Connection attempt %d wait time %d\n", attempt, waitTime)); } @Override public void notifyConnectionError(final TransportGnipException e) { out.append(String.format("ConnectionError: %s\n", e.getMessage())); } @Override public void notify(final Activity activity, final GnipStream stream) { out.append(activity.getBody() + "\n"); if (count.incrementAndGet() >= 4) { stream.close(); } } }; stream.open(n); stream.await(); final String s = out.toString(); final String expected = IOUtils .toString(getClass().getClassLoader().getResourceAsStream("reconnectlog.txt")); Assert.assertEquals(expected, s); Assert.assertEquals( "transferedBytes = 8000\ntransferedActivities = 4\n" + "numberOfSucessfulReconnections = 1\nnumberOfReconnections = 4", stream.getStreamStats().toString()); }
From source file:com.cronutils.model.time.TimeNode.java
/** * We return same reference value if matches or next one if does not match. * Then we start applying shifts.// www. java 2 s. co m * This way we ensure same value is returned if no shift is requested. * @param reference - reference value * @param shiftsToApply - shifts to apply * @return NearestValue instance, never null. Holds information on nearest (forward) value and shifts performed. */ @VisibleForTesting NearestValue getNearestForwardValue(int reference, int shiftsToApply) { List<Integer> values = new ArrayList<Integer>(this.values); int index = 0; boolean foundGreater = false; AtomicInteger shift = new AtomicInteger(0); if (!values.contains(reference)) { for (Integer value : values) { if (value > reference) { index = values.indexOf(value); shiftsToApply--;//we just moved a position! foundGreater = true; break; } } if (!foundGreater) { shift.incrementAndGet(); } } else { index = values.indexOf(reference); } int value = values.get(index); for (int j = 0; j < shiftsToApply; j++) { value = getValueFromList(values, index + 1, shift); index = values.indexOf(value); } return new NearestValue(value, shift.get()); }