Package java.util.concurrent

Examples of java.util.concurrent.Semaphore.availablePermits()


            catch ( Exception ignore )
            {
                // ignore
            }

            Assert.assertTrue(semaphore.availablePermits() == 0);
            Assert.assertFalse(selector.hasLeadership());

            selector.requeue();
            Assert.assertTrue(timing.multiple(4).acquireSemaphore(semaphore));
        }
View Full Code Here


            catch ( Exception ignore )
            {
                // ignore
            }

            Assert.assertTrue(semaphore.availablePermits() == 0);
            Assert.assertFalse(selector.hasLeadership());

            selector.requeue();
            Assert.assertTrue(timing.multiple(4).acquireSemaphore(semaphore));
        }
View Full Code Here

                                try
                                {
                                    if ( isFirst.compareAndSet(true, false) )
                                    {
                                        semaphore.release(THREAD_QTY - 1);
                                        while ( semaphore.availablePermits() > 0 )
                                        {
                                            Thread.sleep(100);
                                        }
                                    }
                                    else
View Full Code Here

                async.run();
            }
        });

        // drain checkpoint permits
        checkpoint.acquireUninterruptibly(checkpoint.availablePermits());
        // block NodeStore.retrieve()
        retrieve.acquireUninterruptibly();
        t.start();

        // wait until async update called checkpoint
View Full Code Here

    @Test
    public void releasesPermit() throws Exception {
        final Semaphore semaphore = new Semaphore(1);
        assertThat("semaphore begins with single permit",
                semaphore.availablePermits(), is(1));
        semaphore.acquire(1);
        assertThat("semaphore has no available permits",
                semaphore.availablePermits(), is(0));
        new PermitReleasingCallback<>(semaphore).call(new Object());
        assertThat("callback releases a permit",
View Full Code Here

        final Semaphore semaphore = new Semaphore(1);
        assertThat("semaphore begins with single permit",
                semaphore.availablePermits(), is(1));
        semaphore.acquire(1);
        assertThat("semaphore has no available permits",
                semaphore.availablePermits(), is(0));
        new PermitReleasingCallback<>(semaphore).call(new Object());
        assertThat("callback releases a permit",
                semaphore.availablePermits(), is(1));
    }
}
View Full Code Here

        semaphore.acquire(1);
        assertThat("semaphore has no available permits",
                semaphore.availablePermits(), is(0));
        new PermitReleasingCallback<>(semaphore).call(new Object());
        assertThat("callback releases a permit",
                semaphore.availablePermits(), is(1));
    }
}
View Full Code Here

    }

    // Wait until all puts are finished.
    if (!outstandingPutSemaphore.tryAcquire(_maxOutstandingWrites, _timeout, _timeoutUnit))
    {
      _log.error("Put timed out with {} outstanding writes", _maxOutstandingWrites - outstandingPutSemaphore.availablePermits());
      throw new TimeoutException();
    }

    FutureCallback<None> shutdownCallback = new FutureCallback<None>();
    _store.shutdown(shutdownCallback);
View Full Code Here

                async.run();
            }
        });

        // drain checkpoint permits
        checkpoint.acquireUninterruptibly(checkpoint.availablePermits());
        // block NodeStore.retrieve()
        retrieve.acquireUninterruptibly();
        t.start();

        // wait until async update called checkpoint
View Full Code Here

            server.stop();

            // test foreground retry
            client.checkExists().forPath("/hey");
            Assert.assertTrue(semaphore.tryAcquire(MAX_RETRIES, timing.forWaiting().seconds(), TimeUnit.SECONDS), "Remaining leases: " + semaphore.availablePermits());

            // make sure we're reconnected
            client.getZookeeperClient().setRetryPolicy(new RetryOneTime(100));
            client.checkExists().forPath("/hey");
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.