@ThriftMethod
public List<LeaseProjection> acquireSemaphore(CuratorProjection projection, final String path, int acquireQty, int maxWaitMs, int maxLeases) throws RpcException
{
try
{
CuratorEntry entry = CuratorEntry.mustGetEntry(connectionManager, projection);
final InterProcessSemaphoreV2 semaphore = new InterProcessSemaphoreV2(entry.getClient(), path, maxLeases);
final Collection<Lease> leases = semaphore.acquire(acquireQty, maxWaitMs, TimeUnit.MILLISECONDS);
if ( leases == null )
{
return Lists.newArrayList();
}
List<LeaseProjection> leaseProjections = Lists.newArrayList();
for ( final Lease lease : leases )
{
Closer closer = new Closer()
{
@Override
public void close()
{
try
{
semaphore.returnLease(lease);
}
catch ( Exception e )
{
log.error("Could not release semaphore leases for path: " + path, e);
}
}
};
leaseProjections.add(new LeaseProjection(entry.addThing(lease, closer)));
}
return leaseProjections;
}
catch ( Exception e )
{