Class LeaseManager
java.lang.Object
java.lang.Thread
org.apache.hadoop.hbase.regionserver.LeaseManager
- All Implemented Interfaces:
Runnable
Leases There are several server classes in HBase that need to track external clients that
occasionally send heartbeats.
These external clients hold resources in the server class. Those resources need to be released if the external client fails to send a heartbeat after some interval of time passes.
The Leases class is a general reusable class for this kind of pattern. An instance of the Leases class will create a thread to do its dirty work. You should close() the instance if you want to clean up the thread properly.
NOTE: This class extends Thread rather than Chore because the sleep time can be interrupted when there is something to do, rather than the Chore sleep time which is invariant.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classThis class tracks a single Lease.static classThrown if we are asked to create a lease but lease on passed name already exists.Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intprivate final Map<String,LeaseManager.Lease> private static final org.slf4j.Loggerprivate static final intprivate booleanFields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLease(LeaseManager.Lease lease) Inserts lease.voidcancelLease(String leaseName) Client explicitly cancels a lease.voidclose()Shut down this Leases instance.voidShuts down this lease instance when all outstanding leases expire.createLease(String leaseName, int leaseTimeoutPeriod, LeaseListener listener) Create a lease and insert it to the map of leases.(package private) LeaseManager.LeaseremoveLease(String leaseName) Remove named lease.voidrenewLease(String leaseName) Renew a leasevoidrun()Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
Field Details
-
LOG
-
MIN_WAIT_TIME
- See Also:
-
leases
-
leaseCheckFrequency
-
stopRequested
-
-
Constructor Details
-
LeaseManager
Creates a lease manager.- Parameters:
leaseCheckFrequency- - how often the lease should be checked (milliseconds)
-
-
Method Details
-
run
-
closeAfterLeasesExpire
Shuts down this lease instance when all outstanding leases expire. Likeclose()but rather than violently end all leases, waits first on extant leases to finish. Use this method if the lease holders could lose data, leak locks, etc. Presumes client has shutdown allocation of new leases. -
close
Shut down this Leases instance. All pending leases will be destroyed, without any cancellation calls. -
createLease
public LeaseManager.Lease createLease(String leaseName, int leaseTimeoutPeriod, LeaseListener listener) throws LeaseManager.LeaseStillHeldException Create a lease and insert it to the map of leases.- Parameters:
leaseName- name of the leaseleaseTimeoutPeriod- length of the lease in millisecondslistener- listener that will process lease expirations- Returns:
- The lease created.
- Throws:
LeaseManager.LeaseStillHeldException
-
addLease
Inserts lease. Resets expiration before insertion. -
renewLease
Renew a lease- Parameters:
leaseName- name of the lease- Throws:
LeaseException
-
cancelLease
Client explicitly cancels a lease.- Parameters:
leaseName- name of lease- Throws:
LeaseException
-
removeLease
Remove named lease. Lease is removed from the map of leases.- Parameters:
leaseName- name of lease- Returns:
- Removed lease
- Throws:
LeaseException
-