Interface Lease<T>

  • All Known Implementing Classes:
    ContractLease

    public interface Lease<T>
    The Lease object is used to keep a keyed resource active. This provides a very simple lease that can be used to track the activity of a resource or system. Keeping track of activity allows resources to be maintained until such time that they are no longer required, allowing the server to clean up any allocated memory, file descriptors, or other such data.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void cancel()
      This will cancel the lease and release the resource.
      long getExpiry​(java.util.concurrent.TimeUnit unit)
      Determines the duration remaining before the lease expires.
      T getKey()
      Provides the key for the resource that this lease represents.
      void renew​(long duration, java.util.concurrent.TimeUnit unit)
      This ensures that the leased resource is maintained for the specified number of TimeUnit seconds.
    • Method Detail

      • getExpiry

        long getExpiry​(java.util.concurrent.TimeUnit unit)
                throws LeaseException
        Determines the duration remaining before the lease expires. The expiry is given as the number of TimeUnit seconds remaining before the lease expires. If this value is negative it should be assumed that the lease has expired.
        Parameters:
        unit - this is the time unit used for the duration
        Returns:
        the duration remaining within this lease instance
        Throws:
        java.lang.Exception - if the expiry could not be acquired
        LeaseException
      • renew

        void renew​(long duration,
                   java.util.concurrent.TimeUnit unit)
            throws LeaseException
        This ensures that the leased resource is maintained for the specified number of TimeUnit seconds. Allowing the duration unit to be specified enables the lease system to maintain a resource with a high degree of accuracy. The accuracy of the leasing system is dependent on how long it takes to clean the resource associated with the lease.
        Parameters:
        duration - this is the length of time to renew for
        unit - this is the time unit used for the duration
        Throws:
        java.lang.Exception - if the lease could not be renewed
        LeaseException
      • cancel

        void cancel()
             throws LeaseException
        This will cancel the lease and release the resource. This has the same effect as the renew method with a zero length duration. Once this has been called the Cleaner used should be notified immediately. If the lease has already expired this throws an exception.
        Throws:
        java.lang.Exception - if the expiry has been passed
        LeaseException
      • getKey

        T getKey()
        Provides the key for the resource that this lease represents. This can be used to identify the resource should the need arise. Also, this provides a convenient means of identifying leases when using or storing it as an Object.
        Returns:
        this returns the key for the resource represented