Class 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.
    • 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:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable
      • close

        public void close​(boolean nodeAlreadyDeleted)