|
Side of Software Persistence Library 2.0 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object sos.db.AbstractTransactionPolicy sos.db.DefaultReadWriteTransactionPolicy
public class DefaultReadWriteTransactionPolicy
A transaction policy that uses strict two phase locking (2PL) to ensure that transactions appear to execute sequentially and that uses lock timeouts to break potential deadlock.
With this policy, transactions on different objects are allowed to execute concurrently. Also, transactions invoking read-only methods on the same objects are allowed to execute concurrently.
With this policy, transactions in high contention may deadlock, and
repeated attempts at these transactions may lead to thrashing,
causing no transaction to make progress. To avoid the thrashing, consider
using DefaultTransactionPolicy
instead of this class.
This policy is adequate for applications in which transactions execute on different threads and without much contention.
Activity | Severity |
---|---|
A read lock is acquired | FINEST |
A read lock is released | FINEST |
A write lock is acquired | FINEST |
A write lock is released | FINEST |
A method is invoked | FINEST |
Subclasses may change the log messages or severity by overriding
the logXxx
methods.
DefaultTransactionPolicy
Constructor Summary | |
---|---|
DefaultReadWriteTransactionPolicy()
Creates an instance of DefaultReadWriteTransactionPolicy
with default timeout intervals of one minute each. |
|
DefaultReadWriteTransactionPolicy(long readTimeout,
long writeTimeout)
Creates an instance of DefaultReadWriteTransactionPolicy
with the specified timeout intervals. |
Method Summary | |
---|---|
protected void |
acquireReadLock(TransactionSupport support)
Acquires a read lock for the key referenced by support . |
protected void |
acquireWriteLock(TransactionSupport support)
Acquires a write lock for the key referenced by support . |
protected void |
logReadLockAcquired(java.lang.String databaseName,
java.lang.Object key)
Records that the read lock associated with key has been acquired. |
protected void |
logReadLockReleased(java.lang.String databaseName,
java.lang.Object key)
Records that the read lock associated with key has been released. |
protected void |
logWriteLockAcquired(java.lang.String databaseName,
java.lang.Object key)
Records that the write lock associated with key has been acquired. |
protected void |
logWriteLockReleased(java.lang.String databaseName,
java.lang.Object key)
Records that the write lock associated with key has been released. |
protected void |
prepareForReadOnlyInvocation(TransactionSupport support)
Prepares for the invocation of a read-only method on the object referenced by support . |
protected void |
prepareForWriteInvocation(TransactionSupport support)
Prepares for the invocation of a non-read-only method on the object referenced by support . |
void |
registerObject(TransactionSupport support,
java.lang.Object object)
Notifies this policy that there is a new database object. |
Methods inherited from class sos.db.AbstractTransactionPolicy |
---|
getMethodStatus, invoke, logMethodInvocation, startTransaction, unregisterObjects |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface sos.db.TransactionPolicy |
---|
invoke, startTransaction, unregisterObjects |
Constructor Detail |
---|
public DefaultReadWriteTransactionPolicy()
DefaultReadWriteTransactionPolicy
with default timeout intervals of one minute each.
DefaultReadWriteTransactionPolicy(long,long)
public DefaultReadWriteTransactionPolicy(long readTimeout, long writeTimeout)
DefaultReadWriteTransactionPolicy
with the specified timeout intervals.
readTimeout
- maximum time to wait (in milliseconds) for a read lockwriteTimeout
- maximum time to wait (in milliseconds) for a write lockMethod Detail |
---|
protected void acquireReadLock(TransactionSupport support) throws java.io.IOException
support
.
support
- object that holds the key for which to acquire the read lock
java.io.IOException
- if an I/O error occursprotected void acquireWriteLock(TransactionSupport support) throws java.io.IOException
support
.
support
- object that holds the key for which to acquire the write lock
java.io.IOException
- if an I/O error occursprotected void logReadLockAcquired(java.lang.String databaseName, java.lang.Object key)
key
has been acquired.
It is safe to invoke toString
on key
.
This implementation uses the localized message for key "logReadLockAcquired". The message takes three parameters: the database name, the transaction thread, and the key.
databaseName
- name of the databasekey
- unique key of object being readprotected void logReadLockReleased(java.lang.String databaseName, java.lang.Object key)
key
has been released.
It is safe to invoke toString
on key
.
This implementation uses the localized message for key "logReadLockReleased". The message takes three parameters: the database name, the transaction thread, and the key.
databaseName
- name of the databasekey
- unique key of object being readprotected void logWriteLockAcquired(java.lang.String databaseName, java.lang.Object key)
key
has been acquired.
It is safe to invoke toString
on key
.
This implementation uses the localized message for key "logWriteLockAcquired". The message takes three parameters: the database name, the transaction thread, and the key.
databaseName
- name of the databasekey
- unique key of object being writtenprotected void logWriteLockReleased(java.lang.String databaseName, java.lang.Object key)
key
has been released.
It is safe to invoke toString
on key
.
This implementation uses the localized message for key "logWriteLockReleased". The message takes three parameters: the database name, the transaction thread, and the key.
databaseName
- name of the databasekey
- unique key of object being writtenprotected void prepareForReadOnlyInvocation(TransactionSupport support) throws java.io.IOException
AbstractTransactionPolicy
support
.This implementation does nothing. Subclasses can override this method to provide a more meaningful implementation. For example, they can use this method to acquire a read lock.
prepareForReadOnlyInvocation
in class AbstractTransactionPolicy
support
- object that holds information about the receiver object,
including a key that uniquely identifies it
java.io.IOException
- if an I/O error occursAbstractTransactionPolicy.prepareForWriteInvocation(sos.db.TransactionSupport)
protected void prepareForWriteInvocation(TransactionSupport support) throws java.io.IOException
AbstractTransactionPolicy
support
.This implementation does nothing. Subclasses can override this method to provide a more meaningful implementation. For example, they can use this method to acquire a write lock.
prepareForWriteInvocation
in class AbstractTransactionPolicy
support
- object that holds information about the receiver object,
including a key that uniquely identifies it
java.io.IOException
- if an I/O error occursAbstractTransactionPolicy.prepareForReadOnlyInvocation(sos.db.TransactionSupport)
public void registerObject(TransactionSupport support, java.lang.Object object) throws java.io.IOException
TransactionPolicy
registerObject
in interface TransactionPolicy
registerObject
in class AbstractTransactionPolicy
support
- object to assist in transaction managementobject
- the object added to the database
java.io.IOException
- if an I/O error occurs
|
Side of Software Persistence Library 2.0 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |