org.entityfs.lock
Interface LockAdapter

All Known Subinterfaces:
EntityLockAdapter
All Known Implementing Classes:
ReadWriteEntityLockAdapter, ReentrantLockAdapter

public interface LockAdapter

The lock adapter is used as a generic interface to an object's locks. It is created by a file system's LockAdapterFactory. A lock adapter contains one or more locks that are identified by identifier objects. The locks use the file system's LockAcquiringStrategy when locking.

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

Method Summary
 void createLockForIdentifier(Object identifier)
          Create a lock for the unique (in the lock adapter instance) identifier.
 Lock getLock(Object identifier)
          Get the lock identified by the identifier.
 

Method Detail

createLockForIdentifier

void createLockForIdentifier(Object identifier)
                             throws IllegalArgumentException
Create a lock for the unique (in the lock adapter instance) identifier. How the lock is created is up to the implementation.

This must be called before using a lock to ensure that it exists in the lock adapter. It typically called by the lock-using object's constructor.

Locks created by calling this method can later be retrieved by calling getLock(Object).

Parameters:
identifier - An identifier that is unique for the lock-using object. This may be any kind of object, a static Object constant, for instance.
Throws:
IllegalArgumentException - If there already is a lock for the same identifier.

getLock

Lock getLock(Object identifier)
Get the lock identified by the identifier. The lock must have been defined by calling createLockForIdentifier(Object) before it can be retrieved by this method.

Parameters:
identifier - The identifier for the lock. The identifier for each defined lock is unique in the lock adapter instance.
Returns:
The lock, or null if no lock is defined for the identifier.