hu.netmind.beankeeper
Interface LockTracker


public interface LockTracker

This class tracks locks on objects. Any persistable object can be locked, just like with the synchronized keyword in Java, and it does roughly the same thing too. If an object is locked, no database operations can occur outside of the lock owner transaction. All Store operations automatically try to lock the objects they work with, so there can't be any concurrent modifications.
You can also lock classes or interfaces. These equal to locking database tables, only they are hierarchical. That means, if you lock a class, all subclasses will also be locked automatically. For example, if you lock Object.class successfully, then only the owner of that lock will be able to modify anything. Of course, a class can't be locked, if there is another thread which holds lock on any super-, or sub-classes, or any instances of this class, or any subclass.
There are two flavors of locks: read-only locks and read-write locks. In short, read-only locks prevent read-write locks to be established (and with it prevent save() and remove() calls). While read-write locks prevent both other read-write locks and read-only locks too. Note, that using the find() methods is prevented with none of the locks, since the finders always work correctly, representing a consistent state at the moment when the find() is executed.


Method Summary
 SessionInfoProvider getProvider()
          Get the session provider of locks.
 void lock(java.lang.Object obj)
          Lock a single object.
 void lock(java.lang.Object[] objs)
          Lock multiple objects.
 void lock(java.lang.Object[] objs, int wait)
          Lock multiple objects.
 void lock(java.lang.Object[] objs, SessionInfo info, int wait, boolean ensureCurrent, boolean readOnly)
          Lock multiple objects with all possible parameters specified.
 void lock(java.lang.Object obj, int wait)
          Lock a single object with wait period given.
 void lock(java.lang.Object obj, SessionInfo info)
          Lock a single object with the session information given.
 void lockEnsureCurrent(java.lang.Object obj)
          Lock a single object, and ensure that the object given is the most recent version of the object.
 void lockEnsureCurrent(java.lang.Object[] objs)
          Lock multiple objects, and check whether given objects are current.
 void lockEnsureCurrent(java.lang.Object[] objs, int wait)
          Lock multiple objects, and check whether given objects are current.
 void lockEnsureCurrent(java.lang.Object obj, int wait)
          Lock a single object, and guarantee it's current.
 void lockEnsureCurrent(java.lang.Object obj, SessionInfo info)
          Lock a single object with the session information given, and check is the given object is the current version.
 void lockReadOnly(java.lang.Object obj)
          Lock a single object read-only.
 void lockReadOnly(java.lang.Object[] objs)
          Lock multiple objects read-only.
 void lockReadOnly(java.lang.Object[] objs, int wait)
          Lock multiple objects read-only.
 void lockReadOnly(java.lang.Object obj, int wait)
          Lock a single object read-only with wait period given.
 void lockReadOnly(java.lang.Object obj, SessionInfo info)
          Lock a single object read-only with the session information given.
 void lockReadOnlyEnsureCurrent(java.lang.Object obj)
          Lock a single object read-only, and ensure that the object given is the most recent version of the object.
 void lockReadOnlyEnsureCurrent(java.lang.Object[] objs)
          Lock multiple objects read-only, and check whether given objects are current.
 void lockReadOnlyEnsureCurrent(java.lang.Object[] objs, int wait)
          Lock multiple objects read-only, and check whether given objects are current.
 void lockReadOnlyEnsureCurrent(java.lang.Object obj, int wait)
          Lock a single object read-only, and guarantee it's current.
 void lockReadOnlyEnsureCurrent(java.lang.Object obj, SessionInfo info)
          Lock a single object read-only with the session information given, and check is the given object is the current version.
 void setProvider(SessionInfoProvider provider)
          Set the session info provider implementation.
 void unlock(java.lang.Object obj)
          Unlock a single object.
 void unlock(java.lang.Object[] objs)
          Unlock multiple objects.
 

Method Detail

getProvider

