org.jboss.cache.lock
Class IdentityLock

java.lang.Object
  extended by org.jboss.cache.lock.IdentityLock
All Implemented Interfaces:
NodeLock

Deprecated. will be removed when we drop support for Pessimistic Locking and Optimistic Locking

@Deprecated
public class IdentityLock
extends Object
implements NodeLock

Lock object which grants and releases locks, and associates locks with owners. The methods to acquire and release a lock require an owner (Object). When a lock is acquired, we store the current owner with the lock. When the same owner (but possibly running in a different thread) wants to acquire the lock, it is immediately granted. When an owner different from the one currently owning the lock wants to release the lock, we do nothing (no-op).

Consider the following example:

 FIFOSemaphore lock=new FIFOSemaphore(1);
 lock.acquire();
 lock.acquire();
 lock.release();
 
This would block on the second acquire() (although we currently already hold the lock) because the lock only has 1 permit. So IdentityLock will allow the following code to work properly:
 IdentityLock lock=new IdentityLock();
 lock.readLock().acquire(this, timeout);
 lock.writeLock().acquire(this, timeout);
 lock.release(this);
 
If the owner is null, then the current thread is taken by default. This allow the following code to work:
 IdentityLock lock=new IdentityLock();
 lock.readLock().attempt(null, timeout);
 lock.writeLock().attempt(null, timeout);
 lock.release(null);
 

Note that the Object given as owner is required to implement Object.equals(java.lang.Object). For a use case see the examples in the testsuite.

Author:
Bela Ban Apr 11, 2003, Ben Wang July 2003

Constructor Summary
IdentityLock(LockStrategyFactory factory, NodeSPI node)
          Deprecated. Creates a new IdentityLock using the LockFactory passed in.
 
Method Summary
 boolean acquire(Object caller, long timeout, LockType lock_type)
          Deprecated.  
 Set<NodeLock> acquireAll(Object caller, long timeout, LockType lock_type)
          Deprecated. Recursively acquire locks for this node and all subnodes, including internal Fqns such as buddy backup subtrees.
 Set<NodeLock> acquireAll(Object caller, long timeout, LockType lock_type, boolean excludeInternalFqns)
          Deprecated. Same as the overloaded NodeLock.acquire(Object, long, LockType) except that you can optionally specify that internal Fqns - such as buddy backup subtrees - can be excluded when acquiring locks.
 boolean acquireReadLock(Object caller, long timeout)
          Deprecated. Acquire a read lock with a timeout period of timeout milliseconds.
 boolean acquireWriteLock(Object caller, long timeout)
          Deprecated. Acquire a write lock with a timeout of timeout milliseconds.
 Fqn getFqn()
          Deprecated. Returns the FQN this lock, may be null.
 LockMap getLockMap()
          Deprecated.  
 Node getNode()
          Deprecated. Returns the node for this lock, may be null.
 Collection<Object> getReaderOwners()
          Deprecated. Return a copy of the reader lock owner in List.
 Object getWriterOwner()
          Deprecated. Return the writer lock owner object.
 boolean isLocked()
          Deprecated. Check if there is a read or write lock
 boolean isOwner(Object o)
          Deprecated. Am I a lock owner?
 boolean isReadLocked()
          Deprecated. Check if there is a read lock.
 boolean isWriteLocked()
          Deprecated. Check if there is a write lock.
 void printLockInfo(StringBuilder sb, int indent)
          Deprecated.  
 void release(Object caller)
          Deprecated. Release the lock held by the owner.
 void releaseAll()
          Deprecated. Release all locks associated with this instance.
 void releaseAll(Object owner)
          Deprecated. Releases all locks with this owner.
 void releaseForce()
          Deprecated. Same as releaseAll now.
 String toString()
          Deprecated.  
 String toString(boolean print_lock_details)
          Deprecated.  
 void toString(StringBuilder sb)
          Deprecated.  
 void toString(StringBuilder sb, boolean print_lock_details)
          Deprecated.  
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IdentityLock

public IdentityLock(LockStrategyFactory factory,
                    NodeSPI node)
Deprecated. 
Creates a new IdentityLock using the LockFactory passed in.

Parameters:
factory - to create lock strategies
node - to lock
Method Detail

getNode

public Node getNode()
Deprecated. 
Returns the node for this lock, may be null.


getFqn

public Fqn getFqn()
Deprecated. 
Returns the FQN this lock, may be null.

Specified by:
getFqn in interface NodeLock

getReaderOwners

public Collection<Object> getReaderOwners()
Deprecated. 
Return a copy of the reader lock owner in List. Size is zero is not available. Note that this list is synchronized.

Specified by:
getReaderOwners in interface NodeLock
Returns:
Collection of readers

