Search in sources :

Example 31 with LinkedBlockingQueue

use of java.util.concurrent.LinkedBlockingQueue in project jmxtrans by jmxtrans.

the class JmxTransModule method createExecutorService.

private ThreadPoolExecutor createExecutorService(int poolSize, int workQueueCapacity, String componentName) {
    BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>(workQueueCapacity);
    ThreadFactory threadFactory = threadFactory(componentName);
    return new ThreadPoolExecutor(poolSize, poolSize, 0L, MILLISECONDS, workQueue, threadFactory);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 32 with LinkedBlockingQueue

use of java.util.concurrent.LinkedBlockingQueue in project Openfire by igniterealtime.

the class InternalComponentManager method query.

@Override
public IQ query(Component component, IQ packet, long timeout) throws ComponentException {
    final LinkedBlockingQueue<IQ> answer = new LinkedBlockingQueue<>(8);
    XMPPServer.getInstance().getIQRouter().addIQResultListener(packet.getID(), new IQResultListener() {

        @Override
        public void receivedAnswer(IQ packet) {
            answer.offer(packet);
        }

        @Override
        public void answerTimeout(String packetId) {
            Log.warn("An answer to a previously sent IQ stanza was never received. Packet id: " + packetId);
        }
    });
    sendPacket(component, packet);
    IQ reply = null;
    try {
        reply = answer.poll(timeout, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
    // Ignore
    }
    return reply;
}
Also used : IQResultListener(org.xmpp.component.IQResultListener) IQ(org.xmpp.packet.IQ) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 33 with LinkedBlockingQueue

use of java.util.concurrent.LinkedBlockingQueue in project Openfire by igniterealtime.

the class HttpSessionManager method start.

/**
     * Starts the services used by the HttpSessionManager.
     *
     * (Re)creates and configures a pooled executor to handle async routing for incoming packets with a configurable
     * (through property "xmpp.httpbind.worker.threads") amount of threads; also uses an unbounded task queue and
     * configurable ("xmpp.httpbind.worker.timeout") keep-alive.
     *
     * Note: Apart from the processing threads configured in this class, the server also uses a threadpool to perform
     * the network IO (as configured in ({@link HttpBindManager}). BOSH installations expecting heavy loads may want to
     * allocate additional threads to this worker pool to ensure timely delivery of inbound packets
     */
public void start() {
    Log.info("Starting instance");
    this.sessionManager = SessionManager.getInstance();
    final int maxClientPoolSize = JiveGlobals.getIntProperty("xmpp.client.processing.threads", 8);
    final int maxPoolSize = JiveGlobals.getIntProperty("xmpp.httpbind.worker.threads", maxClientPoolSize);
    final int keepAlive = JiveGlobals.getIntProperty("xmpp.httpbind.worker.timeout", 60);
    sendPacketPool = new ThreadPoolExecutor(getCorePoolSize(maxPoolSize), maxPoolSize, keepAlive, TimeUnit.SECONDS, // unbounded task queue
    new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory("httpbind-worker-", true, null, Thread.currentThread().getThreadGroup(), null));
    sendPacketPool.prestartCoreThread();
    // Periodically check for Sessions that need a cleanup.
    inactivityTask = new HttpSessionReaper();
    TaskEngine.getInstance().schedule(inactivityTask, 30 * JiveConstants.SECOND, 30 * JiveConstants.SECOND);
}
Also used : NamedThreadFactory(org.jivesoftware.util.NamedThreadFactory) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 34 with LinkedBlockingQueue

use of java.util.concurrent.LinkedBlockingQueue in project mapdb by jankotek.

the class LinkedBlockingQueueTest method testEmptyFull.

/**
     * Queue transitions from empty to full when elements added
     */
public void testEmptyFull() {
    LinkedBlockingQueue q = new LinkedBlockingQueue(2);
    assertTrue(q.isEmpty());
    assertEquals("should have room for 2", 2, q.remainingCapacity());
    q.add(one);
    assertFalse(q.isEmpty());
    q.add(two);
    assertFalse(q.isEmpty());
    assertEquals(0, q.remainingCapacity());
    assertFalse(q.offer(three));
}
Also used : LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 35 with LinkedBlockingQueue

use of java.util.concurrent.LinkedBlockingQueue in project mapdb by jankotek.

the class LinkedBlockingQueueTest method testTimedOffer.

/**
     * timed offer times out if full and elements not taken
     */
public void testTimedOffer() {
    final LinkedBlockingQueue q = new LinkedBlockingQueue(2);
    final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
    Thread t = newStartedThread(new CheckedRunnable() {

        public void realRun() throws InterruptedException {
            q.put(new Object());
            q.put(new Object());
            long startTime = System.nanoTime();
            assertFalse(q.offer(new Object(), timeoutMillis(), MILLISECONDS));
            assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
            pleaseInterrupt.countDown();
            try {
                q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
                shouldThrow();
            } catch (InterruptedException success) {
            }
        }
    });
    await(pleaseInterrupt);
    assertThreadStaysAlive(t);
    t.interrupt();
    awaitTermination(t);
}
Also used : LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)259 Test (org.junit.Test)91 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)64 IOException (java.io.IOException)26 ArrayList (java.util.ArrayList)23 Emitter (io.socket.emitter.Emitter)19 JSONObject (org.json.JSONObject)19 CountDownLatch (java.util.concurrent.CountDownLatch)18 ThreadFactory (java.util.concurrent.ThreadFactory)16 ExecutorService (java.util.concurrent.ExecutorService)14 BlockingQueue (java.util.concurrent.BlockingQueue)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 List (java.util.List)12 URI (java.net.URI)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 Intent (android.content.Intent)9 HashMap (java.util.HashMap)9 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)8 Map (java.util.Map)8 UUID (java.util.UUID)8