com.anthonyeden.lib.db
Class LockManager

java.lang.Object
  extended bycom.anthonyeden.lib.db.LockManager

public class LockManager
extends java.lang.Object

A database-independent lock manager. Applications can aquire a named lock and execute actions on that lock.

When a lock is aquired it is mapped to the current thread. Only that thread can do operations with that lock. The lock is leased for a limited amount of time. If the lock is not released prior to that time then a LeaseMonitorThread will force the release of the lock.

The aquireLock() method can try more than once to aquire a lock for a caller. The number of retries and the delay between retries can be specified for each LockManager.

Author:
Anthony Eden

Field Summary
static int DEFAULT_LEASE_TIME
          The default lease time (30 seconds).
static int DEFAULT_RETRY_DELAY
          The default retry delay (5 seconds).
static int DEFAULT_RETRY_LIMIT
          The default retry limit (3).
 
Constructor Summary
LockManager(java.sql.Connection connection)
          Construct a new LockManager using the given JDBC connection.
 
Method Summary
 void aquireLock(java.lang.String name)
          Aquire a named lock.
 int getLeaseTime()
          Get the lease time.
 int getRetryDelay()
          Get the retry delay.
 int getRetryLimit()
          Get the retry limit.
 void releaseLock(java.lang.String name)
          Release a named lock.
 void setLeaseTime(int leaseTime)
          Set the lease time.
 void setRetryDelay(int retryDelay)
          Set the retry delay.
 void setRetryLimit(int retryLimit)
          Set the retry limit.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_LEASE_TIME

public static final int DEFAULT_LEASE_TIME
The default lease time (30 seconds).

See Also:
Constant Field Values

DEFAULT_RETRY_LIMIT

public static final int DEFAULT_RETRY_LIMIT
The default retry limit (3).

See Also:
Constant Field Values

DEFAULT_RETRY_DELAY

public static final int DEFAULT_RETRY_DELAY
The default retry delay (5 seconds).

See Also:
Constant Field Values
Constructor Detail

LockManager

public LockManager(java.sql.Connection connection)
            throws java.sql.SQLException
Construct a new LockManager using the given JDBC connection.

Parameters:
connection - The JDBC connection
Throws:
java.sql.SQLException
Method Detail

aquireLock

public void aquireLock(java.lang.String name)
                throws LockException
Aquire a named lock.

Parameters:
name - The name of the lock
Throws:
LockException - If the lock cannot be aquired

releaseLock

public void releaseLock(java.lang.String name)
                 throws LockException
Release a named lock.

Parameters:
name - The lock name
Throws:
LockException - If the lock release fails

getLeaseTime

public int getLeaseTime()
Get the lease time.

Returns:
The lease time in milliseconds

setLeaseTime

public void setLeaseTime(int leaseTime)
Set the lease time.

Parameters:
leaseTime - The lease time in milliseconds

getRetryLimit

public int getRetryLimit()
Get the retry limit.

Returns:
The retry limit

setRetryLimit

public void setRetryLimit(int retryLimit)
Set the retry limit.

Parameters:
retryLimit - The retry limit

getRetryDelay

public int getRetryDelay()
Get the retry delay.

Returns:
The retry delay

setRetryDelay

public void setRetryDelay(int retryDelay)
Set the retry delay.

Parameters:
retryDelay - The retry delay in milliseconds


Copyright (c) 2000-2003 Anthony Eden. All Rights Reserved.