Class ContractMaintainer<T>

  • All Implemented Interfaces:
    ContractController<T>

    class ContractMaintainer<T>
    extends java.lang.Object
    implements ContractController<T>
    The ContractMaintainer is used provide a controller uses a cleaner. This simple delegates to the cleaner queue when a renewal is required. Renewals are performed by revoking the contract and then reissuing it. This will ensure that the delay for expiry of the contract is reestablished within the queue.
    See Also:
    LeaseCleaner
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private LeaseCleaner<T> queue
      The queue that is used to issue and revoke contracts.
    • Constructor Summary

      Constructors 
      Constructor Description
      ContractMaintainer​(Cleaner<T> cleaner)
      Constructor for the ContractMaintainer object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void cancel​(Contract<T> contract)
      This will cancel the lease and release the resource.
      void close()
      This method is used to cancel all outstanding leases and to close the controller.
      void issue​(Contract<T> contract)
      This method will establish a contract for the given duration.
      void renew​(Contract<T> contract)
      This ensures that the contract is renewed for the duration on the contract, which may have changed since it was issued or last renewed.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • queue

        private final LeaseCleaner<T> queue
        The queue that is used to issue and revoke contracts.
    • Constructor Detail

      • ContractMaintainer

        public ContractMaintainer​(Cleaner<T> cleaner)
        Constructor for the ContractMaintainer object. This is used to create a controller for contracts which will ensure that the lease expiry durations are met. All notifications of expiry will be delivered to the provided cleaner instance.
        Parameters:
        cleaner - this is used to receive expiry notifications
    • Method Detail

      • issue

        public void issue​(Contract<T> contract)
        This method will establish a contract for the given duration. If the contract duration expires before it is renewed then a notification is sent, typically to a Cleaner to to signify that the resource should be released. The contract can also be cancelled by providing a zero length duration.
        Specified by:
        issue in interface ContractController<T>
        Parameters:
        contract - a contract representing a leased resource
      • renew

        public void renew​(Contract<T> contract)
        This ensures that the contract is renewed for the duration on the contract, which may have changed since it was issued or last renewed. If the duration on the contract has changed this will insure the previous contract duration is revoked and the new duration is used to maintain the leased resource.
        Specified by:
        renew in interface ContractController<T>
        Parameters:
        contract - a contract representing a leased resource
      • cancel

        public void cancel​(Contract<T> contract)
        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.
        Specified by:
        cancel in interface ContractController<T>
        Parameters:
        contract - a contract representing a leased resource
      • close

        public void close()
        This method is used to cancel all outstanding leases and to close the controller. Closing the controller ensures that it can no longer be used to issue or renew leases. All resources occupied by the controller are released, including threads, memory, and all leased resources occupied by the instance.
        Specified by:
        close in interface ContractController<T>
        Throws:
        LeaseException - if the controller can not be closed