Class LeaseCleaner<T>

java.lang.Object
org.simpleframework.common.thread.Daemon
org.simpleframework.common.lease.LeaseCleaner<T>
All Implemented Interfaces:
Runnable

class LeaseCleaner<T> extends Daemon
The LeaseCleaner provides a means of providing callbacks to clean a leased resource once the contract duration has expired. This will acquire contracts from the queue and invoke the Cleaner notification method. This will wait until the current clean operation has completed before it attempts to clean the next contract.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Cleaner<T>
    This is the cleaner that is invoked to clean contracts.
    private final ContractQueue<T>
    This is used to queue contracts that are to be cleaned.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor for the LeaseCleaner object.
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    This method is used to take the lease from the queue and give it to the cleaner for expiry.
    void
    Here we shutdown the lease maintainer so that the thread will die.
    boolean
    issue(Contract<T> contract)
    This method will establish a contract for a given resource.
    private void
    Here all of the existing contracts are purged when the invoker is closed.
    boolean
    revoke(Contract<T> contract)
    This revokes a contract that has previously been issued.
    void
    run()
    This acquires expired lease contracts from the queue once the expiry duration has passed.

    Methods inherited from class org.simpleframework.common.thread.Daemon

    interrupt, isActive, start, stop

    Methods inherited from class java.lang.Object

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

    • queue

      private final ContractQueue<T> queue
      This is used to queue contracts that are to be cleaned.
    • cleaner

      private final Cleaner<T> cleaner
      This is the cleaner that is invoked to clean contracts.
  • Constructor Details

    • LeaseCleaner

      public LeaseCleaner(Cleaner<T> cleaner)
      Constructor for the LeaseCleaner object. This can be used to issue, update, and expire leases. When a lease expires notification is sent to the Cleaner object provided. This allows an implementation independent means to clean up once a specific lease has expired.
      Parameters:
      cleaner - this will receive expiration notifications
  • Method Details

    • revoke

      public boolean revoke(Contract<T> contract) throws LeaseException
      This revokes a contract that has previously been issued. This is used when the contract duration has changed so that it can be reissued again with a new duration. This returns true if the contract was still active and false if it did not exist.
      Parameters:
      contract - this is the contract that contains details
      Throws:
      LeaseException
    • issue

      public boolean issue(Contract<T> contract) throws LeaseException
      This method will establish a contract for a given resource. If the contract duration expires before it is renewed then a notification is sent, to the issued Cleaner implementation, to signify that the resource has expired.
      Parameters:
      contract - this is the contract that contains details
      Throws:
      LeaseException
    • run

      public void run()
      This acquires expired lease contracts from the queue once the expiry duration has passed. This will deliver notification to the Cleaner object once the contract has been taken from the queue. This allows the cleaner to clean up any resources associated with the lease before the next expiration.
    • clean

      private void clean() throws Exception
      This method is used to take the lease from the queue and give it to the cleaner for expiry. This effectively waits until the next contract expiry has passed, once it has passed the key for that contract is given to the cleaner to clean up resources.
      Throws:
      Exception
    • purge

      private void purge()
      Here all of the existing contracts are purged when the invoker is closed. This ensures that each leased resource has a chance to clean up after the lease manager has been closed. All of the contracts are given a zero delay and cleaned immediately such that once this method has finished the queue will be empty.
    • close

      public void close()
      Here we shutdown the lease maintainer so that the thread will die. Shutting down the maintainer is done by interrupting the thread and setting the dead flag to true. Once this is invoked then the thread will no longer be running for this object.