net.sf.sasl.distributed.lock.impl
Class DefaultLockSession.LockSequence

java.lang.Object
  extended by net.sf.sasl.distributed.lock.impl.DefaultLockSession.LockSequence
All Implemented Interfaces:
ILockContainer, ILockSequence
Enclosing class:
DefaultLockSession

protected class DefaultLockSession.LockSequence
extends Object
implements ILockSequence

Lock sequence which could have nested lock sequences.

Since:
0.0.1 (sasl-distributed-lock-library)

Constructor Summary
protected DefaultLockSession.LockSequence(String name)
          Creates an empty lock sequence with the given name.
 
Method Summary
 IMutex acquireMutex(Object key)
          Acquires a mutex for the given lock key and returns it.
protected  void assertStrictMode()
          Does a strict mode check for the operation.
 void clear()
          Releases all locks that this lock container holds.
 boolean detach(IMutex mutex)
          Detaches the mutex immediately from the sequence and releases the lock, if it was locked over the sequence.
protected  DefaultLockSession.MutexDecorator getDecoratorForLockKey(Object lockKey)
          Returns the mutex decorator for a given lock key.
protected  DefaultLockSession.LockSequence getInnerSequence()
           
 IMutex getMutex(Object lockKey)
          Returns the corresponding mutex to the lockKey, null if there exists no such mutex for the lockKey at the sequence.
 String getName()
          Returns a name of the lock container, for example "lock-transaction-X".
protected  DefaultLockSession.LockSequence getOuterSequence()
           
 boolean isActive()
          Returns true if this lock container is active which means it was not yet released via ILockContainer.release().
 IMutex lock(Object lockKey)
          Acquires a mutex for the given lock key and locks it initial.
 IMutex lockInterruptibly(Object lockKey)
          Tries to acquire a mutex and do trie to do a lock on it as long as the current thread is not interrupted.
 void release()
          Releases all resources associated with this lock container.
protected  void setInnerSequence(DefaultLockSession.LockSequence innerSequence)
          Sets the child sequence of this sequence.
protected  void setOuterSequence(DefaultLockSession.LockSequence outerSequence)
          Sets the parent sequence of this sequence.
 IMutex tryLock(Object lockKey)
          Tries to acquire a mutex and do a tryLock on it.
 IMutex tryLock(Object lockKey, long maxWaitTime, TimeUnit timeUnit)
          Tries to acquire a mutex and do a timed wait tryLock on it.
 IMutex unlock(Object lockKey)
          Unlocks the mutex for the given lockKey, so that the mutex could be locked by another thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultLockSession.LockSequence

protected DefaultLockSession.LockSequence(String name)
Creates an empty lock sequence with the given name.

Parameters:
name - null or non null
Since:
0.0.1 (sasl-distributed-lock-library)
Method Detail

getInnerSequence

protected DefaultLockSession.LockSequence getInnerSequence()
Returns:
null or non null
Since:
0.0.1 (sasl-distributed-lock-library)
See Also:
#setInnerSequence(LockSequence)

getOuterSequence

protected DefaultLockSession.LockSequence getOuterSequence()
Returns:
Since:
0.0.1 (sasl-distributed-lock-library)
See Also:
#setOuterSequence(LockSequence)

setOuterSequence

protected void setOuterSequence(DefaultLockSession.LockSequence outerSequence)
Sets the parent sequence of this sequence.

Parameters:
outerSequence - null or non null
Since:
0.0.1 (sasl-distributed-lock-library)

setInnerSequence

protected void setInnerSequence(DefaultLockSession.LockSequence innerSequence)
Sets the child sequence of this sequence.

Parameters:
innerSequence - null or non null
Since:
0.0.1 (sasl-distributed-lock-library)

clear

public void clear()
           throws LockOperationException
Description copied from interface: ILockContainer
Releases all locks that this lock container holds. If the container has nested lock containers than they will be released via ILockContainer.release(). The container stays active after the operation.

Specified by:
clear in interface ILockContainer
Throws:
LockOperationException - if an exception occurs during releasing locks and nested containers.
Since:
0.0.1 (sasl-distributed-lock-library)
See Also:
ILockContainer.clear()

getDecoratorForLockKey

protected DefaultLockSession.MutexDecorator getDecoratorForLockKey(Object lockKey)
Returns the mutex decorator for a given lock key. Returns null if no decorator exists for the given lock key at the lock session.

Parameters:
lockKey - null or non null.
Returns:
null or non null.
Since:
0.0.1 (sasl-distributed-lock-library)

acquireMutex

public IMutex acquireMutex(Object key)
                    throws LockOperationException
Description copied from interface: ILockSequence
Acquires a mutex for the given lock key and returns it. The mutex is not locked. If there exists already an attached mutex for the lock key at the sequence, than that instance must be returned.

Specified by:
acquireMutex in interface ILockSequence
Parameters:
key - non null
Returns:
non null
Throws:
LockOperationException - if any exception occurs during trying to acquire a mutex for the lock key.
Since:
0.0.1 (sasl-distributed-lock-library)
See Also:
net.sf.sasl.distributed.lock.ILockContainer#getLock(java.lang.Object)

detach

public boolean detach(IMutex mutex)
               throws LockOperationException
Description copied from interface: ILockSequence
Detaches the mutex immediately from the sequence and releases the lock, if it was locked over the sequence. Returns true, if the detach was successful, false else.

