Search in sources :

Example 96 with AtomicBoolean

use of java.util.concurrent.atomic.AtomicBoolean in project storm by apache.

the class InprocMessaging method waitForReader.

public static void waitForReader(int port) {
    AtomicBoolean ab = getHasReader(port);
    long start = Time.currentTimeMillis();
    while (!ab.get()) {
        if (Time.isSimulating()) {
            Time.advanceTime(100);
        }
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
        //Ignored
        }
        if (Time.currentTimeMillis() - start > 20000) {
            LOG.error("DONE WAITING FOR READER AFTER {} ms", Time.currentTimeMillis() - start);
            break;
        }
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 97 with AtomicBoolean

use of java.util.concurrent.atomic.AtomicBoolean in project storm by apache.

the class DisruptorQueueBackpressureTest method testBackPressureCallback.

@Test
public void testBackPressureCallback() throws Exception {
    final DisruptorQueue queue = createQueue("testBackPressure", CAPACITY);
    queue.setEnableBackpressure(true);
    queue.setHighWaterMark(HIGH_WATERMARK);
    queue.setLowWaterMark(LOW_WATERMARK);
    final AtomicBoolean throttleOn = new AtomicBoolean(false);
    // we need to record the cursor because the DisruptorQueue does not update the readPos during batch consuming
    final AtomicLong consumerCursor = new AtomicLong(-1);
    DisruptorBackpressureCallbackImpl cb = new DisruptorBackpressureCallbackImpl(queue, throttleOn, consumerCursor);
    queue.registerBackpressureCallback(cb);
    for (int i = 0; i < MESSAGES; i++) {
        queue.publish(String.valueOf(i));
    }
    queue.consumeBatchWhenAvailable(new EventHandler<Object>() {

        @Override
        public void onEvent(Object o, long l, boolean b) throws Exception {
            consumerCursor.set(l);
        }
    });
    Assert.assertEquals("Check the calling time of throttle on. ", queue.getHighWaterMark(), cb.highWaterMarkCalledPopulation);
    Assert.assertEquals("Checking the calling time of throttle off. ", queue.getLowWaterMark(), cb.lowWaterMarkCalledPopulation);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) Test(org.junit.Test)

Example 98 with AtomicBoolean

use of java.util.concurrent.atomic.AtomicBoolean in project storm by apache.

the class DisruptorQueueTest method testInOrder.

@Test
public void testInOrder() throws InterruptedException {
    final AtomicBoolean allInOrder = new AtomicBoolean(true);
    DisruptorQueue queue = createQueue("consumerHang", 1024);
    Runnable producer = new IncProducer(queue, 1024 * 1024);
    Runnable consumer = new Consumer(queue, new EventHandler<Object>() {

        long _expected = 0;

        @Override
        public void onEvent(Object obj, long sequence, boolean endOfBatch) throws Exception {
            if (_expected != ((Number) obj).longValue()) {
                allInOrder.set(false);
                System.out.println("Expected " + _expected + " but got " + obj);
            }
            _expected++;
        }
    });
    run(producer, consumer, queue, 1000, 1);
    Assert.assertTrue("Messages delivered out of order", allInOrder.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Example 99 with AtomicBoolean

use of java.util.concurrent.atomic.AtomicBoolean in project tomcat by apache.

the class AsyncContextImpl method isStarted.

public boolean isStarted() {
    AtomicBoolean result = new AtomicBoolean(false);
    request.getCoyoteRequest().action(ActionCode.ASYNC_IS_STARTED, result);
    return result.get();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 100 with AtomicBoolean

use of java.util.concurrent.atomic.AtomicBoolean in project tomcat by apache.

the class Request method getPushBuilder.

// --------------------------------------------- HttpServletRequest Methods
/**
     * {@inheritDoc}
     *
     * @since Servlet 4.0
     */
@Override
public PushBuilder getPushBuilder() {
    AtomicBoolean result = new AtomicBoolean();
    coyoteRequest.action(ActionCode.IS_PUSH_SUPPORTED, result);
    if (result.get()) {
        return new ApplicationPushBuilder(this);
    } else {
        return null;
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ApplicationPushBuilder(org.apache.catalina.core.ApplicationPushBuilder)

Aggregations

AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2412 Test (org.junit.Test)1002 CountDownLatch (java.util.concurrent.CountDownLatch)394 IOException (java.io.IOException)336 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)301 ArrayList (java.util.ArrayList)214 AtomicReference (java.util.concurrent.atomic.AtomicReference)202 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)108 Test (org.testng.annotations.Test)106 List (java.util.List)98 Ignite (org.apache.ignite.Ignite)98 AtomicLong (java.util.concurrent.atomic.AtomicLong)94 HashMap (java.util.HashMap)93 ExecutorService (java.util.concurrent.ExecutorService)90 Map (java.util.Map)88 ExecutionException (java.util.concurrent.ExecutionException)87 File (java.io.File)68 Random (java.util.Random)68 CyclicBarrier (java.util.concurrent.CyclicBarrier)68 HashSet (java.util.HashSet)63