Holger's Java API

## com.antelmann.db
Class LockManager

    java.lang.Object
      com.antelmann.db.LockManager

All Implemented Interfaces:
  Wrapped<DBClassStore<LockEntry>>

    public class LockManager

extends Object
implements Wrapped<DBClassStore<LockEntry>>

provides methods for persistent locks on DBEntry objects. This class requires a proper store capable of handling LockEntry objects (including a working `DBClassStore.generateNewID()` method). Generally, reference may be locked even though the do not exist in the database.

Since:
  27.04.2011, 19:44:51
Author:
  holger

Constructor Summary
`LockManager(DBClassStore<LockEntry> store)`

Method Summary
`boolean` `forceUnlock(DBReference ref, long lockTime)` if you don't have the token, you may first obtain the LockInfo and then use its time to release the given lock
`int` `forceUnlockForAll(long anyLockAquiredBeforeThisTime)`
`String` `generateToken()`
`Filter<LockEntry>` `getFilterFor(DBReference ref)` this may want to be overridden to be more efficient based on the mapping in use
`LockInfo` `getLockInfo(DBReference ref)`
`DBClassStore<LockEntry>` `getStore()`
`TimeSystem` `getTimeSystem()`
`boolean` `isLocked(DBReference ref)`
`boolean` `isLockedWithToken(DBReference ref, String token)`
`String` `lock(DBReference ref, String who, String where, String why)`
`boolean` `release(DBReference ref, String token)`
`void` `setTimeSystem(TimeSystem ts)`
`void` `setWriteLockTask(Task<Exception> task)`
`boolean` `unlock(DBReference ref, String token)`
`DBClassStore<LockEntry>` `unwrap()` returns the embedded instance that this wrapper encloses
`void` `writeLock()` provides a way to put a write lock on the associated data from the store so that we can avoid deadlocks

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### LockManager

    public LockManager(DBClassStore<LockEntry> store)

Method Detail

### getStore

    public DBClassStore<LockEntry> getStore()

### unwrap

    public DBClassStore<LockEntry> unwrap()

  Description copied from interface: `Wrapped`
  returns the embedded instance that this wrapper encloses

  Specified by:
    `unwrap` in interface `Wrapped<DBClassStore<LockEntry>>`

### isLocked

    public boolean isLocked(DBReference ref)
                     throws DatabaseException

  Throws:
    `DatabaseException`

### isLockedWithToken

    public boolean isLockedWithToken(DBReference ref,
                                     String token)
                              throws DatabaseException

  Throws:
    `DatabaseException`

### getLockInfo

    public LockInfo getLockInfo(DBReference ref)
                         throws DatabaseException

  Returns:
    a LockInfo for the given reference or null if the ref is not locked
  Throws:
    `DatabaseException`

### writeLock

    public void writeLock()
                   throws Exception

  provides a way to put a write lock on the associated data from the store so that we can avoid deadlocks

  Throws:
    `Exception`
  See Also:
    `setWriteLockTask(Task)`

### setWriteLockTask

    public void setWriteLockTask(Task<Exception> task)

  See Also:
    `writeLock()`

### lock

    public String lock(DBReference ref,
                       String who,
                       String where,
                       String why)
                throws DatabaseException,
                       NotApplicableDataWarning

  Returns:
    the token for this lock
  Throws:
    `DatabaseException`
    `NotApplicableDataWarning`

### unlock

    public boolean unlock(DBReference ref,
                          String token)
                   throws NotApplicableDataWarning,
                          DatabaseException

  Throws:
    `NotApplicableDataWarning`
    `DatabaseException`
  See Also:
    `release(DBReference, String)`

### release

    public boolean release(DBReference ref,
                           String token)
                    throws NotApplicableDataWarning,
                           DatabaseException

  Throws:
    `NotApplicableDataWarning`
    `DatabaseException`

### forceUnlock

    public boolean forceUnlock(DBReference ref,
                               long lockTime)
                        throws DatabaseException

  if you don't have the token, you may first obtain the LockInfo and then use its time to release the given lock

  Throws:
    `DatabaseException`

### forceUnlockForAll

    @Warning(value="goes through all entries and deletes all those that qualify; use w/ caution!")
    public int forceUnlockForAll(long anyLockAquiredBeforeThisTime)
                          throws DatabaseException

  Throws:
    `DatabaseException`

### getTimeSystem

    public TimeSystem getTimeSystem()

### setTimeSystem

    public void setTimeSystem(TimeSystem ts)

### generateToken

    public String generateToken()

### getFilterFor

    public Filter<LockEntry> getFilterFor(DBReference ref)

  this may want to be overridden to be more efficient based on the mapping in use

(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads