Java 类org.apache.curator.framework.recipes.locks.Lease 实例源码

项目:ZKRecipesByExample    文件:InterProcessSemaphoreExample.java   
public static void main(String[] args) throws Exception {
    FakeLimitedResource resource = new FakeLimitedResource();
    try (TestingServer server = new TestingServer()) {

        CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new ExponentialBackoffRetry(1000, 3));
        client.start();

        InterProcessSemaphoreV2 semaphore = new InterProcessSemaphoreV2(client, PATH, MAX_LEASE);
        Collection<Lease> leases = semaphore.acquire(5);
        System.out.println("get " + leases.size() + " leases");
        Lease lease = semaphore.acquire();
        System.out.println("get another lease");

        resource.use();

        Collection<Lease> leases2 = semaphore.acquire(5, 10, TimeUnit.SECONDS);
        System.out.println("Should timeout and acquire return " + leases2);

        System.out.println("return one lease");
        semaphore.returnLease(lease);
        System.out.println("return another 5 leases");
        semaphore.returnAll(leases);
    }
}
项目:QDrill    文件:ZkDistributedSemaphore.java   
@Override
public DistributedLease acquire(long time, TimeUnit unit) throws Exception {
  Lease lease = semaphore.acquire(time, unit);
  if(lease != null){
    return new LeaseHolder(lease);
  }else{
    return null;
  }
}
项目:dremio-oss    文件:ZkDistributedSemaphore.java   
@Override
public DistributedLease acquire(long time, TimeUnit unit) throws Exception {
  Lease lease = semaphore.acquire(time, unit);
  if(lease != null){
    return new LeaseHolder(lease);
  }else{
    return null;
  }
}
项目:drill    文件:ZkDistributedSemaphore.java   
@Override
public DistributedLease acquire(long time, TimeUnit unit) throws Exception {
  Lease lease = semaphore.acquire(time, unit);
  if(lease != null){
    return new LeaseHolder(lease);
  }else{
    return null;
  }
}
项目:QDrill    文件:ZkDistributedSemaphore.java   
public LeaseHolder(Lease lease) {
  super();
  this.lease = lease;
}
项目:dremio-oss    文件:ZkDistributedSemaphore.java   
public LeaseHolder(Lease lease) {
  super();
  this.lease = lease;
}
项目:drill    文件:ZkDistributedSemaphore.java   
public LeaseHolder(Lease lease) {
  super();
  this.lease = lease;
}