org.geotools.data
Class InProcessLockingManager

java.lang.Object
  extended byorg.geotools.data.InProcessLockingManager
All Implemented Interfaces:
LockingManager

public class InProcessLockingManager
extends java.lang.Object
implements LockingManager

Provides In-Process FeatureLocking support for DataStore implementations.

If at all possible DataStore implementations should provide a real Feature Locking support that is persisted to disk or database and resepected by other processes.

This class provides a stop gap solution that implementations may use for GeoServer compatability.

Author:
Jody Garnett, Refractions Research, Chris Holmes, TOPP
Task:
REVISIT: I'm not sure that the map within a map is a good idea, it makes things perhaps too complicated. A nasty bug came about with releasing, as allLocks put locks into a new collection, and the iterator just removed them from that set instead of from the storage. This is now fixed, but the loop to do it is really damn complex. I'm not sure of the solution, but there should be something that is less confusing.

Field Summary
protected  java.util.Map lockTables
          lockTable access by typeName stores Transactions or MemoryLocks
 
Constructor Summary
InProcessLockingManager()
           
 
Method Summary
protected  java.util.Set allLocks()
          Set of all locks.
 void assertAccess(java.lang.String typeName, java.lang.String featureID, Transaction transaction)
          Checks mutability of featureID for this transaction.
 FeatureWriter checkedWriter(FeatureWriter writer, Transaction transaction)
          Provides a wrapper on the provided writer that checks locks.
protected  org.geotools.data.InProcessLockingManager.Lock createLock(Transaction transaction, FeatureLock featureLock)
          Creates the right sort of In-Process Lock.
 boolean exists(java.lang.String authID)
          Implment lockExists.
protected  org.geotools.data.InProcessLockingManager.Lock getLock(java.lang.String typeName, java.lang.String featureID)
          Lock for typeName & featureID if it exists.
 boolean isLocked(java.lang.String typeName, java.lang.String featureID)
          Used by test cases
 void lockFeatureID(java.lang.String typeName, java.lang.String featureID, Transaction transaction, FeatureLock featureLock)
          Aquire lock on featureID.
protected  java.util.Map locks(java.lang.String typeName)
          Access to a Map of locks for typeName
 boolean refresh(java.lang.String authID, Transaction transaction)
          Refresh locks held by the authorization authID.
 boolean release(java.lang.String authID, Transaction transaction)
          Release locks held by the authorization authID.
 void unLockFeatureID(java.lang.String typeName, java.lang.String featureID, Transaction transaction, FeatureLock featureLock)
          Release indicated featureID, must have correct authroization.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lockTables

protected java.util.Map lockTables
lockTable access by typeName stores Transactions or MemoryLocks

Constructor Detail

InProcessLockingManager

public InProcessLockingManager()
Method Detail

lockFeatureID

public void lockFeatureID(java.lang.String typeName,
                          java.lang.String featureID,
                          Transaction transaction,
                          FeatureLock featureLock)
                   throws FeatureLockException
Aquire lock on featureID.

This method will fail if Lock is already held by another.

Specified by:
lockFeatureID in interface LockingManager
Parameters:
typeName - TypeName storing feature
featureID - FeatureID to lock
transaction - Transaction to lock against
featureLock - FeatureLock describing lock request
Throws:
FeatureLockException - Indicates a problem with the lock request

getLock

protected org.geotools.data.InProcessLockingManager.Lock getLock(java.lang.String typeName,
                                                                 java.lang.String featureID)
Lock for typeName & featureID if it exists.

This method will not return expired locks.

Parameters:
typeName -
featureID -
Returns:
Lock if exists, or null

createLock

protected org.geotools.data.InProcessLockingManager.Lock createLock(Transaction transaction,
                                                                    FeatureLock featureLock)
                                                             throws FeatureLockException
Creates the right sort of In-Process Lock.

Parameters:
transaction -
featureLock -
Returns:
In-Process Lock
Throws:
FeatureLockException - When a Transaction lock is requested against Transaction.AUTO_COMMIT

locks

protected java.util.Map locks(java.lang.String typeName)
Access to a Map of locks for typeName

Parameters:
typeName - typeName
Returns:
Map of Transaction or MemoryLock by featureID

allLocks

protected java.util.Set allLocks()
Set of all locks.

Returns:
Set of all locks

assertAccess

public void assertAccess(java.lang.String typeName,
                         java.lang.String featureID,
                         Transaction transaction)
                  throws FeatureLockException
Checks mutability of featureID for this transaction.

Two behaviors are defined by FeatureLocking:

Right now we are just going to error out with an exception

Parameters:
typeName - Feature type to check against
featureID - FeatureID to check
transaction - Provides Authorization
Throws:
FeatureLockException - If transaction does not have sufficient authroization

checkedWriter

public FeatureWriter checkedWriter(FeatureWriter writer,
                                   Transaction transaction)
Provides a wrapper on the provided writer that checks locks.

Parameters:
writer - FeatureWriter requiring access control
transaction - Transaction being used
Returns:
FeatureWriter with lock checking

unLockFeatureID

public void unLockFeatureID(java.lang.String typeName,
                            java.lang.String featureID,
                            Transaction transaction,
                            FeatureLock featureLock)
                     throws java.io.IOException
Release indicated featureID, must have correct authroization.

Specified by:
unLockFeatureID in interface LockingManager
Parameters:
typeName -
featureID -
transaction -
featureLock -
Throws:
java.io.IOException - If lock could not be released

refresh

public boolean refresh(java.lang.String authID,
                       Transaction transaction)
                throws java.io.IOException
Refresh locks held by the authorization authID.

(remember that the lock may have expired)

Specified by:
refresh in interface LockingManager
Parameters:
authID - Authorization identifing Lock to refresh
transaction - Transaction with authorization for lockID
Returns:
true if lock was found and refreshed
Throws:
java.io.IOException - If transaction not authorized to refresh authID
java.lang.IllegalArgumentException - If authID or transaction not provided

release

public boolean release(java.lang.String authID,
                       Transaction transaction)
                throws java.io.IOException
Release locks held by the authorization authID.

(remember that the lock may have expired)

Specified by:
release in interface LockingManager
Parameters:
authID - Authorization identifing Lock to release
transaction - Transaction with authorization for lockID
Returns:
true if lock was found and released
Throws:
java.io.IOException - If transaction not authorized to release authID
java.lang.IllegalArgumentException - If authID or transaction not provided

exists

public boolean exists(java.lang.String authID)
Implment lockExists.

Remeber lock may have expired.

Specified by:
exists in interface LockingManager
Parameters:
authID -
Returns:
true if lock exists for authID
See Also:
org.geotools.data.LockingManager#lockExists(java.lang.String)

isLocked

public boolean isLocked(java.lang.String typeName,
                        java.lang.String featureID)
Used by test cases

Parameters:
typeName -
featureID -
Returns:
Return if feature is currently locked


Copyright © GeoTools. All Rights Reserved.