getWriterOwner

public Object getWriterOwner()
Deprecated. 
Return the writer lock owner object. Null if not available.

Specified by:
getWriterOwner in interface NodeLock
Returns:
Object owner

getLockMap

public LockMap getLockMap()
Deprecated. 

acquireWriteLock

public boolean acquireWriteLock(Object caller,
                                long timeout)
                         throws LockingException,
                                TimeoutException,
                                InterruptedException
Deprecated. 
Acquire a write lock with a timeout of timeout milliseconds. Note that if the current owner owns a read lock, it will be upgraded automatically. However, if upgrade fails, i.e., timeout, the read lock will be released automatically.

Specified by:
acquireWriteLock in interface NodeLock
Parameters:
caller - Can't be null.
timeout -
Returns:
boolean True if lock was acquired and was not held before, false if lock was held
Throws:
LockingException
TimeoutException
InterruptedException

acquireReadLock

public boolean acquireReadLock(Object caller,
                               long timeout)
                        throws LockingException,
                               TimeoutException,
                               InterruptedException
Deprecated. 
Acquire a read lock with a timeout period of timeout milliseconds.

Specified by:
acquireReadLock in interface NodeLock
Parameters:
caller - Can't be null.
timeout -
Returns:
boolean True if lock was acquired and was not held before, false if lock was held
Throws:
LockingException
TimeoutException
InterruptedException

release

public void release(Object caller)
Deprecated. 
Release the lock held by the owner.

Specified by:
release in interface NodeLock
Parameters:
caller - Can't be null.

releaseAll

public void releaseAll()
Deprecated. 
Release all locks associated with this instance.

Specified by:
releaseAll in interface NodeLock

releaseForce

public void releaseForce()
Deprecated. 
Same as releaseAll now.


isReadLocked

public boolean isReadLocked()
Deprecated. 
Check if there is a read lock.

Specified by:
isReadLocked in interface NodeLock

isWriteLocked

public boolean isWriteLocked()
Deprecated. 
Check if there is a write lock.

Specified by:
isWriteLocked in interface NodeLock

isLocked

public boolean isLocked()
Deprecated. 
Check if there is a read or write lock

Specified by:
isLocked in interface NodeLock

isOwner

public boolean isOwner(Object o)
Deprecated. 
Am I a lock owner?

Specified by:
isOwner in interface NodeLock
Parameters:
o -

toString

public String toString()
Deprecated. 
Overrides:
toString in class Object

toString

public String toString(boolean print_lock_details)
Deprecated. 

toString

public void toString(StringBuilder sb)
Deprecated. 

toString

public void toString(StringBuilder sb,
                     boolean print_lock_details)
Deprecated. 

acquire

public boolean acquire(Object caller,
                       long timeout,
                       LockType lock_type)
                throws LockingException,
                       TimeoutException,
                       InterruptedException
Deprecated. 
Specified by:
acquire in interface NodeLock
Throws:
LockingException
TimeoutException
InterruptedException

acquireAll

public Set<NodeLock> acquireAll(Object caller,
                                long timeout,
                                LockType lock_type)
                         throws LockingException,
                                TimeoutException,
                                InterruptedException
Deprecated. 
Description copied from interface: NodeLock
Recursively acquire locks for this node and all subnodes, including internal Fqns such as buddy backup subtrees.

Specified by:
acquireAll in interface NodeLock
Parameters:
caller - lock owner
timeout - time to wait
lock_type - type of lock
Returns:
locks acquired
Throws:
LockingException
TimeoutException
InterruptedException

acquireAll

public Set<NodeLock> acquireAll(Object caller,
                                long timeout,
                                LockType lock_type,
                                boolean excludeInternalFqns)
                         throws LockingException,
                                TimeoutException,
                                InterruptedException
Deprecated. 
Description copied from interface: NodeLock
Same as the overloaded NodeLock.acquire(Object, long, LockType) except that you can optionally specify that internal Fqns - such as buddy backup subtrees - can be excluded when acquiring locks.

Specified by:
acquireAll in interface NodeLock
Parameters:
caller - lock owner
timeout - time to wait
lock_type - type of lock
excludeInternalFqns - if true, locks on internal fqns are not acquired.
Returns:
locks acquired
Throws:
LockingException
TimeoutException
InterruptedException

releaseAll

public void releaseAll(Object owner)
Deprecated. 
Description copied from interface: NodeLock
Releases all locks with this owner.

Specified by:
releaseAll in interface NodeLock

printLockInfo

public void printLockInfo(StringBuilder sb,
                          int indent)
Deprecated. 
Specified by:
printLockInfo in interface NodeLock


Copyright © 2008 JBoss, a division of Red Hat. All Rights Reserved.