org.apache.hadoop.hbase
Class Leases

java.lang.Object
  extended by org.apache.hadoop.hbase.Leases

public class Leases
extends Object

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.


Field Summary
protected  int leaseCheckFrequency
           
protected  int leasePeriod
           
protected  Map<org.apache.hadoop.hbase.Leases.LeaseName,org.apache.hadoop.hbase.Leases.Lease> leases
           
protected static org.apache.commons.logging.Log LOG
           
protected  TreeSet<org.apache.hadoop.hbase.Leases.Lease> sortedLeases
           
protected  AtomicBoolean stop
           
 
Constructor Summary
Leases(int leasePeriod, int leaseCheckFrequency)
          Creates a lease
 
Method Summary
 void cancelLease(long holderId, long resourceId)
          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(long holderId, long resourceId, LeaseListener listener)
          Obtain a lease
protected  org.apache.hadoop.hbase.Leases.LeaseName createLeaseName(long hid, long rid)
          Create a lease id out of the holder and resource ids.
 void renewLease(long holderId, long resourceId)
          Renew a lease
 void setName(String name)
           
 void start()
          Starts the lease monitor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected static final org.apache.commons.logging.Log LOG

leasePeriod

protected final int leasePeriod

leaseCheckFrequency

protected final int leaseCheckFrequency

leases

protected final Map<org.apache.hadoop.hbase.Leases.LeaseName,org.apache.hadoop.hbase.Leases.Lease> leases

sortedLeases

protected final TreeSet<org.apache.hadoop.hbase.Leases.Lease> sortedLeases

stop

protected AtomicBoolean stop
Constructor Detail

Leases

public Leases(int leasePeriod,
              int leaseCheckFrequency)
Creates a lease

Parameters:
leasePeriod - - length of time (milliseconds) that the lease is valid
leaseCheckFrequency - - how often the lease should be checked (milliseconds)
Method Detail

start

public void start()
Starts the lease monitor


setName

public void setName(String name)
Parameters:
name - Set name on the lease checking daemon thread.

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(long holderId,
                        long resourceId,
                        LeaseListener listener)
Obtain a lease

Parameters:
holderId - id of lease holder
resourceId - id of resource being leased
listener - listener that will process lease expirations

renewLease

public void renewLease(long holderId,
                       long resourceId)
                throws IOException
Renew a lease

Parameters:
holderId - id of lease holder
resourceId - id of resource being leased
Throws:
IOException

cancelLease

public void cancelLease(long holderId,
                        long resourceId)
Client explicitly cancels a lease.

Parameters:
holderId - id of lease holder
resourceId - id of resource being leased

createLeaseName

protected org.apache.hadoop.hbase.Leases.LeaseName createLeaseName(long hid,
                                                                   long rid)
Create a lease id out of the holder and resource ids.



Copyright © 2008 The Apache Software Foundation