org.abstracthorizon.danube.webdav.lock.impl
Class SimpleInMemoryLockingMechanism

java.lang.Object
  extended by org.abstracthorizon.danube.webdav.lock.impl.SimpleInMemoryLockingMechanism
All Implemented Interfaces:
LockingMechanism
Direct Known Subclasses:
FSLockingMechanism

public class SimpleInMemoryLockingMechanism
extends Object
implements LockingMechanism

Simple, in-memory locking mechanism

Author:
Daniel Sendula

Field Summary
protected  int harvestMinimumInterval
          Minimal interval timed out locks are removed.
protected  Map<Lock,Collection<Object>> lockResources
          Map of locks to resources
protected  long nextHarvested
          Time locks can be harvesed as the earliest
protected  Map<Object,Collection<Lock>> resourcesLocks
          Map of resources to locks
protected  Map<String,Lock> tokenLocks
          Map of tokens to locks
 
Fields inherited from interface org.abstracthorizon.danube.webdav.lock.LockingMechanism
SCOPE_EXCLUSIVE, SCOPE_NONE, SCOPE_SHARED, TYPE_WRITE
 
Constructor Summary
SimpleInMemoryLockingMechanism()
          Constructor
 
Method Summary
 Lock createLock(int type, int scope, Object owner, Timeout timeout, int depth)
          Creates the lock
protected  Lock createLockImpl(int type, int scope, Object owner, Timeout timeout, int depth)
          Constructs lock object
 Lock findLock(String token)
          Retunrs the lock with the given token or null
 int getHarvestMinimumInterval()
          Returns minimal harvest interval in miliseconds
 Lock[] getLocks(Object resource)
          Returns locks for the given resource
 Object[] getResources(Lock lock)
          Returns an array of resources for the given lock
 int[] getSupportedLockScopes(Object resource)
          Returns array with LockingMechanism.SCOPE_EXCLUSIVE and LockingMechanism.SCOPE_SHARED
protected  void harvestLocks()
          Removes all locks that are not valid anymore (due to timeout)
 boolean isAccessAllowed(Object resource, String token)
          Returns true if access to the resource is allowed
 boolean isLocked(Object resource)
          Returns true if resource is locked
 boolean lockResource(Lock lock, Object resource)
          Locks reource
protected  void removeLock(Lock lock)
          Removes a lock
 void removeLocks(Object resource)
          Removes locks form the given resource
 void setHarvestMinimumInterval(int harvestMinimumInterval)
          Sets minimal harvest interval in miliseconds
 void unlockResources(Lock lock)
          Unlocks resource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tokenLocks

protected Map<String,Lock> tokenLocks
Map of tokens to locks


lockResources

protected Map<Lock,Collection<Object>> lockResources
Map of locks to resources


resourcesLocks

protected Map<Object,Collection<Lock>> resourcesLocks
Map of resources to locks


harvestMinimumInterval

protected int harvestMinimumInterval
Minimal interval timed out locks are removed. Defaulted to 10 seconds


nextHarvested

protected long nextHarvested
Time locks can be harvesed as the earliest

Constructor Detail

SimpleInMemoryLockingMechanism

public SimpleInMemoryLockingMechanism()
Constructor

Method Detail

createLock

public Lock createLock(int type,
                       int scope,
                       Object owner,
                       Timeout timeout,
                       int depth)
Creates the lock

Specified by:
createLock in interface LockingMechanism
Parameters:
type - lock type
scope - lock type
owner - lock owner
timeout - lock timeout
depth - lock depth
Returns:
newly created lock

createLockImpl

protected Lock createLockImpl(int type,
                              int scope,
                              Object owner,
                              Timeout timeout,
                              int depth)
Constructs lock object

Parameters:
type - lock type
scope - lock scope
owner - lock owner
timeout - lock timeout
depth - lock depth
Returns:

findLock

public Lock findLock(String token)
Retunrs the lock with the given token or null

Specified by:
findLock in interface LockingMechanism
Parameters:
token - token
Returns:
the lock with the given token or null

lockResource

public boolean lockResource(Lock lock,
                            Object resource)
Locks reource

Specified by:
lockResource in interface LockingMechanism
Parameters:
lock - lock
resource - resource
Returns:
true if lock succeded

unlockResources

public void unlockResources(Lock lock)
Unlocks resource

Specified by:
unlockResources in interface LockingMechanism
Parameters:
lock - lock

removeLocks

public void removeLocks(Object resource)
Removes locks form the given resource

Specified by:
removeLocks in interface LockingMechanism
Parameters:
resource - resource

getLocks

public Lock[] getLocks(Object resource)
Returns locks for the given resource

Specified by:
getLocks in interface LockingMechanism
Parameters:
resource - resource
Returns:
locks array

getResources

public Object[] getResources(Lock lock)
Returns an array of resources for the given lock

Specified by:
getResources in interface LockingMechanism
Parameters:
lock - lock
Returns:
an array of resources

isLocked

public boolean isLocked(Object resource)
Returns true if resource is locked

Specified by:
isLocked in interface LockingMechanism
Parameters:
resource - resource
Returns:
true if resource is locked

isAccessAllowed

public boolean isAccessAllowed(Object resource,
                               String token)
Returns true if access to the resource is allowed

Specified by:
isAccessAllowed in interface LockingMechanism
Parameters:
resource - resource
token - token
Returns:
true if access to the resource is allowed

getSupportedLockScopes

public int[] getSupportedLockScopes(Object resource)
Returns array with LockingMechanism.SCOPE_EXCLUSIVE and LockingMechanism.SCOPE_SHARED

Specified by:
getSupportedLockScopes in interface LockingMechanism
Parameters:
resource - resource
Returns:
array with LockingMechanism.SCOPE_EXCLUSIVE and LockingMechanism.SCOPE_SHARED

harvestLocks

protected void harvestLocks()
Removes all locks that are not valid anymore (due to timeout)


removeLock

protected void removeLock(Lock lock)
Removes a lock

Parameters:
lock - lock

getHarvestMinimumInterval

public int getHarvestMinimumInterval()
Returns minimal harvest interval in miliseconds

Returns:
minimal harvest interval in miliseconds

setHarvestMinimumInterval

public void setHarvestMinimumInterval(int harvestMinimumInterval)
Sets minimal harvest interval in miliseconds



Copyright © 2005-2009 Abstract Horizon. All Rights Reserved.