Search in sources :

Example 1 with BlockingArrayQueue

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;
}
Also used : InstrumentedQueuedThreadPool(com.codahale.metrics.jetty9.InstrumentedQueuedThreadPool) BlockingArrayQueue(org.eclipse.jetty.util.BlockingArrayQueue)

Example 2 with BlockingArrayQueue

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);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Consumer(com.yahoo.pulsar.client.api.Consumer) Producer(com.yahoo.pulsar.client.api.Producer) ConsumerConfiguration(com.yahoo.pulsar.client.api.ConsumerConfiguration) BlockingArrayQueue(org.eclipse.jetty.util.BlockingArrayQueue) PulsarClientException(com.yahoo.pulsar.client.api.PulsarClientException) Test(org.testng.annotations.Test)

Example 3 with BlockingArrayQueue

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));
    }
}
Also used : CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite) Duration(javax.cache.expiry.Duration) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) BlockingArrayQueue(org.eclipse.jetty.util.BlockingArrayQueue)

Aggregations

BlockingArrayQueue (org.eclipse.jetty.util.BlockingArrayQueue)3 InstrumentedQueuedThreadPool (com.codahale.metrics.jetty9.InstrumentedQueuedThreadPool)1 Consumer (com.yahoo.pulsar.client.api.Consumer)1 ConsumerConfiguration (com.yahoo.pulsar.client.api.ConsumerConfiguration)1 Producer (com.yahoo.pulsar.client.api.Producer)1 PulsarClientException (com.yahoo.pulsar.client.api.PulsarClientException)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CreatedExpiryPolicy (javax.cache.expiry.CreatedExpiryPolicy)1 Duration (javax.cache.expiry.Duration)1 ExpiryPolicy (javax.cache.expiry.ExpiryPolicy)1 Ignite (org.apache.ignite.Ignite)1 Event (org.apache.ignite.events.Event)1 Test (org.testng.annotations.Test)1