List of usage examples for java.util.concurrent.atomic AtomicInteger AtomicInteger
public AtomicInteger(int initialValue)
From source file:com.shopzilla.hadoop.mapreduce.MiniMRClusterContextPigTest.java
@Test public void testPig() throws Exception { final AtomicInteger inputRecordCount = new AtomicInteger(0); miniMRClusterContext.processData(new Path("/user/test/keywords_data"), new Function<String, Void>() { @Override//w w w .j a va 2 s. co m public Void apply(String line) { inputRecordCount.incrementAndGet(); return null; } }); Map<String, String> params = ImmutableMap.<String, String>builder().put("INPUT", "/user/test/keywords_data") .put("OUTPUT", "/user/test/keywords_output").build(); PigServer pigServer = miniMRClusterContext.getPigServer(); pigServer.registerScript(new ClassPathResource("some_pig_script.pig").getInputStream(), params); pigServer.setBatchOn(); pigServer.executeBatch(); final AtomicInteger outputRecordCount = new AtomicInteger(0); miniMRClusterContext.processData(new Path("/user/test/keywords_output"), new Function<String, Void>() { @Override public Void apply(String line) { outputRecordCount.incrementAndGet(); return null; } }); assertEquals(inputRecordCount.intValue(), outputRecordCount.intValue()); }
From source file:com.mellanox.jxio.tests.benchmarks.ServerPortalWorker.java
public ServerPortalWorker(int index, int inMsg_size, int outMsg_size, URI uri, int num_of_buffers) { portal_index = index;//from ww w.j a v a 2s . c o m eqh = new EventQueueHandler(new ServerEQHCallbacks()); pool = new MsgPool(num_of_buffers, inMsg_size, outMsg_size); eqh.bindMsgPool(pool); sp = new ServerPortal(eqh, uri); num_of_sessions = new AtomicInteger(0); }
From source file:org.jtheque.undo.UndoServiceTest.java
@Test @DirtiesContext/* w ww. j a va 2s . c o m*/ public void addError() { final AtomicInteger undo = new AtomicInteger(0); final AtomicInteger redo = new AtomicInteger(0); UndoableEdit edit = new TestEdit(undo, redo); undoService.addEdit(edit); assertEquals(0, undo.intValue()); assertEquals(0, redo.intValue()); undoService.undo(); assertEquals(1, undo.intValue()); assertEquals(0, redo.intValue()); undoService.redo(); assertEquals(1, undo.intValue()); assertEquals(1, redo.intValue()); }
From source file:com.l2jfree.gameserver.idfactory.BitSetRebuildFactory.java
public synchronized void initialize() { _log.info("starting db rebuild, good luck"); _log.info("this will take a while, dont kill the process or power off youre machine!"); try {/* www. j a v a 2 s.co m*/ _freeIds = new BitSet(PrimeFinder.nextPrime(100000)); _freeIds.clear(); _freeIdCount = new AtomicInteger(FREE_OBJECT_ID_SIZE); List<Integer> used_ids = new FastList<Integer>(); // first get all used ids for (int usedObjectId : extractUsedObjectIDTable()) used_ids.add(usedObjectId); _nextFreeId = new AtomicInteger(_freeIds.nextClearBit(0)); Connection con = null; con = L2DatabaseFactory.getInstance().getConnection(con); int nextid; int changedids = 0; // now loop through all already used oids and assign a new clean one for (int i : extractUsedObjectIDTable()) { for (;;) //danger ;) { nextid = getNextId(); if (!used_ids.contains(nextid)) break; } for (String update : ID_UPDATES) { PreparedStatement ps = con.prepareStatement(update); ps.setInt(1, nextid); ps.setInt(2, i); ps.execute(); ps.close(); changedids++; } } _log.info( "database rebuild done, changed " + changedids + " ids, set idfactory config to BitSet! ^o^/"); System.exit(0); } catch (Exception e) { _log.fatal("could not rebuild database! :", e); System.exit(0); } }
From source file:com.unicodecollective.amsterdam.TokenBucket.java
public TokenBucket(int initialCapacity, int maximumCapacity) { this.capacity = new AtomicInteger(initialCapacity); this.maximumCapacity = maximumCapacity; }
From source file:com.consol.citrus.demo.devoxx.service.ReportService.java
/** * Adds new produced item.// ww w . java2 s . c o m * @param id * @param type * @param amount */ public void add(String id, String type, Integer amount) throws Exception { produced.add(id); if (report.containsKey(type)) { report.get(type).addAndGet(amount); } else { report.put(type, new AtomicInteger(amount)); } if (getCookiesCount(type) >= 1000) { informStakeholders(type); } }
From source file:infrascructure.data.readers.AdvancedResourcesRepository.java
@Override public void readAll() throws IOException { int threads = config.getPropertyInt(Config.CRAWL_THREADS, 1); int i = rawdocs.size(); index = new AtomicInteger(i); ExecutorService pool = Executors.newCachedThreadPool(); for (int t = 0; t < threads; t++) { pool.submit(this); }/*from w w w. j a v a 2s . com*/ }
From source file:com.stratio.decision.unit.engine.validator.BaseRegularExpressionValidatorTest.java
@Ignore @Test//from w w w . j a v a 2s. co m public void mixedMessagesTest() { AtomicInteger count = new AtomicInteger(0); for (StratioStreamingMessage message : getMixedMessages()) { try { this.test(message); } catch (RequestValidationException e) { count.incrementAndGet(); } } Assert.assertTrue(getBadStrings().length <= count.get()); }
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); }/*from w w w . j a v a2 s. c om*/ curFrequency.incrementAndGet(); }
From source file:com.pepaproch.gtswsdl.client.RateLimitTest.java
@Test public void testCOnsumeSLotAsync() { RateLimit rate = new RateLimit(5, 10, ChronoUnit.SECONDS); ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(10); final AtomicInteger cc = new AtomicInteger(0); Instant start = Instant.now(); final Instant[] end = new Instant[1]; Runnable r = () -> {//from ww w . ja va 2 s.c o m for (int i = 0; i < 21; i++) { addTask(cc, scheduler, rate, end); } }; Runnable r1 = () -> { for (int i = 0; i < 9; i++) { addTask(cc, scheduler, rate, end); } }; r1.run(); r.run(); try { scheduler.awaitTermination(5, TimeUnit.SECONDS); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println(Duration.between(start, end[0]).toMillis()); }