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

public Class EhcacheXAResourceImpl

extends Object
implements EhcacheXAResource
Class Inheritance
All Implemented Interfaces
net.sf.ehcache.transaction.xa.EhcacheXAResource, javax.transaction.xa.XAResource
Imports
net.sf.ehcache.CacheException, .Ehcache, .Element, net.sf.ehcache.store.ElementValueComparator, .Store, net.sf.ehcache.transaction.SoftLock, .SoftLockID, .SoftLockManager, .TransactionIDFactory, .TransactionIDNotFoundException, net.sf.ehcache.transaction.manager.TransactionManagerLookup, net.sf.ehcache.transaction.xa.commands.Command, net.sf.ehcache.transaction.xa.processor.XARequest, .XARequestProcessor, org.slf4j.Logger, .LoggerFactory, org.terracotta.statistics.observer.OperationObserver, java.util.ArrayList, .Arrays, .Collections, .HashSet, .LinkedList, .List, .Set, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap, javax.transaction.RollbackException, .SystemException, .Transaction, .TransactionManager, javax.transaction.xa.XAException, .XAResource, .Xid

The EhcacheXAResource implementation
Author
Ludovic Orban

Field Summary

Modifier and TypeField and Description
private final Ehcache
private final OperationObserver<XaCommitOutcome>
private final ElementValueComparator
private volatile Xid
private final List<XAExecutionListener>
private static final Logger
private static final long
private final XARequestProcessor
private final OperationObserver<XaRecoveryOutcome>
private final OperationObserver<XaRollbackOutcome>
private final SoftLockManager
private final TransactionIDFactory
private volatile int
private final TransactionManager
private final Store
private final ConcurrentMap<Xid, XATransactionContext>

Constructor Summary

AccessConstructor and Description
public
EhcacheXAResourceImpl(Ehcache
the cache
cache
,
Store
the underlying store
underlyingStore
,
TransactionManagerLookup
the transaction manager lookup
txnManagerLookup
,
SoftLockManager
the soft lock manager
softLockManager
,
TransactionIDFactory
the transaction ID factory
transactionIDFactory
,
ElementValueComparator
the element value comparator
comparator
,
OperationObserver<XaCommitOutcome> commitObserver, OperationObserver<XaRollbackOutcome> rollbackObserver, OperationObserver<XaRecoveryOutcome> recoveryObserver)

Constructor

Method Summary

Modifier and TypeMethod and Description
public void
addTwoPcExecutionListener(XAExecutionListener
the XAExecutionListener
listener
)

Implements net.sf.ehcache.transaction.xa.EhcacheXAResource.addTwoPcExecutionListener.

Add a listener which will be called back according to the 2PC lifecycle
public void
commit(Xid
A global transaction identifier
xid
,
boolean
If true, the resource manager should use a one-phase commit protocol to commit the work done on behalf of xid.
onePhase
)

Implements javax.transaction.xa.XAResource.commit.

Commits the global transaction specified by xid.
public void
commitInternal(Xid
a XID
xid
,
boolean
true if onePhase, false otherwise
onePhase
)

The commit implementation

public XATransactionContext
createTransactionContext()

Implements net.sf.ehcache.transaction.xa.EhcacheXAResource.createTransactionContext.

Obtain the already associated XATransactionContext with the current Transaction, or create a new one should none be there yet.
public void
end(Xid
A global transaction identifier that is the same as the identifier used previously in the start method.
xid
,
int
One of TMSUCCESS, TMFAIL, or TMSUSPEND.
flag
)

Implements javax.transaction.xa.XAResource.end.

Ends the work performed on behalf of a transaction branch.
private void
private void
public void
forget(Xid
A global transaction identifier.
xid
)

Implements javax.transaction.xa.XAResource.forget.

Tells the resource manager to forget about a heuristically completed transaction branch.
public void
forgetInternal(Xid
a XID
xid
)

The forget implementation

public String
getCacheName()

Implements net.sf.ehcache.transaction.xa.EhcacheXAResource.getCacheName.

Getter to the name of the cache wrapped by this XAResource
public XATransactionContext
public int
getTransactionTimeout()

Implements javax.transaction.xa.XAResource.getTransactionTimeout.

Obtains the current transaction timeout value set for this XAResource instance.
public boolean
isSameRM(XAResource
An XAResource object whose resource manager instance is to be compared with the resource manager instance of the target object.
xaResource
)

Implements javax.transaction.xa.XAResource.isSameRM.

This method is called to determine if the resource manager instance represented by the target object is the same as the resource manager instance represented by the parameter xares.
public int
prepare(Xid
A global transaction identifier.
xid
)

