Example usage for java.util.concurrent.atomic AtomicInteger AtomicInteger

List of usage examples for java.util.concurrent.atomic AtomicInteger AtomicInteger

Introduction

In this page you can find the example usage for java.util.concurrent.atomic AtomicInteger AtomicInteger.

Prototype

public AtomicInteger(int initialValue) 

Source Link

Document

Creates a new AtomicInteger with the given initial value.

Usage

From source file:org.jasig.cas.web.support.AbstractInMemoryThrottledSubmissionHandlerInterceptorAdapter.java

@Override
protected final void updateCount(final HttpServletRequest request, final String usernameParameter) {
    final AtomicInteger newAtomicInteger = new AtomicInteger(1);
    final AtomicInteger oldAtomicInteger = this.ipMap.putIfAbsent(constructKey(request, usernameParameter),
            newAtomicInteger);/*  w  ww.jav  a2s .  c o m*/

    if (oldAtomicInteger != null) {
        oldAtomicInteger.incrementAndGet();
    }
}

From source file:ufo.remote.calls.benchmark.client.caller.resttemplate.AsyncRestTemplateTester.java

@Override
protected void startTest(final TesterResult result) {

    String url = "http://" + hostname + ":" + port + path;

    CountDownLatch latch = new CountDownLatch(result.totalCalls);
    AtomicInteger failures = new AtomicInteger(0);
    Executor executor = Executors.newFixedThreadPool(10);
    for (int i = 0; i < result.totalCalls; i++) {
        executor.execute(new Caller(url, result.message, latch, failures));
    }/*  www .j  a  v  a  2s. c  o m*/

    try {
        latch.await();
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
    result.failures = failures.get();
}

From source file:net.audumla.scheduler.quartz.SunScheduleTest.java

protected AtomicInteger scheduleJob(Trigger trigger, int expectedCount, int maxWait) throws SchedulerException {
    AtomicInteger ai = new AtomicInteger(expectedCount);
    JobDetail job = JobBuilder.newJob(TestJob.class).withIdentity("testJob", "testJobGroup").storeDurably()
            .build();//from   ww w.j a v  a 2 s.  c o m
    job.getJobDataMap().put(TestJob.EXECUTION_COUNT, ai);
    StdSchedulerFactory.getDefaultScheduler().scheduleJob(job, trigger);
    if (!StdSchedulerFactory.getDefaultScheduler().isStarted()) {
        StdSchedulerFactory.getDefaultScheduler().start();

    }
    synchronized (ai) {
        try {
            ai.wait(maxWait * 1000);
        } catch (Exception ex) {
            logger.error(ex);
        }
    }
    return ai;

}

From source file:com.netflix.curator.framework.recipes.barriers.TestDistributedDoubleBarrier.java

@Test
public void testMultiClient() throws Exception {
    final Timing timing = new Timing();
    final CountDownLatch postEnterLatch = new CountDownLatch(QTY);
    final CountDownLatch postLeaveLatch = new CountDownLatch(QTY);
    final AtomicInteger count = new AtomicInteger(0);
    final AtomicInteger max = new AtomicInteger(0);
    List<Future<Void>> futures = Lists.newArrayList();
    ExecutorService service = Executors.newCachedThreadPool();
    for (int i = 0; i < QTY; ++i) {
        Future<Void> future = service.submit(new Callable<Void>() {
            @Override/* w ww.  j ava  2 s  .c o m*/
            public Void call() throws Exception {
                CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(),
                        timing.session(), timing.connection(), new RetryOneTime(1));
                try {
                    client.start();
                    DistributedDoubleBarrier barrier = new DistributedDoubleBarrier(client, "/barrier", QTY);

                    Assert.assertTrue(barrier.enter(timing.seconds(), TimeUnit.SECONDS));

                    synchronized (TestDistributedDoubleBarrier.this) {
                        int thisCount = count.incrementAndGet();
                        if (thisCount > max.get()) {
                            max.set(thisCount);
                        }
                    }

                    postEnterLatch.countDown();
                    Assert.assertTrue(timing.awaitLatch(postEnterLatch));

                    Assert.assertEquals(count.get(), QTY);

                    Assert.assertTrue(barrier.leave(timing.seconds(), TimeUnit.SECONDS));
                    count.decrementAndGet();

                    postLeaveLatch.countDown();
                    Assert.assertTrue(timing.awaitLatch(postEnterLatch));
                } finally {
                    IOUtils.closeQuietly(client);
                }

                return null;
            }
        });
        futures.add(future);
    }

    for (Future<Void> f : futures) {
        f.get();
    }
    Assert.assertEquals(count.get(), 0);
    Assert.assertEquals(max.get(), QTY);
}

