org.progeeks.repository
Class WormSharedLockManager

java.lang.Object
  extended by org.progeeks.repository.WormSharedLockManager
All Implemented Interfaces:
LockManager

public class WormSharedLockManager
extends java.lang.Object
implements LockManager

A locking manager that provides basic distributed locking among several processes assuming that all processes are willing to access repository items in a WORM (Write Once, Read Many) manner. The next repository item id is maintained in a file in the root of the repository. This file is locked by each process only when it needs a new item id. This locking manager is not safe to use with the meta-class cache.

Version:
$Revision: 1.4 $
Author:
Paul Wisneskey

Field Summary
static int DEFAULT_RETRY_TIME
          Default time in milliseconds between locking attempt tries.
protected static java.lang.String ID_FILE
          File used to save the id number to assign to the next added item.
 
Constructor Summary
WormSharedLockManager()
           
 
Method Summary
 void createRepository(java.io.File repositoryDir)
          Creates the repository.
 int getNextItemId()
          Returns the next item id, locking the id file for the read and write so that the id can be guaranteed unique between all the processes using the repository.
 int getRetryTime()
          Returns the time in millseconds to wait between attempts to obtain the id lock.
 void initialize(java.io.File repositoryDir)
          Initializes the repository, verifying that the id file is present.
 Lock lockItem(RepositoryItem item, boolean writeLock)
          Locks an item in the repository.
 Lock lockItem(java.lang.String itemId, boolean writeLock)
          Locks an item in the repository.
 void releaseLock(Lock lock)
          Releases a lock on an item on the repository.
 void setRetryTime(int retryTime)
          Sets the time in milliseconds to wait between attempts to obtain the id lock.
 void terminate()
          Terminates the locking manager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_RETRY_TIME

public static final int DEFAULT_RETRY_TIME
Default time in milliseconds between locking attempt tries.

See Also:
Constant Field Values

ID_FILE

protected static final java.lang.String ID_FILE
File used to save the id number to assign to the next added item.

See Also:
Constant Field Values
Constructor Detail

WormSharedLockManager

public WormSharedLockManager()
Method Detail

setRetryTime

public void setRetryTime(int retryTime)
Sets the time in milliseconds to wait between attempts to obtain the id lock.


getRetryTime

public int getRetryTime()
Returns the time in millseconds to wait between attempts to obtain the id lock.


initialize

public void initialize(java.io.File repositoryDir)
Initializes the repository, verifying that the id file is present.

Specified by:
initialize in interface LockManager

createRepository

public void createRepository(java.io.File repositoryDir)
Creates the repository. Note that nothing is done to ensure that another process is not also trying to create the repository at the same time.

Specified by:
createRepository in interface LockManager

terminate

public void terminate()
Terminates the locking manager.

Specified by:
terminate in interface LockManager

getNextItemId

public int getNextItemId()
Returns the next item id, locking the id file for the read and write so that the id can be guaranteed unique between all the processes using the repository.

Specified by:
getNextItemId in interface LockManager

lockItem

public Lock lockItem(RepositoryItem item,
                     boolean writeLock)
Locks an item in the repository. Since this locking manager assumes a write once, read many policy, all locks are approved since they all should be shared read locks. Any write locks are assumed to be for item deletions - or if not, for updates that are coordinated externally.

Specified by:
lockItem in interface LockManager

releaseLock

public void releaseLock(Lock lock)
Releases a lock on an item on the repository. Since we don't really assign locks, this does nothing under the covers.

Specified by:
releaseLock in interface LockManager

lockItem

public Lock lockItem(java.lang.String itemId,
                     boolean writeLock)
Locks an item in the repository. Since this locking manager assumes a write once, read many policy, all locks are approved since they all should be shared read locks. Any write locks are assumed to be for item deletions - or if not, for updates that are coordinated externally.

Specified by:
lockItem in interface LockManager


Copyright © 2002-2003 Paul Speed. All Rights Reserved.