Implements javax.transaction.xa.XAResource.prepare.

Ask the resource manager to prepare for a transaction commit of the transaction specified in xid.
public int

Returns:

XA_OK or XA_RDONLY
prepareInternal
(Xid
a XID
xid
)

The prepare implementation

private static String
public Xid[]
recover(int
One of TMSTARTRSCAN, TMENDRSCAN, TMNOFLAGS. TMNOFLAGS must be used when no other flags are set in the parameter.
flags
)

Implements javax.transaction.xa.XAResource.recover.

Obtains a list of prepared transaction branches from a resource manager.
public void
rollback(Xid
A global transaction identifier.
xid
)

Implements javax.transaction.xa.XAResource.rollback.

Informs the resource manager to roll back work done on behalf of a transaction branch.
public void
rollbackInternal(Xid
a XID
xid
)

The rollback implementation

public boolean
setTransactionTimeout(int
The transaction timeout value in seconds.
timeout
)

Implements javax.transaction.xa.XAResource.setTransactionTimeout.

Sets the current transaction timeout value for this XAResource instance.
public void
start(Xid
A global transaction identifier to be associated with the resource.
xid
,
int
One of TMNOFLAGS, TMJOIN, or TMRESUME.
flag
)

Implements javax.transaction.xa.XAResource.start.

Starts work on behalf of a transaction branch specified in xid.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

cacheback to summary
private final Ehcache cache
commitObserverback to summary
private final OperationObserver<XaCommitOutcome> commitObserver
comparatorback to summary
private final ElementValueComparator comparator
currentXidback to summary
private volatile Xid currentXid
listenersback to summary
private final List<XAExecutionListener> listeners
LOGback to summary
private static final Logger LOG
MILLISECOND_PER_SECONDback to summary
private static final long MILLISECOND_PER_SECOND
processorback to summary
private final XARequestProcessor processor
recoveryObserverback to summary
private final OperationObserver<XaRecoveryOutcome> recoveryObserver
rollbackObserverback to summary
private final OperationObserver<XaRollbackOutcome> rollbackObserver
softLockManagerback to summary
private final SoftLockManager softLockManager
transactionIDFactoryback to summary
private final TransactionIDFactory transactionIDFactory
transactionTimeoutback to summary
private volatile int transactionTimeout
txnManagerback to summary
private final TransactionManager txnManager
underlyingStoreback to summary
private final Store underlyingStore
xidToContextMapback to summary
private final ConcurrentMap<Xid, XATransactionContext> xidToContextMap

Constructor Detail

EhcacheXAResourceImplback to summary
public EhcacheXAResourceImpl(Ehcache cache, Store underlyingStore, TransactionManagerLookup txnManagerLookup, SoftLockManager softLockManager, TransactionIDFactory transactionIDFactory, ElementValueComparator comparator, OperationObserver<XaCommitOutcome> commitObserver, OperationObserver<XaRollbackOutcome> rollbackObserver, OperationObserver<XaRecoveryOutcome> recoveryObserver)

Constructor

Parameters
cache:Ehcache

the cache

underlyingStore:Store

the underlying store

txnManagerLookup:TransactionManagerLookup

the transaction manager lookup

softLockManager:SoftLockManager

the soft lock manager

transactionIDFactory:TransactionIDFactory

the transaction ID factory

comparator:ElementValueComparator

the element value comparator

Method Detail

addTwoPcExecutionListenerback to summary
public void addTwoPcExecutionListener(XAExecutionListener listener)

Implements net.sf.ehcache.transaction.xa.EhcacheXAResource.addTwoPcExecutionListener.

Doc from net.sf.ehcache.transaction.xa.EhcacheXAResource.addTwoPcExecutionListener.

Add a listener which will be called back according to the 2PC lifecycle

Parameters
listener:XAExecutionListener

the XAExecutionListener

commitback to summary
public void commit(Xid xid, boolean onePhase) throws XAException

Implements javax.transaction.xa.XAResource.commit.

Doc from javax.transaction.xa.XAResource.commit.

Commits the global transaction specified by xid.

Parameters
xid:Xid

A global transaction identifier

onePhase:boolean

If true, the resource manager should use a one-phase commit protocol to commit the work done on behalf of xid.

Exceptions
XAException:
An error has occurred. Possible XAExceptions are XA_HEURHAZ, XA_HEURCOM, XA_HEURRB, XA_HEURMIX, XAER_RMERR, XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or XAER_PROTO.

If the resource manager did not commit the transaction and the paramether onePhase is set to true, the resource manager may throw one of the XA_RB* exceptions. Upon return, the resource manager has rolled back the branch's work and has released all held resources.

