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.
  • Field Details

  • Constructor Details

    • InProcessLockingManager

      public InProcessLockingManager()
  • Method Details

    • 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 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 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 against
      featureID - FeatureID to check
      transaction - Provides Authorization
      Throws:
      FeatureLockException - If transaction does not have sufficient authroization
    • checkedWriter

      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(String typeName, String featureID, Transaction transaction, FeatureLock featureLock) throws IOException
      Release indicated featureID, must have correct authroization.
      Specified by:
      unLockFeatureID in interface LockingManager
      Throws:
      IOException - If lock could not be released
    • refresh

      public boolean refresh(String authID, Transaction transaction) throws 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:
      IOException - If transaction not authorized to refresh authID
      IllegalArgumentException - If authID or transaction not provided
    • release

      public boolean release(String authID, Transaction transaction) throws 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:
      IOException - If transaction not authorized to release authID
      IllegalArgumentException - If authID or transaction not provided
    • exists

      public boolean exists(String authID)
      Implment lockExists.

      Remeber lock may have expired.

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

      public boolean isLocked(String typeName, String featureID)
      Used by test cases
      Returns:
      Return if feature is currently locked