Specified by:
detach in interface ILockSequence
Parameters:
mutex - non null
Returns:
true or false.
Throws:
LockOperationException - if the operation is not allowed.
See Also:
ILockSequence.detach(net.sf.sasl.distributed.lock.IMutex)

getMutex

public IMutex getMutex(Object lockKey)
                throws LockOperationException
Description copied from interface: ILockSequence
Returns the corresponding mutex to the lockKey, null if there exists no such mutex for the lockKey at the sequence.

Specified by:
getMutex in interface ILockSequence
Parameters:
lockKey - non null
Returns:
null or non null
Throws:
LockOperationException - if the operation is not allowed.
See Also:
ILockSequence.getMutex(java.lang.Object)

lock

public IMutex lock(Object lockKey)
            throws LockOperationException,
                   DeadlockException
Description copied from interface: ILockSequence
Acquires a mutex for the given lock key and locks it initial.

Specified by:
lock in interface ILockSequence
Parameters:
lockKey - non null.
Returns:
acquired and locked mutex.
Throws:
LockOperationException - if the mutex could not get acquired, for example because its held by another sequence (of the same session), or the operation is not allowed.
DeadlockException - if a deadlock scenario occurred.
See Also:
ILockSequence.lock(java.lang.Object)

lockInterruptibly

public IMutex lockInterruptibly(Object lockKey)
                         throws LockOperationException,
                                DeadlockException,
                                InterruptedException
Description copied from interface: ILockSequence
Tries to acquire a mutex and do trie to do a lock on it as long as the current thread is not interrupted. The acquired mutex will be attached to the sequence.

Specified by:
lockInterruptibly in interface ILockSequence
Parameters:
lockKey - non null
Returns:
non null
Throws:
LockOperationException - if the mutex could not get acquired, for example because its held by another sequence (of the same session), or the operation is not allowed.
DeadlockException - if a deadlock scenario occurred.
InterruptedException - if the current thread was interrupted.
See Also:
ILockSequence.lockInterruptibly(Object)

tryLock

public IMutex tryLock(Object lockKey)
               throws LockOperationException,
                      DeadlockException
Description copied from interface: ILockSequence
Tries to acquire a mutex and do a tryLock on it. If the tryLock is successful, than the mutex is returned. Else null will be returned, but the acquired mutex will be attached to the sequence.

Specified by:
tryLock in interface ILockSequence
Parameters:
lockKey - non null
Returns:
null or non null
Throws:
LockOperationException - if the mutex could not get acquired, for example because its held by another sequence (of the same session), or the operation is not allowed.
DeadlockException - if a deadlock scenario occurred.
See Also:
ILockSequence.tryLock(java.lang.Object)

tryLock

public IMutex tryLock(Object lockKey,
                      long maxWaitTime,
                      TimeUnit timeUnit)
               throws LockOperationException,
                      DeadlockException,
                      InterruptedException
Description copied from interface: ILockSequence
Tries to acquire a mutex and do a timed wait tryLock on it. If the timed waited tryLock is successful, than the mutex is returned. Else null will be returned, but the acquired mutex will be attached to the sequence.

Specified by:
tryLock in interface ILockSequence
Parameters:
lockKey - non null
maxWaitTime - positive long value.
timeUnit - non null, describing of what time unit the maxWaitTime is.
Returns:
null or non null.
Throws:
LockOperationException - if the mutex could not get acquired, for example because its held by another sequence (of the same session).
DeadlockException - if a deadlock scenario occurred.
InterruptedException
See Also:
ILockSequence.tryLock(java.lang.Object, long, java.util.concurrent.TimeUnit)

unlock

public IMutex unlock(Object lockKey)
              throws LockOperationException
Description copied from interface: ILockSequence
Unlocks the mutex for the given lockKey, so that the mutex could be locked by another thread.

Specified by:
unlock in interface ILockSequence
Parameters:
lockKey - non null.
Returns:
unlocked mutex.
Throws:
LockOperationException - if the mutex could not get unlocked, for example because it was never held by this sequence, or the operation is not allowed.
See Also:
ILockSequence.unlock(java.lang.Object)

getName

public String getName()
Description copied from interface: ILockContainer
Returns a name of the lock container, for example "lock-transaction-X".

Specified by:
getName in interface ILockContainer
Returns:
null or non null
Since:
0.0.1 (sasl-distributed-lock-library)
See Also:
ILockContainer.getName()

release

public void release()
             throws LockOperationException
Description copied from interface: ILockContainer
Releases all resources associated with this lock container. If the container has got nested containers, than all nested containers of the container must get released and all locks, which are held by the container.
After the operation the lock element should be disconnected from all types of lock operations, which means it is inactive and garbage.

Specified by:
release in interface ILockContainer
Throws:
LockOperationException
Since:
0.0.1 (sasl-distributed-lock-library)
See Also:
ILockContainer.release()

isActive

public boolean isActive()
Description copied from interface: ILockContainer
Returns true if this lock container is active which means it was not yet released via ILockContainer.release(). False else. An inactive lock container should be disconnected from all types of lock operations.

Specified by:
isActive in interface ILockContainer
Returns:
true or false.
Since:
0.0.1 (sasl-distributed-lock-library)
See Also:
ILockContainer.isActive()

assertStrictMode

protected void assertStrictMode()
                         throws LockOperationException
Does a strict mode check for the operation.

Throws:
LockOperationException - if strict mode is enabled and violated.
Since:
0.0.1 (sasl-distributed-lock-library)


Copyright © 2010. All Rights Reserved.