commitInternalback to summary
public void commitInternal(Xid xid, boolean onePhase) throws XAException

The commit implementation

Parameters
xid:Xid

a XID

onePhase:boolean

true if onePhase, false otherwise

Exceptions
XAException:
when an error occurs
createTransactionContextback to summary
public XATransactionContext createTransactionContext() throws SystemException, RollbackException

Implements net.sf.ehcache.transaction.xa.EhcacheXAResource.createTransactionContext.

Doc from net.sf.ehcache.transaction.xa.EhcacheXAResource.createTransactionContext.

Obtain the already associated XATransactionContext with the current Transaction, or create a new one should none be there yet.

Returns:XATransactionContext

The associated Transaction associated XATransactionContext

Exceptions
SystemException:
Thrown if the associated transaction manager encounters an unexpected error condition.
RollbackException:
Thrown if the resource has to be enlisted with the transaction, while it is marked for rollback only.
endback to summary
public void end(Xid xid, int flag) throws XAException

Implements javax.transaction.xa.XAResource.end.

Doc from javax.transaction.xa.XAResource.end.

Ends the work performed on behalf of a transaction branch. The resource manager disassociates the XA resource from the transaction branch specified and lets the transaction complete.

If TMSUSPEND is specified in the flags, the transaction branch is temporarily suspended in an incomplete state. The transaction context is in a suspended state and must be resumed via the start method with TMRESUME specified.

If TMFAIL is specified, the portion of work has failed. The resource manager may mark the transaction as rollback-only

If TMSUCCESS is specified, the portion of work has completed successfully.

Parameters
xid:Xid

A global transaction identifier that is the same as the identifier used previously in the start method.

flag:int

One of TMSUCCESS, TMFAIL, or TMSUSPEND.

Exceptions
XAException:
An error has occurred. Possible XAException values are XAER_RMERR, XAER_RMFAILED, XAER_NOTA, XAER_INVAL, XAER_PROTO, or XA_RB*.
fireAfterCommitOrRollbackback to summary
private void fireAfterCommitOrRollback()
fireBeforePrepareback to summary
private void fireBeforePrepare()
forgetback to summary
public void forget(Xid xid) throws XAException

Implements javax.transaction.xa.XAResource.forget.

Doc from javax.transaction.xa.XAResource.forget.

Tells the resource manager to forget about a heuristically completed transaction branch.

Parameters
xid:Xid

A global transaction identifier.

Exceptions
XAException:
An error has occurred. Possible exception values are XAER_RMERR, XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or XAER_PROTO.
forgetInternalback to summary
public void forgetInternal(Xid xid) throws XAException

The forget implementation

Parameters
xid:Xid

a XID

Exceptions
XAException:
when an error occurs
getCacheNameback to summary
public String getCacheName()

Implements net.sf.ehcache.transaction.xa.EhcacheXAResource.getCacheName.

Doc from net.sf.ehcache.transaction.xa.EhcacheXAResource.getCacheName.

Getter to the name of the cache wrapped by this XAResource

Returns:String

net.sf.ehcache.Ehcache#getName value

getCurrentTransactionContextback to summary
public XATransactionContext getCurrentTransactionContext()

Implements net.sf.ehcache.transaction.xa.EhcacheXAResource.getCurrentTransactionContext.

Doc from net.sf.ehcache.transaction.xa.EhcacheXAResource.getCurrentTransactionContext.

Gets the current XATransactionContext associated with this resource

Returns:XATransactionContext

the current XATransactionContext, or null if none

getTransactionTimeoutback to summary
public int getTransactionTimeout() throws XAException

Implements javax.transaction.xa.XAResource.getTransactionTimeout.

Doc from javax.transaction.xa.XAResource.getTransactionTimeout.

Obtains the current transaction timeout value set for this XAResource instance. If XAResource.setTransactionTimeout was not used prior to invoking this method, the return value is the default timeout set for the resource manager; otherwise, the value used in the previous setTransactionTimeout call is returned.

Returns:int

the transaction timeout value in seconds.

Exceptions
XAException:
An error has occurred. Possible exception values are XAER_RMERR and XAER_RMFAIL.
isSameRMback to summary
public boolean isSameRM(XAResource xaResource) throws XAException

Implements javax.transaction.xa.XAResource.isSameRM.

Doc from javax.transaction.xa.XAResource.isSameRM.

This method is called to determine if the resource manager instance represented by the target object is the same as the resource manager instance represented by the parameter xares.

Parameters
xaResource:XAResource

