com.sun.sgs.impl.kernel
Class LockingAccessCoordinator

java.lang.Object
  extended by com.sun.sgs.impl.kernel.AbstractAccessCoordinator
      extended by com.sun.sgs.impl.kernel.LockingAccessCoordinator
All Implemented Interfaces:
AccessCoordinatorHandle, AccessCoordinator

public class LockingAccessCoordinator
extends AbstractAccessCoordinator

An implementation of AccessCoordinator that uses locking to handle conflicts.

This implementation checks for deadlock whenever an access request is blocked due to a conflict. It selects the youngest transaction as the deadlock victim, determining the age using the originally requested start time for the task associated with the transaction. The implementation does not deny requests that would not result in deadlock. When requests block, it services the requests in the order that they arrive.

The methods that this class provides to implement AccessReporter are not thread safe, and should either be called from a single thread or else protected with external synchronization.

The constructor supports the following configuration properties:

Property: "com.sun.sgs.impl.kernel.LockingAccessCoordinator.lock.timeout"
Default: 0.1 times the value of the com.sun.sgs.txn.timeout property, if specified, otherwise times the value of the default transaction timeout.
The maximum number of milliseconds to wait for obtaining a lock. The value must be greater than 0, and should be less than the transaction timeout.

Property: "com.sun.sgs.impl.kernel.LockingAccessCoordinator.num.key.maps"
Default: 8
The number of maps to use for associating keys and maps. The number of maps controls the amount of concurrency, and should typically be set to a value to support concurrent access by the number of active threads. The value must be greater than 0.

This class uses the Logger named com.sun.sgs.impl.kernel.LockingAccessCoordinator to log information at the following logging levels:


Nested Class Summary
static class LockingAccessCoordinator.LockerImpl
          Define a locker that records information about the transaction requesting locks, and descriptions.
 
Nested classes/interfaces inherited from class com.sun.sgs.impl.kernel.AbstractAccessCoordinator
AbstractAccessCoordinator.AbstractAccessReporter<T>
 
Field Summary
static double DEFAULT_LOCK_TIMEOUT_PROPORTION
          The proportion of the transaction timeout to use for the lock timeout if no lock timeout is specified.
static String LOCK_TIMEOUT_PROPERTY
          The property for specifying the maximum number of milliseconds to wait for obtaining a lock.
(package private) static LoggerWrapper logger
          The logger for this class.
static int NUM_KEY_MAPS_DEFAULT
          The default number of key maps.
static String NUM_KEY_MAPS_PROPERTY
          The property for specifying the number of maps to use for associating keys and maps.
 
Fields inherited from class com.sun.sgs.impl.kernel.AbstractAccessCoordinator
profileCollectorHandle, txnProxy
 
Constructor Summary
LockingAccessCoordinator(Properties properties, TransactionProxy txnProxy, ProfileCollectorHandle profileCollectorHandle)
          Creates an instance of this class.
 
Method Summary
 Transaction getConflictingTransaction(Transaction txn)
          Find out what transaction, if still active, caused the given transaction to fail due to conflict.
(package private)  LockingAccessCoordinator.LockerImpl getLocker(Transaction txn)
          Returns the locker associated with a transaction.
 void notifyNewTransaction(Transaction txn, long requestedStartTime, int tryCount)
          Notifies the coordinator that a new transaction is starting.
<T> AccessReporter<T>
registerAccessSource(String sourceName, Class<T> objectIdType)
          Register as a provider of shared objects, and therefore a possible source of conflict between transactions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCK_TIMEOUT_PROPERTY

public static final String LOCK_TIMEOUT_PROPERTY
The property for specifying the maximum number of milliseconds to wait for obtaining a lock.

See Also:
Constant Field Values

DEFAULT_LOCK_TIMEOUT_PROPORTION

public static final double DEFAULT_LOCK_TIMEOUT_PROPORTION
The proportion of the transaction timeout to use for the lock timeout if no lock timeout is specified.

See Also:
Constant Field Values

NUM_KEY_MAPS_PROPERTY

public static final String NUM_KEY_MAPS_PROPERTY
The property for specifying the number of maps to use for associating keys and maps. The number of maps controls the amount of concurrency.

See Also:
Constant Field Values

NUM_KEY_MAPS_DEFAULT

public static final int NUM_KEY_MAPS_DEFAULT
The default number of key maps.

See Also:
Constant Field Values

logger

static final LoggerWrapper logger
The logger for this class.

Constructor Detail

LockingAccessCoordinator

public LockingAccessCoordinator(Properties properties,
                                TransactionProxy txnProxy,
                                ProfileCollectorHandle profileCollectorHandle)
Creates an instance of this class.

Parameters:
properties - the configuration properties
txnProxy - the transaction proxy
profileCollectorHandle - the profile collector handle
Throws:
IllegalArgumentException - if the values of the configuration properties are illegal
Method Detail

registerAccessSource

public <T> AccessReporter<T> registerAccessSource(String sourceName,
                                                  Class<T> objectIdType)
Register as a provider of shared objects, and therefore a possible source of conflict between transactions. This should be used by any component that is providing access to shared objects (e.g., the DataService which provides access to ManagedObjects and name bindings). This ensures that conflict is managed for access to the reported objects, and that a report of all accesses is available through profiling.

Type Parameters:
T - the type of the id object used to report accesses
Parameters:
sourceName - the name of the source of objects which may cause conflict on access
objectIdType - the type of the identifier that will be used to identify accessed objects
Returns:
an AccessReporter used to notify the system of access to shared objects

getConflictingTransaction

public Transaction getConflictingTransaction(Transaction txn)
Find out what transaction, if still active, caused the given transaction to fail due to conflict. This is particularly useful if you want to wait for that active transaction to finish, e.g. for re-trying the failed transaction.

This implementation does not record information about completed transactions, so it always returns null.

Parameters:
txn - a Transaction that failed due to conflict
Returns:
the active Transaction that caused the provided Transaction to fail due to conflict, or null if there is no such active Transaction

notifyNewTransaction

public void notifyNewTransaction(Transaction txn,
                                 long requestedStartTime,
                                 int tryCount)
Notifies the coordinator that a new transaction is starting.

Parameters:
txn - the transaction
requestedStartTime - the time in milliseconds that the task associated with the transaction was originally requested to start
tryCount - the number of times that transactions have been attempted for the task associated with txn

getLocker

LockingAccessCoordinator.LockerImpl getLocker(Transaction txn)
Returns the locker associated with a transaction.

Parameters:
txn - the transaction
Returns:
the locker
Throws:
IllegalArgumentException - if the transaction is not active

RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved