Package org.geotools.data
Class InProcessLockingManager
- Object
-
- InProcessLockingManager
-
- All Implemented Interfaces:
LockingManager
public class InProcessLockingManager extends 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
- TODO:
- 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
InProcessLockingManager.Lock
Represents In-Process locks for Transactions or FeatureLocks.
-
Field Summary
Fields Modifier and Type Field Description protected Map<String,Map<String,InProcessLockingManager.Lock>>
lockTables
lockTable access by typeName stores Transactions or MemoryLocks
-
Constructor Summary
Constructors Constructor Description InProcessLockingManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<InProcessLockingManager.Lock>
allLocks()
Set of all locks.void
assertAccess(String typeName, String featureID, Transaction transaction)
Checks mutability of featureID for this transaction.FeatureWriter<SimpleFeatureType,SimpleFeature>
checkedWriter(FeatureWriter<SimpleFeatureType,SimpleFeature> writer, Transaction transaction)
Provides a wrapper on the provided writer that checks locks.protected InProcessLockingManager.Lock
createLock(Transaction transaction, FeatureLock featureLock)
Creates the right sort of In-Process Lock.boolean
exists(String authID)
Implment lockExists.protected InProcessLockingManager.Lock
getLock(String typeName, String featureID)
Lock for typeName & featureID if it exists.boolean
isLocked(String typeName, String featureID)
Used by test casesvoid
lockFeatureID(String typeName, String featureID, Transaction transaction, FeatureLock featureLock)
Aquire lock on featureID.Map<String,InProcessLockingManager.Lock>
locks(String typeName)
Access to a Map of locks for typeNameboolean
refresh(String authID, Transaction transaction)
Refresh locks held by the authorizationauthID
.boolean
release(String authID, Transaction transaction)
Release locks held by the authorizationauthID
.void
unLockFeatureID(String typeName, String featureID, Transaction transaction, FeatureLock featureLock)
Release indicated featureID, must have correct authroization.
-
-
-
Field Detail
-
lockTables
protected Map<String,Map<String,InProcessLockingManager.Lock>> lockTables
lockTable access by typeName stores Transactions or MemoryLocks
-
-
Method Detail
-
lockFeatureID
public void lockFeatureID(String typeName, 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 interfaceLockingManager
- Parameters:
typeName
- TypeName storing featurefeatureID
- FeatureID to locktransaction
- Transaction to lock againstfeatureLock
- FeatureLock describing lock request- Throws:
FeatureLockException
- Indicates a problem with the lock request
-
getLock
protected InProcessLockingManager.Lock getLock(String typeName, String featureID)
Lock for typeName & featureID if it exists.This method will not return expired locks.
- Returns:
- Lock if exists, or null
-
createLock
protected InProcessLockingManager.Lock createLock(Transaction transaction, FeatureLock featureLock) throws FeatureLockException
Creates the right sort of In-Process Lock.- Returns:
- In-Process Lock
- Throws:
FeatureLockException
- When a Transaction lock is requested against Transaction.AUTO_COMMIT
-
locks
public Map<String,InProcessLockingManager.Lock> locks(String typeName)
Access to a Map of locks for typeName- Parameters:
typeName
- typeName- Returns:
- Map of Transaction or MemoryLock by featureID
-
allLocks
public Set<InProcessLockingManager.Lock> allLocks()
Set of all locks.- Returns:
- Set of all locks
-
assertAccess
public void assertAccess(String typeName, String featureID, Transaction transaction) throws FeatureLockException
Checks mutability of featureID for this transaction.Two behaviors are defined by FeatureLocking:
- TransactionLock (Blocking): lock held by a Transaction
Authorization is granted to the Transaction holding the Lock. Conflict will result in a block until the Transaction holding the lock completes. (This behavior is equivalent to a Database row-lock, or a java synchronized statement) - FeatureLock (Error): lock held by a FeatureLock
Authorization is based on the set of Authorization IDs held by the provided Transaction. Conflict will result in an error. (This behavior is equivalent to the WFS locking specification)
Right now we are just going to error out with an exception
- Parameters:
typeName
- Feature type to check againstfeatureID
- FeatureID to checktransaction
- Provides Authorization- Throws:
FeatureLockException
- If transaction does not have sufficient authroization
- TransactionLock (Blocking): lock held by a Transaction
-
checkedWriter
public FeatureWriter<SimpleFeatureType,SimpleFeature> checkedWriter(FeatureWriter<SimpleFeatureType,SimpleFeature> writer, Transaction transaction)
Provides a wrapper on the provided writer that checks locks.- Parameters:
writer
- FeatureWriter requiring access controltransaction
- Transaction being used- Returns:
- FeatureWriter with lock checking
-
unLockFeatureID
public void unLockFeatureID(String typeName, String featureID, Transaction transaction, FeatureLock featureLock) throws IOException
Release indicated featureID, must have correct authroization.- Specified by:
unLockFeatureID
in interfaceLockingManager
- Throws:
IOException
- If lock could not be released
-
refresh
public boolean refresh(String authID, Transaction transaction) throws IOException
Refresh locks held by the authorizationauthID
.(remember that the lock may have expired)
- Specified by:
refresh
in interfaceLockingManager
- Parameters:
authID
- Authorization identifing Lock to refreshtransaction
- Transaction with authorization for lockID- Returns:
true
if lock was found and refreshed- Throws:
IOException
- If transaction not authorized to refresh authIDIllegalArgumentException
- If authID or transaction not provided
-
release
public boolean release(String authID, Transaction transaction) throws IOException
Release locks held by the authorizationauthID
.(remember that the lock may have expired)
- Specified by:
release
in interfaceLockingManager
- Parameters:
authID
- Authorization identifing Lock to releasetransaction
- Transaction with authorization for lockID- Returns:
true
if lock was found and released- Throws:
IOException
- If transaction not authorized to release authIDIllegalArgumentException
- If authID or transaction not provided
-
exists
public boolean exists(String authID)
Implment lockExists.Remeber lock may have expired.
- Specified by:
exists
in interfaceLockingManager
- Parameters:
authID
- Authorization for lock- Returns:
- true if lock exists for authID
- See Also:
LockingManager#lockExists(java.lang.String)
-
-