Package com.j_spaces.core
Class LeaseManager
java.lang.Object
com.j_spaces.core.LeaseManager
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*iEach 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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncancel(String entryUid, String classname, int objectType, boolean fromReplication, boolean origin, boolean isFromGateway) Cancel a lease for a registered Entry in this Lease Manager.cancel(String entryUid, String classname, int objectType, boolean fromReplication, boolean origin, boolean lease_expired, OperationID operationID, boolean isFromGateway) Batch cancellation operations for entries.final voidclose()Closes the Lease Manager by waking up the lease reaper daemon thread and waits for it to gracefully die.voidforceLeaseReaperCycle(boolean mustExecute) voidforceLeaseReaperCycle(boolean mustExecute, long timeToWait) Force a lease reaper cycle and blocks until the cycle is completed (unlessLeaseReaper#_minForceReapIntervalis not elapsed since last reaper cycle completion)longgetEffectiveEntryLeaseTime(long time) longgetEffectiveEntryLeaseTimeForReaper(long time) longlonggetExpirationOnUpdateByLeaseOrByTimeRule(long lease, long startTime, IEntryPacket entry, boolean fromReplication) longgetExpirationOnWriteByLeaseOrByTimeRule(long lease, long startTime, IEntryPacket entry, boolean fromReplication) voidinit()booleanbooleanbooleanisReRegisterLeaseOnUpdate(long lease, IEntryPacket entry) booleanbooleanbooleanvoidregisterEntryLease(IEntryCacheInfo entryCacheInfo, long expiration) voidregisterEntryLease(ILeasedEntryCacheInfo entryCacheInfo, IEntryHolder entryHolder, long expiration) registerTemplateLease(TemplateCacheInfo templateCacheInfo) longrenew(String entryUid, String className, int objectType, long duration, boolean fromReplication, boolean origin, boolean isFromGateway) Renews a lease for an additional period of time (specified in milliseconds) for a registered entry in this Lease Manager.Object[]Batch renewal operations for entries.booleanbooleanvoidreRegisterLease(ILeasedEntryCacheInfo leaseCacheInfo, IEntryHolder entry, long original_expiration, long new_expiration, int objectType) static final longtoAbsoluteTime(long duration) Calculates the absolute time for the given duration.static final longtoAbsoluteTime(long duration, long current) Calculates the absolute time for the given duration.voidunregister(ILeasedEntryCacheInfo leaseCacheInfo, long expiration) unregister from lease manager based on direct backrefs Note: entry/template must be lockedvoidbooleanwaitForNoCycleOnQuiesce(long timeout) called as part of demote from primary to backup in order to verify LM is not active
-
Constructor Details
-
LeaseManager
-
-
Method Details
-
init
public void init() -
registerEntryLease
-
registerEntryLease
public void registerEntryLease(ILeasedEntryCacheInfo entryCacheInfo, IEntryHolder entryHolder, long expiration) -
registerTemplateLease
-
reRegisterLease
public void reRegisterLease(ILeasedEntryCacheInfo leaseCacheInfo, IEntryHolder entry, long original_expiration, long new_expiration, int objectType) -
createOperationIDForLeaseExpirationEvent
-
isNoReapUnderXtnLeases
public boolean isNoReapUnderXtnLeases() -
getEffectiveEntryLeaseTime
public long getEffectiveEntryLeaseTime(long time) -
getEffectiveEntryLeaseTimeForReaper
public long getEffectiveEntryLeaseTimeForReaper(long time) -
isCurrentLeaseReaperThread
public boolean isCurrentLeaseReaperThread() -
forceLeaseReaperCycle
Force a lease reaper cycle and blocks until the cycle is completed (unlessLeaseReaper#_minForceReapIntervalis 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
- 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 -
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
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. SametoAbsoluteTime(long)but uses a provided clock.- Parameters:
duration- duration in milliseconds.current- current time.- Returns:
- The absolute time of the requested given duration.
-
getExpirationByTimeRuleOnInitialLoad
-
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
-
toAbsoluteTime
public static final long toAbsoluteTime(long duration) Calculates the absolute time for the given duration. Handles Lease.FOREVER, Lease.ANY, and NO_WAIT. SametoAbsoluteTime(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
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
-