An XAResource object whose resource manager instance is to be compared with the resource manager instance of the target object.

Returns:boolean

true if it's the same RM instance; otherwise false.

Exceptions
XAException:
An error has occurred. Possible exception values are XAER_RMERR and XAER_RMFAIL.
prepareback to summary
public int prepare(Xid xid) throws XAException

Implements javax.transaction.xa.XAResource.prepare.

Doc from javax.transaction.xa.XAResource.prepare.

Ask the resource manager to prepare for a transaction commit of the transaction specified in xid.

Parameters
xid:Xid

A global transaction identifier.

Returns:int

A value indicating the resource manager's vote on the outcome of the transaction. The possible values are: XA_RDONLY or XA_OK. If the resource manager wants to roll back the transaction, it should do so by raising an appropriate XAException in the prepare method.

Exceptions
XAException:
An error has occurred. Possible exception values are: XA_RB*, XAER_RMERR, XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or XAER_PROTO.
prepareInternalback to summary
public int prepareInternal(Xid xid) throws XAException

The prepare implementation

Parameters
xid:Xid

a XID

Returns:int

XA_OK or XA_RDONLY

Exceptions
XAException:
when an error occurs
prettyPrintXAResourceFlagsback to summary
private static String prettyPrintXAResourceFlags(int flags)
recoverback to summary
public Xid[] recover(int flags) throws XAException

Implements javax.transaction.xa.XAResource.recover.

Doc from javax.transaction.xa.XAResource.recover.

Obtains a list of prepared transaction branches from a resource manager. The transaction manager calls this method during recovery to obtain the list of transaction branches that are currently in prepared or heuristically completed states.

Parameters
flags:int

One of TMSTARTRSCAN, TMENDRSCAN, TMNOFLAGS. TMNOFLAGS must be used when no other flags are set in the parameter.

Returns:Xid[]

The resource manager returns zero or more XIDs of the transaction branches that are currently in a prepared or heuristically completed state. If an error occurs during the operation, the resource manager should throw the appropriate XAException.

Exceptions
XAException:
An error has occurred. Possible values are XAER_RMERR, XAER_RMFAIL, XAER_INVAL, and XAER_PROTO.
rollbackback to summary
public void rollback(Xid xid) throws XAException

Implements javax.transaction.xa.XAResource.rollback.

Doc from javax.transaction.xa.XAResource.rollback.

Informs the resource manager to roll back work done on behalf of a transaction branch.

Parameters
xid:Xid

A global transaction identifier.

Exceptions
XAException:
An error has occurred.
rollbackInternalback to summary
public void rollbackInternal(Xid xid) throws XAException

The rollback implementation

Parameters
xid:Xid

a XID

Exceptions
XAException:
when an error occurs
setTransactionTimeoutback to summary
public boolean setTransactionTimeout(int timeout) throws XAException

Implements javax.transaction.xa.XAResource.setTransactionTimeout.

Doc from javax.transaction.xa.XAResource.setTransactionTimeout.

Sets the current transaction timeout value for this XAResource instance. Once set, this timeout value is effective until setTransactionTimeout is invoked again with a different value. To reset the timeout value to the default value used by the resource manager, set the value to zero. If the timeout operation is performed successfully, the method returns true; otherwise false. If a resource manager does not support explicitly setting the transaction timeout value, this method returns false.

Parameters
timeout:int

The transaction timeout value in seconds.

Returns:boolean

true if the transaction timeout value is set successfully; otherwise false.

Exceptions
XAException:
An error has occurred. Possible exception values are XAER_RMERR, XAER_RMFAIL, or XAER_INVAL.
startback to summary
public void start(Xid xid, int flag) throws XAException

Implements javax.transaction.xa.XAResource.start.

Doc from javax.transaction.xa.XAResource.start.

Starts work on behalf of a transaction branch specified in xid. If TMJOIN is specified, the start applies to joining a transaction previously seen by the resource manager. If TMRESUME is specified, the start applies to resuming a suspended transaction specified in the parameter xid. If neither TMJOIN nor TMRESUME is specified and the transaction specified by xid has previously been seen by the resource manager, the resource manager throws the XAException exception with XAER_DUPID error code.

Parameters
xid:Xid

A global transaction identifier to be associated with the resource.

flag:int

One of TMNOFLAGS, TMJOIN, or TMRESUME.

Exceptions
XAException:
An error has occurred. Possible exceptions are XA_RB*, XAER_RMERR, XAER_RMFAIL, XAER_DUPID, XAER_OUTSIDE, XAER_NOTA, XAER_INVAL, or XAER_PROTO.
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override