Oracle Fusion Middleware
Oracle WebLogic Server API Reference
11g Release 1 (10.3.6)

Part Number E13941-06

weblogic.cluster.singleton
Class LeaseManager

java.lang.Object
  extended by weblogic.cluster.singleton.LeaseManager
All Implemented Interfaces:
Leasing, weblogic.timers.NakedTimerListener, weblogic.timers.TimerListener

public class LeaseManager
extends Object
implements Leasing, weblogic.timers.NakedTimerListener

Implementation of the Leasing interface.


Field Summary
static String DELIMITER
           
static String DIVIDER
           
static String FAILED
           
 
Constructor Summary
LeaseManager(LeasingBasis basis, int heartbeatPeriod, int healthCheckPeriod, int gracePeriod, String leaseType)
          Create a new LeaseManager.
 
Method Summary
 void acquire(String leaseName, LeaseObtainedListener listener)
          Registers interest in claiming ownership of a lease for this server whenever it becomes available.
 void addLeaseLostListener(LeaseLostListener listener)
          Add a LeaseLostListener.
 String[] findExpiredLeases()
          Returns a list of the servers that have consistently missed sending heartbeats in a timely manner, AND have gone past their grace period.
 String findOwner(String leaseName)
          Returns the identity of the server that currently owns the lease.
 String findPreviousOwner(String leaseName)
           
 int getGracePeriod()
           
static String getOwnerIdentity(weblogic.protocol.ServerIdentity id)
           
static String getServerNameFromOwnerIdentity(String ownerIdentity)
           
 void release(String leaseName)
          If the lease is owned by this server, attempts to give up ownership.
 void removeLeaseLostListener(LeaseLostListener listener)
          Remove a LeaseLostListener.
 void start()
           
 void stop()
          During shutdown operation, LeaseManager should give up his leases so that some other server in the cluster can take over the role.
 void timerExpired(weblogic.timers.Timer timer)
          Regularly called by the timer service.
 boolean tryAcquire(String leaseName)
          Attempts to claim immediate ownership of a lease for this server.
 void voidLeases()
           
 void voidLeases(String owner)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FAILED

public static final String FAILED
See Also:
Constant Field Values

DELIMITER

public static final String DELIMITER
See Also:
Constant Field Values

DIVIDER

public static final String DIVIDER
See Also:
Constant Field Values
Constructor Detail

LeaseManager

public LeaseManager(LeasingBasis basis,
                    int heartbeatPeriod,
                    int healthCheckPeriod,
                    int gracePeriod,
                    String leaseType)
Create a new LeaseManager.

Parameters:
basis - The underlying implementation of Leasing.
heartbeatPeriod - The rate at which heartbeats are sent in ms
healthCheckPeriod - If a server is unable to send a heartbeat within the healthCheckPeriod in ms, it must take corrective action.
gracePeriod - How long to wait, in ms, after the last time the previous owner has successfully sent a heartbeat before it is permissible migrate a server based on that lease.
leaseType - the type of the lease, in the form of a unique string. For example, 'singletonService', 'server', 'timer', 'ejbtimer', etc. All leases of a particular type should have the same leaseType.
Method Detail

tryAcquire

public boolean tryAcquire(String leaseName)
                   throws LeasingException
Attempts to claim immediate ownership of a lease for this server. Returns true if the lease was successfully claimed or if it is already owned by the server. Returns false if the lease is owned by another server. Throws a LeasingException if this server is already waiting to get the lease (through lease()) or if there were infrastructure problems trying to get ownership.

Specified by:
tryAcquire in interface Leasing
Throws:
LeasingException - if this server is already waiting to get the lease (through Leasing.acquire(java.lang.String, weblogic.cluster.singleton.LeaseObtainedListener)) or if there were infrastructure problems trying to get ownership.

acquire

public void acquire(String leaseName,
                    LeaseObtainedListener listener)
             throws LeasingException
Registers interest in claiming ownership of a lease for this server whenever it becomes available. Notification of successful claiming of the lease is provided through the LeaseObtainedListener. Notification occurs (again) if the lease is already owned by this server. Throws a LeasingException if this server is already waiting to get the lease (through a previous call to lease()). Does NOT throw an exception if there were infrastructure problems trying to get ownership.

Specified by:
acquire in interface Leasing
Throws:
LeasingException - if this server is already waiting to get the lease (through a previous call to lease()). Will callback via LeaseObtainedListener with an exception if there are infrastructure problems obtaining the lease. This callback will NOT cancel the interest in claiming ownership. The leaser must do so themselves via release.

release

public void release(String leaseName)
             throws LeasingException
If the lease is owned by this server, attempts to give up ownership. If this server is waiting to get the lease (through lease()), cancels the registration. Otherwise does nothing. Throws a LeasingException if infrastructure problems make it impossible to access the lease.

Specified by:
release in interface Leasing
Throws:
LeasingException - if infrastructure problems make it impossible to access the lease.

findOwner

public String findOwner(String leaseName)
                 throws LeasingException
Returns the identity of the server that currently owns the lease. Returns null if the lease is not owned. The lease is not considered to be owned if it has been claimed by a server that has missed heartbeats. This is a best-effort result in that the answer may change after the value is returned. Throws a LeasingException if infrastructure problems make it impossible to determine who owns the lease.

Specified by:
findOwner in interface Leasing
Throws:
LeasingException - if infrastructure problems make it impossible to determine who owns the lease.

findPreviousOwner

public String findPreviousOwner(String leaseName)
                         throws LeasingException
Throws:
LeasingException

getOwnerIdentity

public static String getOwnerIdentity(weblogic.protocol.ServerIdentity id)

getServerNameFromOwnerIdentity

public static String getServerNameFromOwnerIdentity(String ownerIdentity)

addLeaseLostListener

public void addLeaseLostListener(LeaseLostListener listener)
Add a LeaseLostListener. Called back if the local server ever misses sending a heartbeat in a timely manner.

Specified by:
addLeaseLostListener in interface Leasing

removeLeaseLostListener

public void removeLeaseLostListener(LeaseLostListener listener)
Remove a LeaseLostListener.

Specified by:
removeLeaseLostListener in interface Leasing

getGracePeriod

public int getGracePeriod()

findExpiredLeases

public String[] findExpiredLeases()
Returns a list of the servers that have consistently missed sending heartbeats in a timely manner, AND have gone past their grace period. Will only return the leases associated with this LeaseManager's Lease Type.

Leasing services also include a method LeaseManager.findExpiredLeases() that returns a list of all servers in the cluster that have consistently missed sending heartbeats in a timely manner. INVARIANT: If a server stops heartbeating PERMANENTLY, then it will EVENTUALLY be returned in this list, although there is no guarantee as to how long that will take. This method might be used by a centralized control process, such as a Cluster Master, to migrate failed servers.


stop

public void stop()
During shutdown operation, LeaseManager should give up his leases so that some other server in the cluster can take over the role.


start

public void start()

voidLeases

public void voidLeases()

voidLeases

public void voidLeases(String owner)

timerExpired

public void timerExpired(weblogic.timers.Timer timer)
Regularly called by the timer service. Attempts to send a heartbeat to prove the health of the server. If a heartbeat was missed, calls back any registered leaseLostListeners. Checks whether any leases that this server is waiting to obtain have become available.

Specified by:
timerExpired in interface weblogic.timers.TimerListener
Parameters:
timer - The timer that expired and caused the listener to be invoked.

Copyright 1996, 2011, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

Oracle Fusion Middleware
Oracle WebLogic Server API Reference
11g Release 1 (10.3.6)

Part Number E13941-06