org.apache.ojb.broker.locking
Interface LockManager

All Superinterfaces:
IsolationLevels
All Known Implementing Classes:
LockManagerCommonsImpl, LockManagerInMemoryImpl, LockManagerRemoteImpl

public interface LockManager
extends IsolationLevels

This interface declares the functionality of the OJB locking-api for support of pessimistic locking.

OJB allows to provide user defined implementations of this interface. To activate a user defined LockManager implementation it must be configured in the OJB.properties file.

All locks have to be reentrant, this means if you already have a lock for writing and you try to acquire write access again you will not be blocked by this first lock.

It's optional to support the lockTimeout and blockTimeout properties.

Version:
$Id: LockManager.java 365232 2005-12-21 22:36:07Z tomdz $
See Also:
LockManagerInMemoryImpl, LockManagerCommonsImpl

Field Summary
static long DEFAULT_BLOCK_TIMEOUT
          Default lock wait time in millisecond - set to 1000 ms;
static long DEFAULT_LOCK_TIMEOUT
          Default lock timeout value - set to 60000 ms.
 
Fields inherited from interface org.apache.ojb.broker.locking.IsolationLevels
IL_DEFAULT, IL_NONE, IL_OPTIMISTIC, IL_READ_COMMITTED, IL_READ_UNCOMMITTED, IL_REPEATABLE_READ, IL_SERIALIZABLE, LITERAL_IL_NONE, LITERAL_IL_OPTIMISTIC, LITERAL_IL_READ_COMMITTED, LITERAL_IL_READ_UNCOMMITTED, LITERAL_IL_REPEATABLE_READ, LITERAL_IL_SERIALIZABLE
 
Method Summary
 long getBlockTimeout()
          The maximal time to wait for acquire a lock.
 java.lang.String getLockInfo()
          Returns info about the used lock manager implementation and the state of the lock manager.
 long getLockTimeout()
          Get the current used lock timeout value in milliseconds.
 boolean hasRead(java.lang.Object key, java.lang.Object resourceId)
          Checks if there is a read lock for owner key on resource object.
 boolean hasUpgrade(java.lang.Object key, java.lang.Object resourceId)
          Checks if there is a upgrade lock for lock key on resource object.
 boolean hasWrite(java.lang.Object key, java.lang.Object resourceId)
          Checks if there is a write lock for lock key on resource object.
 boolean readLock(java.lang.Object key, java.lang.Object resourceId, int isolationLevel)
          Acquires a readlock for lock key on resource object.
 boolean releaseLock(java.lang.Object key, java.lang.Object resourceId)
          Releases a lock for lock key on resource object.
 void releaseLocks(java.lang.Object key)
          Release all resource locks hold by the specified owner key.
 void setBlockTimeout(long timeout)
          Set the maximal time to wait for acquire a lock in milliseconds.
 void setLockTimeout(long timeout)
          Set the lock timeout value in milliseconds.
 boolean upgradeLock(java.lang.Object key, java.lang.Object resourceId, int isolationLevel)
          Acquire an upgrade lock.
 boolean writeLock(java.lang.Object key, java.lang.Object resourceId, int isolationLevel)
          Acquires a write lock for lock key on resource object.
 

Field Detail

DEFAULT_LOCK_TIMEOUT

static final long DEFAULT_LOCK_TIMEOUT
Default lock timeout value - set to 60000 ms.

See Also:
Constant Field Values

DEFAULT_BLOCK_TIMEOUT

static final long DEFAULT_BLOCK_TIMEOUT
Default lock wait time in millisecond - set to 1000 ms;

See Also:
Constant Field Values
Method Detail

getBlockTimeout

long getBlockTimeout()
The maximal time to wait for acquire a lock.

Returns:

setBlockTimeout

void setBlockTimeout(long timeout)
Set the maximal time to wait for acquire a lock in milliseconds. All so called non-blocking implementation will ignore this setting.

Parameters:
timeout - The time to wait for acquire a lock.

getLockTimeout

long getLockTimeout()
Get the current used lock timeout value in milliseconds.

Returns:
Current used locking timeout value in ms.

setLockTimeout

void setLockTimeout(long timeout)
Set the lock timeout value in milliseconds. If timeout was set to -1 the never will never timeout.

Parameters:
timeout - The lock timeout in ms of acquired read/write/upgrade locks.

getLockInfo

java.lang.String getLockInfo()
Returns info about the used lock manager implementation and the state of the lock manager.


readLock

boolean readLock(java.lang.Object key,
                 java.lang.Object resourceId,
                 int isolationLevel)
Acquires a readlock for lock key on resource object. Returns true if successful, else false.

Parameters:
key - The owner key of the lock.
resourceId - The resource to lock.
isolationLevel - The isolation level of the lock.
Returns:
True if the lock was successfully acquired.

writeLock

boolean writeLock(java.lang.Object key,
                  java.lang.Object resourceId,
                  int isolationLevel)
Acquires a write lock for lock key on resource object. Returns true if successful, else false.

Parameters:
key - The owner key of the lock.
resourceId - The resource to lock.
isolationLevel - The isolation level of the lock.
Returns:
True if the lock was successfully acquired.

upgradeLock

boolean upgradeLock(java.lang.Object key,
                    java.lang.Object resourceId,
                    int isolationLevel)
Acquire an upgrade lock. (Current implementations always acquire a write lock instead).

Parameters:
key - The owner key of the lock.
resourceId - The resource to lock.
isolationLevel - The isolation level of the lock.
Returns:
True if the lock was successfully acquired.

releaseLock

boolean releaseLock(java.lang.Object key,
                    java.lang.Object resourceId)
Releases a lock for lock key on resource object. Returns true if successful, else false.

Parameters:
key - The owner key of the lock.
resourceId - The resource to release.
Returns:
True if the lock was successfully released.

releaseLocks

void releaseLocks(java.lang.Object key)
Release all resource locks hold by the specified owner key.

Parameters:
key - The owner key to release all associated locks.

hasRead

boolean hasRead(java.lang.Object key,
                java.lang.Object resourceId)
Checks if there is a read lock for owner key on resource object. Returns true if so, else false.

Parameters:
key - The owner key of the lock.
resourceId - The resource to check.
Returns:
True if the lock exists.

hasWrite

boolean hasWrite(java.lang.Object key,
                 java.lang.Object resourceId)
Checks if there is a write lock for lock key on resource object. Returns true if so, else false.

Parameters:
key - The owner key of the lock.
resourceId - The resource to check.
Returns:
True if the lock exists.

hasUpgrade

boolean hasUpgrade(java.lang.Object key,
                   java.lang.Object resourceId)
Checks if there is a upgrade lock for lock key on resource object. Returns true if so, else false.

Parameters:
key - The owner key of the lock.
resourceId - The resource to check.
Returns:
True if the lock exists.


(C) 2002 - 2006 Apache Software Foundation
All rights reserved. Published under the Apache License 2.0.
http://db.apache.org/ojb
Version: 1.0.4, 2005-12-30