Top Description Fields Constructors Methods
net.sf.ehcache.transaction.local

public Class LocalTransactionContext

extends Object
Class Inheritance
Imports
net.sf.ehcache.transaction.SoftLock, .TransactionException, .TransactionID, .TransactionIDFactory, .TransactionTimeoutException, org.slf4j.Logger, .LoggerFactory, java.util.ArrayList, .Collections, .HashMap, .List, .Map, java.util.concurrent.TimeUnit

A local transaction's thread context
Author
Ludovic Orban

Field Summary

Modifier and TypeField and Description
private final long
private final List<TransactionListener>
private static final Logger
private boolean
private final Map<String, List<SoftLock>>
private final Map<String, LocalTransactionStore>
private final TransactionID
private final TransactionIDFactory

Constructor Summary

AccessConstructor and Description
public
LocalTransactionContext(int
the timeout before the context expires
transactionTimeout
,
TransactionIDFactory
the transaction ID factory to retrieve a new transaction id from
transactionIdFactory
)

Create a new LocalTransactionContext

Method Summary

Modifier and TypeMethod and Description
public void
addListener(TransactionListener
the listener
listener
)

Add a TransactionListener to this context

public void
commit(boolean
true if commit should proceed no matter the timeout
ignoreTimeout
)

Commit all work done in the context and release all registered soft locks

public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
private void
private void
private void
private void
public List<SoftLock>

Returns:

a List of registered soft locks for this cache
getSoftLocksForCache
(String
the name of the cache
cacheName
)

Get all soft locks registered in this context for a specific cache

public TransactionID

Returns:

the transaction ID
getTransactionId
()

Get the transaction ID of the context

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public boolean

Returns:

true if at least one soft lock got registered, false otherwise
hasLockedAnything
()

Check if anything was locked in this transaction's context

public void
registerSoftLock(String
the name of the cache this soft lock is in
cacheName
,
LocalTransactionStore
the LocalTransactionStore this soft lock is in
store
,
SoftLock
the soft lock
softLock
)

Register a soft lock in the context

public void
rollback()

Rollback all work done in the context and release all registered soft locks

public void
setRollbackOnly()

Mark the context for rollback

public long

Returns:

the time in milliseconds after which this context will expire
timeBeforeTimeout
()

Get the time until this context will expire

public boolean

Returns:

true if the context timed out, false otherwise
timedOut
()

Check if the context timed out

private void
public void
updateSoftLock(String
the name of the cache this soft lock is in
cacheName
,
SoftLock
the soft lock
softLock
)

Update a soft lock already registered in the context

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

expirationTimestampback to summary
private final long expirationTimestamp
listenersback to summary
private final List<TransactionListener> listeners
LOGback to summary
private static final Logger LOG
rollbackOnlyback to summary
private boolean rollbackOnly
softLockMapback to summary
private final Map<String, List<SoftLock>> softLockMap
storeMapback to summary
private final Map<String, LocalTransactionStore> storeMap
transactionIdback to summary
private final TransactionID transactionId
transactionIdFactoryback to summary
private final TransactionIDFactory transactionIdFactory

Constructor Detail

LocalTransactionContextback to summary
public LocalTransactionContext(int transactionTimeout, TransactionIDFactory transactionIdFactory)

Create a new LocalTransactionContext

Parameters
transactionTimeout:int

the timeout before the context expires

transactionIdFactory:TransactionIDFactory

the transaction ID factory to retrieve a new transaction id from

Method Detail

addListenerback to summary
public void addListener(TransactionListener listener)

Add a TransactionListener to this context

Parameters
listener:TransactionListener

the listener

commitback to summary
public void commit(boolean ignoreTimeout)

Commit all work done in the context and release all registered soft locks

Parameters
ignoreTimeout:boolean

true if commit should proceed no matter the timeout

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
fireAfterCommitEventback to summary
private void fireAfterCommitEvent()
fireAfterRollbackEventback to summary
private void fireAfterRollbackEvent()
fireBeforeCommitEventback to summary
private void fireBeforeCommitEvent()
freezeback to summary
private void freeze()
getSoftLocksForCacheback to summary
public List<SoftLock> getSoftLocksForCache(String cacheName)

Get all soft locks registered in this context for a specific cache

Parameters
cacheName:String

the name of the cache

Returns:List<SoftLock>

a List of registered soft locks for this cache

getTransactionIdback to summary
public TransactionID getTransactionId()

Get the transaction ID of the context

Returns:TransactionID

the transaction ID

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
hasLockedAnythingback to summary
public boolean hasLockedAnything()

Check if anything was locked in this transaction's context

Returns:boolean

true if at least one soft lock got registered, false otherwise

registerSoftLockback to summary
public void registerSoftLock(String cacheName, LocalTransactionStore store, SoftLock softLock)

Register a soft lock in the context

Parameters
cacheName:String

the name of the cache this soft lock is in

store:LocalTransactionStore

the LocalTransactionStore this soft lock is in

softLock:SoftLock

the soft lock

rollbackback to summary
public void rollback()

Rollback all work done in the context and release all registered soft locks

setRollbackOnlyback to summary
public void setRollbackOnly()

Mark the context for rollback

timeBeforeTimeoutback to summary
public long timeBeforeTimeout()

Get the time until this context will expire

Returns:long

the time in milliseconds after which this context will expire

timedOutback to summary
public boolean timedOut()

Check if the context timed out

Returns:boolean

true if the context timed out, false otherwise

unfreezeAndUnlockback to summary
private void unfreezeAndUnlock()
updateSoftLockback to summary
public void updateSoftLock(String cacheName, SoftLock softLock)

Update a soft lock already registered in the context

Parameters
cacheName:String

the name of the cache this soft lock is in

softLock:SoftLock

the soft lock