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;
}
}
}
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);
}
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());
}
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();
}
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;
}
}
Aggregations