org.progeeks.repository
Class DefaultLockManager

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

public class DefaultLockManager
extends java.lang.Object
implements LockManager

Default implementation of repository lock manager that permits only one instance of the repository to be used at a time. Maintains the next repository item id to be assigned in a file in the root repository directory. This locking manager is safe to use with the meta-class cache.

Version:
$Revision: 1.3 $
Author:
Paul Wisneskey

Field Summary
protected static java.lang.String ID_FILE
          File used to save the id number to assign to the next added item.
 
Constructor Summary
DefaultLockManager()
           
 
Method Summary
 void createRepository(java.io.File repositoryDir)
          Method invoked when a new repository is created.
 int getNextItemId()
          Returns the next item id.
 void initialize(java.io.File repositoryDir)
          Initializes the repository, locking its id file to ensure that only one process has access to the repository.
 Lock lockItem(RepositoryItem item, boolean writeLock)
          Lock the given item for reading and/or writing.
 Lock lockItem(java.lang.String itemId, boolean writeLock)
          Lock the given itemId for reading and/or writing.
 void releaseLock(Lock lock)
          Release the lock held on the given item.
 void terminate()
          Terminate the locking manager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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

DefaultLockManager

public DefaultLockManager()
Method Detail

initialize

public void initialize(java.io.File repositoryDir)
Initializes the repository, locking its id file to ensure that only one process has access to the repository.

Specified by:
initialize in interface LockManager

terminate

public void terminate()
Description copied from interface: LockManager
Terminate the locking manager.

Specified by:
terminate in interface LockManager

getNextItemId

public int getNextItemId()
Returns the next item id.

Specified by:
getNextItemId in interface LockManager

lockItem

public Lock lockItem(RepositoryItem item,
                     boolean writeLock)
Lock the given item for reading and/or writing.

Specified by:
lockItem in interface LockManager

lockItem

public Lock lockItem(java.lang.String itemId,
                     boolean writeLock)
Lock the given itemId for reading and/or writing.

Specified by:
lockItem in interface LockManager

releaseLock

public void releaseLock(Lock lock)
Description copied from interface: LockManager
Release the lock held on the given item.

Specified by:
releaseLock in interface LockManager

createRepository

public void createRepository(java.io.File repositoryDir)
Description copied from interface: LockManager
Method invoked when a new repository is created. Can be used by the lock manager to set up any persistent storage. Does not actually initialize the lock manager (i.e. initialize will be called after the create).

Specified by:
createRepository in interface LockManager


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