Class 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.
    • Constructor Detail

      • InProcessLockingManager

        public InProcessLockingManager()
    • 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 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
      • 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
      • 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