Class LeaseManager

java.lang.Object
com.j_spaces.core.LeaseManager

public class LeaseManager extends Object
Lease Manager handles operations that can be carried out on a lease: creation, renewal and cancellation. It doesn't actually manage the leases, since they have been given to the client. Rather, it handles the lease resource which has the type identifier (Entry/Template/Notify) and the expiration time for the lease. LeaseManager groups expirations into Cells, each specifying a given boundary interval.
 [ Cell-1 | Cell-2 | Cell-3 | ... | Cell-i ] where each cell holds leases
 in between intervals:
 Cell-1         0...LM_EXPIRATION_TIME_INTERVAL
 Cell-2 LM_EXPIRATION_TIME_INTERVAL...LM_EXPIRATION_TIME_INTERVAL*2
 ...
 Cell-i LM_EXPIRATION_TIME_INTERVAL...LM_EXPIRATION_TIME_INTERVAL*i
 
Each Cell is ordered in a Sorted Tree Map which guarantees that the map will be in ascending key order, sorted according to the natural order of the key's class (Long).
  • Constructor Details

  • Method Details

    • init

      public void init()
    • registerEntryLease

      public void registerEntryLease(IEntryCacheInfo entryCacheInfo, long expiration)
    • registerEntryLease

      public void registerEntryLease(ILeasedEntryCacheInfo entryCacheInfo, IEntryHolder entryHolder, long expiration)
    • registerTemplateLease

      public Lease registerTemplateLease(TemplateCacheInfo templateCacheInfo)
    • reRegisterLease

      public void reRegisterLease(ILeasedEntryCacheInfo leaseCacheInfo, IEntryHolder entry, long original_expiration, long new_expiration, int objectType)
    • createOperationIDForLeaseExpirationEvent

      public OperationID createOperationIDForLeaseExpirationEvent()
    • isNoReapUnderXtnLeases

      public boolean isNoReapUnderXtnLeases()
    • getEffectiveEntryLeaseTime

      public long getEffectiveEntryLeaseTime(long time)
    • getEffectiveEntryLeaseTimeForReaper

      public long getEffectiveEntryLeaseTimeForReaper(long time)
    • isCurrentLeaseReaperThread

      public boolean isCurrentLeaseReaperThread()
    • forceLeaseReaperCycle

      public void forceLeaseReaperCycle(boolean mustExecute, long timeToWait) throws InterruptedException
      Force a lease reaper cycle and blocks until the cycle is completed (unless LeaseReaper#_minForceReapInterval is not elapsed since last reaper cycle completion)
      Parameters:
      mustExecute - TODO XML:
      timeToWait - indicates how long should the leaseReaperDaemon wait for completing the cycle, 0 means forever
      Throws:
      InterruptedException
    • forceLeaseReaperCycle

      public void forceLeaseReaperCycle(boolean mustExecute) throws InterruptedException
      Throws:
      InterruptedException
    • renew

      public long renew(String entryUid, String className, int objectType, long duration, boolean fromReplication, boolean origin, boolean isFromGateway) throws UnknownLeaseException, InternalSpaceException
      Renews a lease for an additional period of time (specified in milliseconds) for a registered entry in this Lease Manager. This duration is not added to the original lease, but is used to determine a new expiration time for the existing lease. If the renewal is granted this is reflected in value returned by getExpiration. If the renewal fails, the lease is left intact for the same duration that was in force prior to the call to renew.
      Parameters:
      entryUid - Uid of entry to renew a lease for.
      className - The class name of this entry.
      objectType - The type of the entry.
      duration - The requested duration in milliseconds.
      fromReplication - true If this entry arrived from replication.
      Returns:
      duration the requested duration in milliseconds
      Throws:
      UnknownLeaseException - if lease is unknown to the registrar.
      InternalSpaceException - if an internal error occurred.
    • update

      public void update(String entryUid, String className, int objectType, long duration) throws UnknownLeaseException, InternalSpaceException
      Throws:
      UnknownLeaseException
      InternalSpaceException
    • renewAll

      public Object[] renewAll(String[] entryUids, String[] classNames, int[] objectTypes, long[] durations)
      Batch renewal operations for entries.
      Parameters:
      entryUids - Uid of entries to renew a lease for.
      classNames - The class name of each corresponding entry.
      objectTypes - Type of the object of each entry.
      durations - The requested durations (in milliseconds) of each entry.
      Returns:
      an Object[] { exceptions, newDurations }
      See Also:
    • cancel

      public IEntryHolder cancel(String entryUid, String classname, int objectType, boolean fromReplication, boolean origin, boolean isFromGateway) throws UnknownLeaseException
      Cancel a lease for a registered Entry in this Lease Manager.
      Parameters:
      entryUid - Uid of entry to renew a lease for.
      classname - The class name of this entry.
      objectType - The type of the entry.
      fromReplication - true If this entry arrived from replication.
      Returns:
      IEntryHolder
      Throws:
      UnknownLeaseException
    • cancel

      public IEntryHolder cancel(String entryUid, String classname, int objectType, boolean fromReplication, boolean origin, boolean lease_expired, OperationID operationID, boolean isFromGateway) throws UnknownLeaseException
      Throws:
      UnknownLeaseException
    • cancelAll

      public Exception[] cancelAll(String[] entryUids, String[] classNames, int[] objectTypes)
      Batch cancellation operations for entries.
      Parameters:
      entryUids - Uid of entries to cancel their lease.
      classNames - The class name of each corresponding entry.
      objectTypes - Type of the object of each entry.
      Returns:
      a non-null Exception[] array; might be empty.
      See Also:
    • close

      public final void close()
      Closes the Lease Manager by waking up the lease reaper daemon thread and waits for it to gracefully die.
    • toAbsoluteTime

      public static final long toAbsoluteTime(long duration, long current)
      Calculates the absolute time for the given duration. Handles Lease.FOREVER, Lease.ANY, and NO_WAIT. Same toAbsoluteTime(long) but uses a provided clock.
      Parameters:
      duration - duration in milliseconds.
      current - current time.
      Returns:
      The absolute time of the requested given duration.
    • getExpirationByTimeRuleOnInitialLoad

      public long getExpirationByTimeRuleOnInitialLoad(IEntryData entry)
    • getExpirationOnWriteByLeaseOrByTimeRule

      public long getExpirationOnWriteByLeaseOrByTimeRule(long lease, long startTime, IEntryPacket entry, boolean fromReplication)
    • getExpirationOnUpdateByLeaseOrByTimeRule

      public long getExpirationOnUpdateByLeaseOrByTimeRule(long lease, long startTime, IEntryPacket entry, boolean fromReplication)
    • isReRegisterLeaseOnUpdate

      public boolean isReRegisterLeaseOnUpdate(long lease, IEntryPacket entry)
    • toAbsoluteTime

      public static final long toAbsoluteTime(long duration)
      Calculates the absolute time for the given duration. Handles Lease.FOREVER, Lease.ANY, and NO_WAIT. Same toAbsoluteTime(long, long) but uses a system clock.
      Parameters:
      duration - duration in milliseconds.
      Returns:
      The absolute time of the requested given duration.
    • isSlaveLeaseManagerForEntries

      public boolean isSlaveLeaseManagerForEntries()
    • isSlaveLeaseManagerForNotifyTemplates

      public boolean isSlaveLeaseManagerForNotifyTemplates()
    • replicateLeaseExpirationEventsForEntries

      public boolean replicateLeaseExpirationEventsForEntries()
    • replicateLeaseExpirationEventsForNotifyTemplates

      public boolean replicateLeaseExpirationEventsForNotifyTemplates()
    • isSupportsRecentExtendedUpdates

      public boolean isSupportsRecentExtendedUpdates()
    • unregister

      public void unregister(ILeasedEntryCacheInfo leaseCacheInfo, long expiration)
      unregister from lease manager based on direct backrefs Note: entry/template must be locked
    • waitForNoCycleOnQuiesce

      public boolean waitForNoCycleOnQuiesce(long timeout)
      called as part of demote from primary to backup in order to verify LM is not active
      Returns:
      true if no cycle false if timeout pqassed and cycle still busy