Package java.util.concurrent

Examples of java.util.concurrent.BlockingQueue.offer()


         return false;
      }

      private void tryAddKey(Address address, Object key) {
         BlockingQueue queue = address2key.get(address);
         boolean added = queue.offer(key);
         if (added) {
            exitingNumberOfKeys.incrementAndGet();
         }
         if (log.isTraceEnabled()) {
            log.trace((added ? "Successfully" : "Not") + " added key(" + key + ") to the address(" + address + ").");
View Full Code Here


         BlockingQueue queue = address2key.get(address);
         // on node stop the distribution manager might still return the dead server for a while after we have already removed its queue
         if (queue == null)
            return;

         boolean added = queue.offer(key);
         if (added) {
            exitingNumberOfKeys.incrementAndGet();
         }
         if (log.isTraceEnabled()) {
            if (added)
View Full Code Here

         return false;
      }

      private void tryAddKey(Address address, Object key) {
         BlockingQueue queue = address2key.get(address);
         boolean added = queue.offer(key);
         if (added) {
            exitingNumberOfKeys.incrementAndGet();
         }
         if (log.isTraceEnabled()) {
            log.trace((added ? "Successfully" : "Not") + " added key(" + key + ") to the address(" + address + ").");
View Full Code Here

         BlockingQueue queue = address2key.get(address);
         // on node stop the distribution manager might still return the dead server for a while after we have already removed its queue
         if (queue == null)
            return;

         boolean added = queue.offer(key);
         if (added) {
            exitingNumberOfKeys.incrementAndGet();
         }
         if (log.isTraceEnabled()) {
            if (added)
View Full Code Here

        q.add(two);
        ExecutorService executor = Executors.newFixedThreadPool(2);
        final CheckedBarrier threadsStarted = new CheckedBarrier(2);
        executor.execute(new CheckedRunnable() {
            public void realRun() throws InterruptedException {
                assertFalse(q.offer(three));
                threadsStarted.await();
                assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS));
                assertEquals(0, q.remainingCapacity());
            }
        });
View Full Code Here

        final CheckedBarrier threadsStarted = new CheckedBarrier(2);
        executor.execute(new CheckedRunnable() {
            public void realRun() throws InterruptedException {
                assertFalse(q.offer(three));
                threadsStarted.await();
                assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS));
                assertEquals(0, q.remainingCapacity());
            }
        });

        executor.execute(new CheckedRunnable() {
View Full Code Here

    @Test
    public void testDrainToN() {
        BlockingQueue q = new LocalConcurrentBlockingObjectQueue(SIZE * 2);
        for (int i = 0; i < SIZE + 2; ++i) {
            for (int j = 0; j < SIZE; j++)
                assertTrue(q.offer(new Integer(j)));
            ArrayList l = new ArrayList();
            q.drainTo(l, i);
            int k = (i < SIZE) ? i : SIZE;
            assertEquals(k, l.size());
            assertEquals(SIZE - k, q.size());
View Full Code Here

        q.add(one);
        assertFalse(q.isEmpty());
        q.add(two);
        assertFalse(q.isEmpty());
        assertEquals(0, q.remainingCapacity());
        assertFalse(q.offer(three));
    }

    /**
     * remainingCapacity decreases on add, increases on remove
     */
 
View Full Code Here

     */
    public void testTimedOfferNull() throws InterruptedException {
        final BlockingQueue q = emptyCollection();
        long startTime = System.nanoTime();
        try {
            q.offer(null, LONG_DELAY_MS, MILLISECONDS);
            shouldThrow();
        } catch (NullPointerException success) {
        }
        assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
    }
View Full Code Here

     * Offer succeeds if not full; fails if full
     */
    @Test
    public void testOffer() {
        BlockingQueue q = new LocalConcurrentBlockingObjectQueue(1);
        assertTrue(q.offer(zero));
        assertFalse(q.offer(one));
    }

    /**
     * add succeeds if not full; throws ISE if full
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.