ehcache

net.sf.ehcache.transaction.xa
Class EhcacheXAResourceImpl

java.lang.Object
  extended by net.sf.ehcache.transaction.xa.EhcacheXAResourceImpl
All Implemented Interfaces:
XAResource, EhcacheXAResource

public class EhcacheXAResourceImpl
extends Object
implements EhcacheXAResource

The EhcacheXAResource implementation

Author:
Ludovic Orban

Field Summary
 
Fields inherited from interface javax.transaction.xa.XAResource
TMENDRSCAN, TMFAIL, TMJOIN, TMNOFLAGS, TMONEPHASE, TMRESUME, TMSTARTRSCAN, TMSUCCESS, TMSUSPEND, XA_OK, XA_RDONLY
 
Constructor Summary
EhcacheXAResourceImpl(Ehcache cache, Store underlyingStore, TransactionManagerLookup txnManagerLookup, SoftLockManager softLockManager, TransactionIDFactory transactionIDFactory, ElementValueComparator comparator, org.terracotta.statistics.observer.OperationObserver<XaCommitOutcome> commitObserver, org.terracotta.statistics.observer.OperationObserver<XaRollbackOutcome> rollbackObserver, org.terracotta.statistics.observer.OperationObserver<XaRecoveryOutcome> recoveryObserver)
          Constructor
 
Method Summary
 void addTwoPcExecutionListener(XAExecutionListener listener)
          Add a listener which will be called back according to the 2PC lifecycle
 void commit(Xid xid, boolean onePhase)
          
 void commitInternal(Xid xid, boolean onePhase)
          The commit implementation
 XATransactionContext createTransactionContext()
          Obtain the already associated XATransactionContext with the current Transaction, or create a new one should none be there yet.
 void end(Xid xid, int flag)
          
 void forget(Xid xid)
          
 void forgetInternal(Xid xid)
          The forget implementation
 String getCacheName()
          Getter to the name of the cache wrapped by this XAResource
 XATransactionContext getCurrentTransactionContext()
          Gets the current XATransactionContext associated with this resource
 int getTransactionTimeout()
          
 boolean isSameRM(XAResource xaResource)
          
 int prepare(Xid xid)
          
 int prepareInternal(Xid xid)
          The prepare implementation
 Xid[] recover(int flags)
          
 void rollback(Xid xid)
          
 void rollbackInternal(Xid xid)
          The rollback implementation
 boolean setTransactionTimeout(int timeout)
          
 void start(Xid xid, int flag)
          
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EhcacheXAResourceImpl

public EhcacheXAResourceImpl(Ehcache cache,
                             Store underlyingStore,
                             TransactionManagerLookup txnManagerLookup,
                             SoftLockManager softLockManager,
                             TransactionIDFactory transactionIDFactory,
                             ElementValueComparator comparator,
                             org.terracotta.statistics.observer.OperationObserver<XaCommitOutcome> commitObserver,
                             org.terracotta.statistics.observer.OperationObserver<XaRollbackOutcome> rollbackObserver,
                             org.terracotta.statistics.observer.OperationObserver<XaRecoveryOutcome> recoveryObserver)
Constructor

Parameters:
cache - the cache
underlyingStore - the underlying store
txnManagerLookup - the transaction manager lookup
softLockManager - the soft lock manager
transactionIDFactory - the transaction ID factory
comparator - the element value comparator
Method Detail

start

public void start(Xid xid,
                  int flag)
           throws XAException

Specified by:
start in interface XAResource
Throws:
XAException

end

public void end(Xid xid,
                int flag)
         throws XAException

Specified by:
end in interface XAResource
Throws:
XAException

forget

public void forget(Xid xid)
            throws XAException

Specified by:
forget in interface XAResource
Throws:
XAException

forgetInternal

public void forgetInternal(Xid xid)
                    throws XAException
The forget implementation

Parameters:
xid - a XID
Throws:
XAException - when an error occurs

getTransactionTimeout

public int getTransactionTimeout()
                          throws XAException

Specified by:
getTransactionTimeout in interface XAResource
Throws:
XAException

isSameRM

public boolean isSameRM(XAResource xaResource)
                 throws XAException

Specified by:
isSameRM in interface XAResource
Throws:
XAException

prepare

public int prepare(Xid xid)
            throws XAException

Specified by:
prepare in interface XAResource
Throws:
XAException

prepareInternal

public int prepareInternal(Xid xid)
                    throws XAException
The prepare implementation

Parameters:
xid - a XID
Returns:
XA_OK or XA_RDONLY
Throws:
XAException - when an error occurs

commit

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

Specified by:
commit in interface XAResource
Throws:
XAException

commitInternal

public void commitInternal(Xid xid,
                           boolean onePhase)
                    throws XAException
The commit implementation

Parameters:
xid - a XID
onePhase - true if onePhase, false otherwise
Throws:
XAException - when an error occurs

recover

public Xid[] recover(int flags)
              throws XAException

Specified by:
recover in interface XAResource
Throws:
XAException

rollback

public void rollback(Xid xid)
              throws XAException

Specified by:
rollback in interface XAResource
Throws:
XAException

rollbackInternal

public void rollbackInternal(Xid xid)
                      throws XAException
The rollback implementation

Parameters:
xid - a XID
Throws:
XAException - when an error occurs

setTransactionTimeout

public boolean setTransactionTimeout(int timeout)
                              throws XAException

Specified by:
setTransactionTimeout in interface XAResource
Throws:
XAException

addTwoPcExecutionListener

public void addTwoPcExecutionListener(XAExecutionListener listener)
Add a listener which will be called back according to the 2PC lifecycle

Specified by:
addTwoPcExecutionListener in interface EhcacheXAResource
Parameters:
listener - the XAExecutionListener

getCacheName

public String getCacheName()
Getter to the name of the cache wrapped by this XAResource

Specified by:
getCacheName in interface EhcacheXAResource
Returns:
Ehcache.getName() value

createTransactionContext

public XATransactionContext createTransactionContext()
                                              throws SystemException,
                                                     RollbackException
Obtain the already associated XATransactionContext with the current Transaction, or create a new one should none be there yet.

Specified by:
createTransactionContext in interface EhcacheXAResource
Returns:
The associated Transaction associated XATransactionContext
Throws:
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.

getCurrentTransactionContext

public XATransactionContext getCurrentTransactionContext()
Gets the current XATransactionContext associated with this resource

Specified by:
getCurrentTransactionContext in interface EhcacheXAResource
Returns:
the current XATransactionContext, or null if none

toString

public String toString()
Overrides:
toString in class Object

ehcache

Copyright 2001-2015, Terracotta, Inc.