@Test public void testThreadedLeaseIncrease() throws Exception { final Timing timing = new Timing(); CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1)); try { client.start(); final SharedCount count = new SharedCount(client, "/foo/count", 1); count.start(); final InterProcessSemaphoreV2 semaphore = new InterProcessSemaphoreV2(client, "/test", count); ExecutorService service = Executors.newCachedThreadPool(); final CountDownLatch latch1 = new CountDownLatch(1); final CountDownLatch latch2 = new CountDownLatch(1); Future<Object> future1 = service.submit ( new Callable<Object>() { @Override public Object call() throws Exception { Lease lease = semaphore.acquire(timing.seconds(), TimeUnit.SECONDS); Assert.assertNotNull(lease); latch1.countDown(); lease = semaphore.acquire(timing.forWaiting().seconds(), TimeUnit.SECONDS); Assert.assertNotNull(lease); latch2.countDown(); return null; } } ); Future<Object> future2 = service.submit ( new Callable<Object>() { @Override public Object call() throws Exception { Assert.assertTrue(latch1.await(timing.forWaiting().seconds(), TimeUnit.SECONDS)); timing.sleepABit(); Assert.assertTrue(count.trySetCount(2)); timing.sleepABit(); Assert.assertTrue(latch2.await(0, TimeUnit.SECONDS)); return null; } } ); future1.get(); future2.get(); count.close(); } finally { TestCleanState.closeAndTestClean(client); } }
public Lease acquire() throws Exception { String path = internals.attemptLock(-1, null, null); return makeLease(path); }
InterProcessSemaphore { public Lease acquire() throws Exception { String path = internals.attemptLock(-1, null, null); return makeLease(path); } }
InterProcessSemaphore { public Lease acquire() throws Exception { String path = internals.attemptLock(-1, null, null); return makeLease(path); } InterProcessSemaphore(CuratorFramework client, String path, int maxLeases);  InterProcessSemaphore(CuratorFramework client, String path, SharedCountReader count); private  InterProcessSemaphore(CuratorFramework client, String path, int maxLeases, SharedCountReader count); }
InterProcessSemaphore { public Lease acquire() throws Exception { String path = internals.attemptLock(-1, null, null); return makeLease(path); } InterProcessSemaphore(CuratorFramework client, String path, int maxLeases);  InterProcessSemaphore(CuratorFramework client, String path, SharedCountReader count); private  InterProcessSemaphore(CuratorFramework client, String path, int maxLeases, SharedCountReader count); void returnAll(Collection<Lease> leases); void returnLease(Lease lease); Lease acquire(); Collection<Lease> acquire(int qty); Lease acquire(long time, TimeUnit unit); Collection<Lease> acquire(int qty, long time, TimeUnit unit); }
InterProcessSemaphore { public Lease acquire() throws Exception { String path = internals.attemptLock(-1, null, null); return makeLease(path); } InterProcessSemaphore(CuratorFramework client, String path, int maxLeases);  InterProcessSemaphore(CuratorFramework client, String path, SharedCountReader count); private  InterProcessSemaphore(CuratorFramework client, String path, int maxLeases, SharedCountReader count); void returnAll(Collection<Lease> leases); void returnLease(Lease lease); Lease acquire(); Collection<Lease> acquire(int qty); Lease acquire(long time, TimeUnit unit); Collection<Lease> acquire(int qty, long time, TimeUnit unit);  }