uk.ac.ebi.intact.application.editor.util
Class LockManager

java.lang.Object
  |
  +--uk.ac.ebi.intact.application.editor.util.LockManager

public class LockManager
extends java.lang.Object

The lock manager keeps a track of edit objects. It uses the AC as a unique identifier for edit objects. Only a single instance of this class is used by multiple users. This class is thread safe.

Version:
$Id: LockManager.java,v 1.6 2004/02/27 17:23:45 smudali Exp $
Author:
Sugath Mudali (smudali@ebi.ac.uk)

Nested Class Summary
 class LockManager.LockObject
           
 
Method Summary
 boolean acquire(java.lang.String id, java.lang.String owner)
          Obtains a lock.
static LockManager getInstance()
           
 LockManager.LockObject getLock(java.lang.String id)
          Returns the lock object for given id if it exists.
 java.util.List getLocks()
          Returns a clone of the current locks.
 java.lang.String getOwner(java.lang.String id)
          Returns the owner for given id if it exists.
 boolean hasLock(java.lang.String ac)
          Checks the existence of given lock.
 void release(java.lang.String id)
          Removes given lock.
 void releaseAllLocks(java.lang.String owner)
          Release all the locks held by given owner.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static LockManager getInstance()
Returns:
the only instance of this class.

hasLock

public boolean hasLock(java.lang.String ac)
Checks the existence of given lock.

Parameters:
ac - the id to check for the lock
Returns:
true if a lock exists for ac; false is returned for all other instances.

getLock

public LockManager.LockObject getLock(java.lang.String id)
Returns the lock object for given id if it exists.

Parameters:
id - the of the lock.
Returns:
the lock object for id if a lock exists for it. Null is returned if there is no lock object.

getOwner

public java.lang.String getOwner(java.lang.String id)
Returns the owner for given id if it exists.

Parameters:
id - the of the lock.
Returns:
the owner of id if there is an owner or an empty street is returned.

acquire

public boolean acquire(java.lang.String id,
                       java.lang.String owner)
Obtains a lock.

Parameters:
id - the id to obtain the lock for.
owner - the onwer of the lock.
Returns:
true if a lock was acquired successfully; false is returned for all other instances.

release

public void release(java.lang.String id)
Removes given lock.

Parameters:
id - the id for the lock.

releaseAllLocks

public void releaseAllLocks(java.lang.String owner)
Release all the locks held by given owner.

Parameters:
owner - the owner to release the locks for.

getLocks

public java.util.List getLocks()
Returns a clone of the current locks.

Returns:
a clone of the current locks. None of the lock objects are cloned because LockObjects are immutable.


IntAct Project - EMBL-EBI 2004 - intact-help@ebi.ac.uk