SessionInfoProvider getProvider()
Get the session provider of locks. A session provider is a factory class that creates a session object for the locks. A session info object is a map which holds data about the lock session.


setProvider

void setProvider(SessionInfoProvider provider)
Set the session info provider implementation.


lockEnsureCurrent

void lockEnsureCurrent(java.lang.Object obj)
Lock a single object, and ensure that the object given is the most recent version of the object. The session information is gathered from the session info provider.

Throws:
ConcurrentModificationException - If the object is already locked by another thread.

lock

void lock(java.lang.Object obj)
Lock a single object. The session information is gathered from the session info provider.

Throws:
ConcurrentModificationException - If the object is already locked by another thread.

lockEnsureCurrent

void lockEnsureCurrent(java.lang.Object obj,
                       int wait)
Lock a single object, and guarantee it's current. The session information is gathered from the session info provider.

Parameters:
obj - The object to lock.
wait - Wait the given amount of milliseconds for the lock to free up. Method only throws ConcurrentModificationException if the lock is not available in the given time.
Throws:
ConcurrentModificationException - If the object is already locked by another thread.

lock

void lock(java.lang.Object obj,
          int wait)
Lock a single object with wait period given. The session information is gathered from the session info provider.

Parameters:
obj - The object to lock.
wait - Wait the given amount of milliseconds for the lock to free up. Method only throws ConcurrentModificationException if the lock is not available in the given time.
Throws:
ConcurrentModificationException - If the object is already locked by another thread.

lockEnsureCurrent

void lockEnsureCurrent(java.lang.Object obj,
                       SessionInfo info)
Lock a single object with the session information given, and check is the given object is the current version.

Throws:
ConcurrentModificationException - If the object is already locked by another thread.

lock

void lock(java.lang.Object obj,
          SessionInfo info)
Lock a single object with the session information given.

Throws:
ConcurrentModificationException - If the object is already locked by another thread.

lockEnsureCurrent

void lockEnsureCurrent(java.lang.Object[] objs)
Lock multiple objects, and check whether given objects are current. The session information is gathered from the session info provider. Use this method, if you want to lock multiple objects at the same time.

Throws:
ConcurrentModificationException - If the object is already locked by another thread.

lock

void lock(java.lang.Object[] objs)
Lock multiple objects. The session information is gathered from the session info provider. Use this method, if you want to lock multiple objects at the same time.

Throws:
ConcurrentModificationException - If the object is already locked by another thread.

lockEnsureCurrent

void lockEnsureCurrent(java.lang.Object[] objs,
                       int wait)
Lock multiple objects, and check whether given objects are current. The session information is gathered from the session info provider. Use this method, if you want to lock multiple objects at the same time.

Parameters:
wait - Wait the given amount of milliseconds for the lock to free up. Method only throws ConcurrentModificationException if the lock is not available in the given time.
Throws:
ConcurrentModificationException - If the object is already locked by another thread.

lock

void lock(java.lang.Object[] objs,
          int wait)
Lock multiple objects. The session information is gathered from the session info provider. Use this method, if you want to lock multiple objects at the same time.

Parameters:
wait - Wait the given amount of milliseconds for the lock to free up. Method only throws ConcurrentModificationException if the lock is not available in the given time.
Throws:
ConcurrentModificationException - If the object is already locked by another thread.

lockReadOnlyEnsureCurrent

void lockReadOnlyEnsureCurrent(java.lang.Object obj)
Lock a single object read-only, and ensure that the object given is the most recent version of the object. The session information is gathered from the session info provider.

Throws:
ConcurrentModificationException - If the object is already locked by another thread.

lockReadOnly

void lockReadOnly(java.lang.Object obj)
Lock a single object read-only. The session information is gathered from the session info provider.

Throws:
ConcurrentModificationException - If the object is already locked by another thread.

lockReadOnlyEnsureCurrent

void lockReadOnlyEnsureCurrent(java.lang.Object obj,
                               int wait)
Lock a single object read-only, and guarantee it's current. The session information is gathered from the session info provider.

Parameters:
obj - The object to lock.
wait - Wait the given amount of milliseconds for the lock to free up. Method only throws ConcurrentModificationException if the lock is not available in the given time.
Throws:
ConcurrentModificationException - If the object is already locked by another thread.

lockReadOnly

void lockReadOnly(java.lang.Object obj,
                  int wait)
Lock a single object read-only with wait period given. The session information is gathered from the session info provider.

Parameters:
obj - The object to lock.
wait - Wait the given amount of milliseconds for the lock to free up. Method only throws ConcurrentModificationException if the lock is not available in the given time.
Throws:
ConcurrentModificationException - If the object is already locked by another thread.

lockReadOnlyEnsureCurrent

void lockReadOnlyEnsureCurrent(java.lang.Object obj,
                               SessionInfo info)
Lock a single object read-only with the session information given, and check is the given object is the current version.

Throws:
ConcurrentModificationException - If the object is already locked by another thread.

lockReadOnly

void lockReadOnly(java.lang.Object obj,
                  SessionInfo info)
Lock a single object read-only with the session information given.

Throws:
ConcurrentModificationException - If the object is already locked by another thread.

lockReadOnlyEnsureCurrent

void lockReadOnlyEnsureCurrent(java.lang.Object[] objs)
Lock multiple objects read-only, and check whether given objects are current. The session information is gathered from the session info provider. Use this method, if you want to lock multiple objects at the same time.

Throws:
ConcurrentModificationException - If the object is already locked by another thread.

lockReadOnly

void lockReadOnly(java.lang.Object[] objs)
Lock multiple objects read-only. The session information is gathered from the session info provider. Use this method, if you want to lock multiple objects at the same time.

Throws:
ConcurrentModificationException - If the object is already locked by another thread.

lockReadOnlyEnsureCurrent

void lockReadOnlyEnsureCurrent(java.lang.Object[] objs,
                               int wait)
Lock multiple objects read-only, and check whether given objects are current. The session information is gathered from the session info provider. Use this method, if you want to lock multiple objects at the same time.

Parameters:
wait - Wait the given amount of milliseconds for the lock to free up. Method only throws ConcurrentModificationException if the lock is not available in the given time.
Throws:
ConcurrentModificationException - If the object is already locked by another thread.

lockReadOnly

void lockReadOnly(java.lang.Object[] objs,
                  int wait)
Lock multiple objects read-only. The session information is gathered from the session info provider. Use this method, if you want to lock multiple objects at the same time.

Parameters:
wait - Wait the given amount of milliseconds for the lock to free up. Method only throws ConcurrentModificationException if the lock is not available in the given time.
Throws:
ConcurrentModificationException - If the object is already locked by another thread.

lock

void lock(java.lang.Object[] objs,
          SessionInfo info,
          int wait,
          boolean ensureCurrent,
          boolean readOnly)
Lock multiple objects with all possible parameters specified. Use this method, if you want to lock multiple objects at the same time. If classes are asked to be ensured to be current, the following date is taken into account: Whichever was earlier, the classes are checked against that date.

Parameters:
objs - The objects to lock simultaniously.
info - The session info to memorize for this lock. This object will be included in the ConcurrentModificationException.
wait - Wait the given amount of milliseconds for the lock to free up. Method only throws ConcurrentModificationException if the lock is not available in the given time.
ensureCurrent - Do the objects need to be guaranteed to be current. If this flag is set, the lock operation will fail, if any supplied object has a newer version.
readOnly - Whether the lock should be read-only. If a lock is read-only, then other read-only locks can still be established on the specified objects, read-write locks will however fail.
Throws:
ConcurrentModificationException - If the object is already locked by another process.

unlock

void unlock(java.lang.Object obj)
Unlock a single object. If the object is not locked, nothing is done.


unlock

void unlock(java.lang.Object[] objs)
Unlock multiple objects.