Package org.lable.oss.uniqueid.etcd
Class ResourceClaim
- java.lang.Object
-
- org.lable.oss.uniqueid.etcd.ResourceClaim
-
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
ExpiringResourceClaim
public class ResourceClaim extends Object implements Closeable
Represents a claim on resource (represented by an int) from a finite pool of resources negotiated through a queueing protocol facilitated by a ZooKeeper-quorum.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classResourceClaim.StateInternal state of this ResourceClaim.
-
Field Summary
Fields Modifier and Type Field Description protected List<Closeable>closeablesprotected ResourceClaim.Statestate
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ResourceClaimclaim(io.etcd.jetcd.Client etcd, int maxGeneratorCount, List<Integer> clusterIds)Claim a resource.static ResourceClaimclaim(io.etcd.jetcd.Client etcd, int maxGeneratorCount, List<Integer> clusterIds, Duration timeout)Claim a resource.voidclose()Relinquish the claim to this resource, and release it back to the resource pool.voidclose(boolean nodeAlreadyDeleted)intgetClusterId()Get the claimed resource.intgetGeneratorId()
-
-
-
Field Detail
-
state
protected ResourceClaim.State state
-
-
Method Detail
-
claim
public static ResourceClaim claim(io.etcd.jetcd.Client etcd, int maxGeneratorCount, List<Integer> clusterIds) throws IOException
Claim a resource.- Parameters:
etcd- Etcd connection.maxGeneratorCount- Maximum number of generators possible.- Returns:
- A resource claim.
- Throws:
IOException
-
claim
public static ResourceClaim claim(io.etcd.jetcd.Client etcd, int maxGeneratorCount, List<Integer> clusterIds, Duration timeout) throws IOException
Claim a resource.- Parameters:
etcd- Etcd connection.maxGeneratorCount- Maximum number of generators possible.clusterIds- Cluster Ids available to use.timeout- Time out if the process takes longer than this.- Returns:
- A resource claim.
- Throws:
IOException
-
getClusterId
public int getClusterId()
Get the claimed resource.- Returns:
- The resource claimed.
- Throws:
IllegalStateException- Thrown when the claim is no longer held.
-
getGeneratorId
public int getGeneratorId()
-
close
public void close()
Relinquish the claim to this resource, and release it back to the resource pool.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
close
public void close(boolean nodeAlreadyDeleted)
-
-