From source file:com.jerrellmardis.amphitheatre.task.GetFilesTask.java

public GetFilesTask(Context context, String user, String password, String path, boolean isMovie, Callback l) {

    mContext = context;/*  ww  w . j av a2  s  .c  o m*/
    mUser = user;
    mPassword = password;
    mPath = path;
    mIsMovie = isMovie;
    mCallback = l;

    mSetsProcessedCounter = new AtomicInteger(0);

    if (!mPath.startsWith("smb://")) {
        mPath = "smb://" + mPath;
    }
    if (!mPath.endsWith("/")) {
        mPath += "/";
    }
}

From source file:com.ewcms.web.pubsub.ProgressSender.java

@Override
protected String constructOutput() {
    List<Taskable> tasks = publishFac.getSitePublishTasks(siteId);

    StringBuilder builder = new StringBuilder();

    builder.append(" <script type=\"text/javascript\">");
    builder.append("parent.loadData(");
    AtomicInteger count = new AtomicInteger(0);
    builder.append("{\"rows\":[");
    for (Taskable task : tasks) {
        constructTreeGridRows(builder, count, -1, task);
    }//from www  .j  a va 2 s. com
    builder.append("]");
    builder.append(",\"total\":").append(count.get()).append("}");
    builder.append(");");
    builder.append("</script>");
    return builder.toString();
}

From source file:CreateTest.java

static void doTestPool(int nThreads) {
    done = false;/*ww  w .  ja  v  a 2 s  .com*/
    nCalls = new AtomicInteger(0);
    ThreadPoolExecutor tpe = new ThreadPoolExecutor(nThreads, nThreads, 50000L, TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>());
    Runnable r = new CreateTest();
    for (int i = 0; i < target; i++) {
        tpe.execute(r);
    }
    tpe.shutdown();
    try {
        tpe.awaitTermination(10000000L, TimeUnit.SECONDS);
    } catch (Exception e) {
    }
}

From source file:strat.mining.multipool.stats.service.impl.coinshift.RequestStatsLoggingServiceImpl.java

public RequestStatsLoggingServiceImpl() {
    nbAllGlobal = new AtomicInteger(0);
    nbLastGlobal = new AtomicInteger(0);
    nbAllAddress = new AtomicInteger(0);
    nbLastAddress = new AtomicInteger(0);
    nbPaidout = new AtomicInteger(0);
    nbSuggestion = new AtomicInteger(0);
    nbInitialization = new AtomicInteger(0);

    uniqueAddressesAllStats = Collections.synchronizedSet(new HashSet<String>());
    uniqueAddressesLastStats = Collections.synchronizedSet(new HashSet<String>());
    uniqueAddressesPaidout = Collections.synchronizedSet(new HashSet<String>());
}

From source file:org.jtheque.errors.ErrorServiceTest.java

@Test
@DirtiesContext//from w  w w  .jav a 2  s  .  c  o m
public void listenerCalled() {
    final Error error = Errors.newError("Test");

    final AtomicInteger integer = new AtomicInteger(0);

    errorService.addErrorListener(new ErrorListener() {
        @Override
        public void errorOccurred(Error occuredError) {
            integer.incrementAndGet();

            assertEquals(error, occuredError);
        }
    });

    errorService.addError(error);
    assertEquals(1, integer.intValue());
}

From source file:lockstep.ServerReceivingQueue.java

/**
 * Constructor.//from   ww w.  j a va2  s .co m
 * 
 * @param initialFrameNumber First frame's number. Must be the same for all 
 * the hosts using the protocol
 * 
 * @param senderID ID of the client whose frames are collected in this queue
 * 
 * @param serverExecutionSemaphore semaphore used by to signal the client of
 * the availability of the next frame input. The client awaits that all the 
 * queues are ready before collecting the next frame inputs
 */
public ServerReceivingQueue(int initialFrameNumber, int senderID, Semaphore serverExecutionSemaphore) {
    this.senderID = senderID;

    this.commandBuffer = new ConcurrentSkipListMap<>();
    this.executionSemaphore = serverExecutionSemaphore;

    this.lastInOrderACK = new AtomicInteger(initialFrameNumber - 1);
    this.selectiveACKsSet = new ConcurrentSkipListSet<>();
}