org.multiverse.api.commitlock
Class GenericCommitLockPolicy

java.lang.Object
  extended by org.multiverse.api.commitlock.GenericCommitLockPolicy
All Implemented Interfaces:
CommitLockPolicy

public final class GenericCommitLockPolicy
extends Object
implements CommitLockPolicy

An CommitLockPolicy that spins when it can't acquire a lock. When the lock can't be acquired, all locks are released and the locks are tries to be acquired again. The number of spins and retries can be configured. So you can createReference a version that doesn't spin, but doesn't retry, or a version that does spin but doesn't retry, etc.

Because spinning increases the time a lock is hold, it could prevent other transactions from making progress. So be careful. Setting the retry level too high, could lead to livelocking, but on the other side it could also cause an increase in failure rates of transactions and also cause livelocking on transaction level. So finding good value's is something that needs to be determined.

This GenericCommitLockPolicy is immutable and thread-safe to use.

Author:
Peter Veentjer

Field Summary
static CommitLockPolicy FAIL_FAST
           
static CommitLockPolicy FAIL_FAST_BUT_RETRY
           
static CommitLockPolicy SPIN_AND_RETRY
           
 
Constructor Summary
GenericCommitLockPolicy(int spinAttemptsPerLockCount, int retryCount)
           
 
Method Summary
 int getRetryCount()
           
 int getSpinAttemptsPerLockCount()
           
 String toString()
           
 boolean tryAcquire(CommitLock lock, CommitLockFilter filter, Transaction lockOwner)
          Tries to acquire the lock.
 boolean tryAcquireAll(Collection<CommitLock> locks, CommitLockFilter filter, Transaction lockOwner)
           
 boolean tryAcquireAll(CommitLock[] locks, CommitLockFilter filter, Transaction lockOwner)
          Tries to acquire all the locks that should be locked (so are allowed by the lock filter).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FAIL_FAST

public static final CommitLockPolicy FAIL_FAST

FAIL_FAST_BUT_RETRY

public static final CommitLockPolicy FAIL_FAST_BUT_RETRY

SPIN_AND_RETRY

public static final CommitLockPolicy SPIN_AND_RETRY
Constructor Detail

GenericCommitLockPolicy

public GenericCommitLockPolicy(int spinAttemptsPerLockCount,
                               int retryCount)
Method Detail

getRetryCount

public int getRetryCount()

getSpinAttemptsPerLockCount

public int getSpinAttemptsPerLockCount()

tryAcquire

public boolean tryAcquire(CommitLock lock,
                          CommitLockFilter filter,
                          Transaction lockOwner)
Description copied from interface: CommitLockPolicy
Tries to acquire the lock.

Specified by:
tryAcquire in interface CommitLockPolicy
Parameters:
lock - the CommitLock to acquire.
filter - the filter that selects to objects to lock.
lockOwner - the Transaction that wants to own the lock.
Returns:
true if the lock is acquired, false otherwise.

tryAcquireAll

public boolean tryAcquireAll(CommitLock[] locks,
                             CommitLockFilter filter,
                             Transaction lockOwner)
Description copied from interface: CommitLockPolicy
Tries to acquire all the locks that should be locked (so are allowed by the lock filter).

The filter is useful for dealing with a read/write set where only the writes need to be locked.

Specified by:
tryAcquireAll in interface CommitLockPolicy
Parameters:
locks - the CommitLocks where some need to be acquired.
filter - selects which CommitLocks need to be acquired
lockOwner - the Transaction that wants to acquire the locks.
Returns:
true if desired locks are acquired, false otherwise.

tryAcquireAll

public boolean tryAcquireAll(Collection<CommitLock> locks,
                             CommitLockFilter filter,
                             Transaction lockOwner)
Specified by:
tryAcquireAll in interface CommitLockPolicy

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2008-2010 Multiverse. All Rights Reserved.