org.entityfs.lock.impl
Class AbstractLockAcquiringStrategy

java.lang.Object
  extended by org.entityfs.lock.impl.AbstractLockAcquiringStrategy
All Implemented Interfaces:
LockAcquiringStrategy
Direct Known Subclasses:
SimpleLockAcquiringStrategy, TimeoutLockAcquiringStrategy

public abstract class AbstractLockAcquiringStrategy
extends Object
implements LockAcquiringStrategy

Abstract base class for lock acquiring strategy classes. Subclasses only have to implement the lockIt(Lock) method.

Since:
1.0
Author:
Karl Gustafsson
In_jar:
entityfs-core

Constructor Summary
AbstractLockAcquiringStrategy()
           
 
Method Summary
 EntityLock getEntityLock(Object identifier, EntityLockAdapter la, LogAdapter lga)
          Get a custom entity lock for an entity from its lock adapter.
 Lock getLock(Object identifier, LockAdapter la, LogAdapter lga)
          Lock a custom lock that is not tied to any specific entity.
 EntityLock getReadLock(EntityLockAdapter la, LogAdapter lga)
          Get a locked read lock for an entity from its lock adapter.
 EntityLock getWriteLock(EntityLockAdapter la, LogAdapter lga)
          Get a locked write lock for an entity from its lock adapter.
protected abstract  boolean lockIt(Lock l)
          Subclasses implement this to lock the given lock.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractLockAcquiringStrategy

public AbstractLockAcquiringStrategy()
Method Detail

lockIt

protected abstract boolean lockIt(Lock l)
                           throws InterruptedException
Subclasses implement this to lock the given lock.

Parameters:
l - The lock.
Returns:
true if successful, false otherwise. When false is returned, it is interpreted as due to a timeout.
Throws:
InterruptedException - If the thread is interrupted while trying to acquire the lock.

getReadLock

public final EntityLock getReadLock(EntityLockAdapter la,
                                    LogAdapter lga)
Description copied from interface: LockAcquiringStrategy
Get a locked read lock for an entity from its lock adapter.

Specified by:
getReadLock in interface LockAcquiringStrategy
Parameters:
la - The entity's lock adapter.
lga - The file system's current log adapter.
Returns:
A locked read lock.

getWriteLock

public EntityLock getWriteLock(EntityLockAdapter la,
                               LogAdapter lga)
Description copied from interface: LockAcquiringStrategy
Get a locked write lock for an entity from its lock adapter.

Specified by:
getWriteLock in interface LockAcquiringStrategy
Parameters:
la - The entity's lock adapter.
lga - The file system's current log adapter.
Returns:
A locked write lock.

getEntityLock

public EntityLock getEntityLock(Object identifier,
                                EntityLockAdapter la,
                                LogAdapter lga)
Description copied from interface: LockAcquiringStrategy
Get a custom entity lock for an entity from its lock adapter. The lock must have been registered with the entity lock adapter's createEntityLockForIdentifier(Object, boolean, boolean) method before it can be locked.

Specified by:
getEntityLock in interface LockAcquiringStrategy
Parameters:
identifier - The unique identifier for the lock.
la - The entity's lock adapter
lga - The file system's current log adapter.
Returns:
A locked custom lock.

getLock

public Lock getLock(Object identifier,
                    LockAdapter la,
                    LogAdapter lga)
Description copied from interface: LockAcquiringStrategy
Lock a custom lock that is not tied to any specific entity. The lock must have been registered with the lock adapter's createLockForIdentifier(Object) method before it can be locked.

Specified by:
getLock in interface LockAcquiringStrategy
Parameters:
identifier - The unique identifier for the lock.
la - The lock adapter.
lga - A log adapter
Returns:
A locked lock