org.entityfs.lock.cmd
Class LockCommandExecutorImpl

java.lang.Object
  extended by org.entityfs.lock.cmd.LockCommandExecutorImpl
All Implemented Interfaces:
LockCommandExecutor

public class LockCommandExecutorImpl
extends Object
implements LockCommandExecutor

This is the default implementation of the LockCommandExecutor interface.

The LockCommand:s understood by this class are:

The locking strategy rules implemented are, in this order of precedence:

  1. Lock locks for entities higher up in the file system hierarchy (nearer the root directory) before locks for entities further down.
  2. Lock entities on the same level in the file system hierarchy in hash code order.
  3. Acquire write locks for an entity before read locks for the same entity (read locks cannot be promoted to write locks).
The first rule is hard to comply with in an efficient manner since entities are not aware of their absolute location in a file system. This implementation tries to establish different entities positions relative to each other by checking if any of the entities to lock are the parent directory of any of the other entities to lock.

This class does not contain any mutable internal state; the singleton instance INSTANCE may be used instead of instantiating the class.

Since:
1.0
Author:
Karl Gustafsson
In_jar:
entityfs-core

Field Summary
static LockCommandExecutorImpl INSTANCE
          Since this class does not contain any mutable internal state, this singleton instance may be used instead of instantiating the class.
 
Constructor Summary
LockCommandExecutorImpl()
           
 
Method Summary
 LockCollection execute(Collection<? extends LockCommand> c)
          Execute the supplied lock commands and return the collection of locked locks.
 LockCollection execute(LockCommand... commands)
          Execute the supplied lock commands and return the collection of locked locks.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INSTANCE

public static final LockCommandExecutorImpl INSTANCE
Since this class does not contain any mutable internal state, this singleton instance may be used instead of instantiating the class.

Constructor Detail

LockCommandExecutorImpl

public LockCommandExecutorImpl()
Method Detail

execute

public LockCollection execute(LockCommand... commands)
Description copied from interface: LockCommandExecutor
Execute the supplied lock commands and return the collection of locked locks.

Implementations should make sure that, when all locks are locked, they are valid with respect to the commands that were supplied. More specifically, that locked parent directories are still parent directories of the entities whose parents this method was instructed to lock.

Specified by:
execute in interface LockCommandExecutor
Parameters:
commands - The lock commands. May be null.
Returns:
The collection of locked locks. If the file system where all entities live is not locking, this collection is empty.

execute

public LockCollection execute(Collection<? extends LockCommand> c)
Description copied from interface: LockCommandExecutor
Execute the supplied lock commands and return the collection of locked locks.

Implementations should make sure that, when all locks are locked, they are valid with respect to the commands that were supplied. More specifically, that locked parent directories are still parent directories of the entities whose parents this method was instructed to lock.

Specified by:
execute in interface LockCommandExecutor
Parameters:
c - The collection of lock commands. May be null.
Returns:
The collection of locked locks. If the file system where all entities live is not locking, this collection is empty.