use of org.eclipse.jetty.util.BlockingArrayQueue in project dropwizard by dropwizard.
the class AbstractServerFactory method createThreadPool.
protected ThreadPool createThreadPool(MetricRegistry metricRegistry) {
final BlockingQueue<Runnable> queue = new BlockingArrayQueue<>(minThreads, maxThreads, maxQueuedRequests);
final InstrumentedQueuedThreadPool threadPool = new InstrumentedQueuedThreadPool(metricRegistry, maxThreads, minThreads, (int) idleThreadTimeout.toMilliseconds(), queue);
threadPool.setName("dw");
return threadPool;
}
use of org.eclipse.jetty.util.BlockingArrayQueue in project pulsar by yahoo.
the class PersistentQueueE2ETest method testReplayOnConsumerDisconnect.
@Test
public void testReplayOnConsumerDisconnect() throws Exception {
final String topicName = "persistent://prop/use/ns-abc/shared-topic3";
final String subName = "sub3";
final int numMsgs = 100;
final List<String> messagesProduced = Lists.newArrayListWithCapacity(numMsgs);
final List<String> messagesConsumed = new BlockingArrayQueue<>(numMsgs);
ConsumerConfiguration conf1 = new ConsumerConfiguration();
conf1.setSubscriptionType(SubscriptionType.Shared);
conf1.setMessageListener((consumer, msg) -> {
try {
consumer.acknowledge(msg);
messagesConsumed.add(new String(msg.getData()));
} catch (Exception e) {
fail("Should not fail");
}
});
ConsumerConfiguration conf2 = new ConsumerConfiguration();
conf2.setSubscriptionType(SubscriptionType.Shared);
conf2.setMessageListener((consumer, msg) -> {
try {
// do nothing
} catch (Exception e) {
fail("Should not fail");
}
});
Consumer consumer1 = pulsarClient.subscribe(topicName, subName, conf1);
// consumer2 does not ack messages
Consumer consumer2 = pulsarClient.subscribe(topicName, subName, conf2);
List<CompletableFuture<MessageId>> futures = Lists.newArrayListWithCapacity(numMsgs * 2);
Producer producer = pulsarClient.createProducer(topicName);
for (int i = 0; i < numMsgs; i++) {
String message = "msg-" + i;
futures.add(producer.sendAsync(message.getBytes()));
messagesProduced.add(message);
}
FutureUtil.waitForAll(futures).get();
producer.close();
consumer2.close();
for (int n = 0; n < 10 && messagesConsumed.size() < numMsgs; n++) {
Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT);
}
// 1. consumer1 gets all messages
assertTrue(CollectionUtils.subtract(messagesProduced, messagesConsumed).isEmpty());
consumer1.close();
admin.persistentTopics().delete(topicName);
}
use of org.eclipse.jetty.util.BlockingArrayQueue in project ignite by apache.
the class GridCacheTtlManagerNotificationTest method testThatNotificationWorkAsExpected.
/**
* @throws Exception If failed.
*/
public void testThatNotificationWorkAsExpected() throws Exception {
try (final Ignite g = startGrid(0)) {
final BlockingArrayQueue<Event> queue = new BlockingArrayQueue<>();
g.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
queue.add(evt);
return true;
}
}, EventType.EVT_CACHE_OBJECT_EXPIRED);
final String key = "key";
IgniteCache<Object, Object> cache = g.cache(DEFAULT_CACHE_NAME);
ExpiryPolicy plc1 = new CreatedExpiryPolicy(new Duration(MILLISECONDS, 100_000));
cache.withExpiryPolicy(plc1).put(key + 1, 1);
// Cleaner should see entry.
Thread.sleep(1_000);
ExpiryPolicy plc2 = new CreatedExpiryPolicy(new Duration(MILLISECONDS, 1000));
cache.withExpiryPolicy(plc2).put(key + 2, 1);
// We should receive event about second entry expiration.
assertNotNull(queue.poll(5, SECONDS));
}
}
Aggregations