org.apache.hadoop.hbase.regionserver
Class Leases

java.lang.Object
  extended by org.apache.hadoop.hbase.util.HasThread
      extended by org.apache.hadoop.hbase.regionserver.Leases
All Implemented Interfaces:
Runnable

@InterfaceAudience.Private
public class Leases
extends HasThread

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
static class Leases.LeaseStillHeldException
          Thrown if we are asked create a lease but lease on passed name already exists.
 
Field Summary
protected  int leaseCheckFrequency
           
protected  boolean stopRequested
           
 
Constructor Summary
Leases(int leaseCheckFrequency)
          Creates a lease monitor
 
Method Summary
 void addLease(org.apache.hadoop.hbase.regionserver.Leases.Lease lease)
          Inserts lease.
 void cancelLease(String leaseName)
          Client explicitly cancels a lease.
 void close()
          Shut down this Leases instance.
 void closeAfterLeasesExpire()
          Shuts down this lease instance when all outstanding leases expire.
 void createLease(String leaseName, int leaseTimeoutPeriod, LeaseListener listener)
          Obtain a lease.
 void renewLease(String leaseName)
          Renew a lease
 void run()
           
 
Methods inherited from class org.apache.hadoop.hbase.util.HasThread
getName, getThread, interrupt, isAlive, isInterrupted, join, join, join, setDaemon, setName, setPriority, setUncaughtExceptionHandler, start
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

leaseCheckFrequency

protected final int leaseCheckFrequency

stopRequested

protected volatile boolean stopRequested
Constructor Detail

Leases

public Leases(int leaseCheckFrequency)
Creates a lease monitor

Parameters:
leaseCheckFrequency - - how often the lease should be checked (milliseconds)
Method Detail

run

public void run()
Specified by:
run in interface Runnable
Specified by:
run in class HasThread
See Also:
Thread.run()

closeAfterLeasesExpire

public void closeAfterLeasesExpire()
Shuts down this lease instance when all outstanding leases expire. Like close() but rather than violently end all leases, waits first on extant leases to finish. Use this method if the lease holders could loose data, leak locks, etc. Presumes client has shutdown allocation of new leases.


close

public void close()
Shut down this Leases instance. All pending leases will be destroyed, without any cancellation calls.


createLease

public void createLease(String leaseName,
                        int leaseTimeoutPeriod,
                        LeaseListener listener)
                 throws Leases.LeaseStillHeldException
Obtain a lease.

Parameters:
leaseName - name of the lease
leaseTimeoutPeriod - length of the lease in milliseconds
listener - listener that will process lease expirations
Throws:
Leases.LeaseStillHeldException

addLease

public void addLease(org.apache.hadoop.hbase.regionserver.Leases.Lease lease)
              throws Leases.LeaseStillHeldException
Inserts lease. Resets expiration before insertion.

Parameters:
lease -
Throws:
Leases.LeaseStillHeldException

renewLease

public void renewLease(String leaseName)
                throws LeaseException
Renew a lease

Parameters:
leaseName - name of lease
Throws:
LeaseException

cancelLease

public void cancelLease(String leaseName)
                 throws LeaseException
Client explicitly cancels a lease.

Parameters:
leaseName - name of lease
Throws:
LeaseException


Copyright © 2013 The Apache Software Foundation. All Rights Reserved.