org.csc.phynixx.xa
Class PhynixxXAResource<C extends IPhynixxConnection>

java.lang.Object
  extended by org.csc.phynixx.xa.PhynixxXAResource<C>
All Implemented Interfaces:
XAResource, IPhynixxXAResource<C>

public class PhynixxXAResource<C extends IPhynixxConnection>
extends Object
implements IPhynixxXAResource<C>

A transactional branch may be associated with differnt XAResources (TMJOIN) or a XAResource may be shared with different transaction branches

Therefore a transactional branch might be associated to many XAResources or to many transactions (==XIDs)

A XAresourec can be initialized with a connection. This connection is used, the first time an TX is opened on the XAResource.

Any following TX get an new connection

Author:
christoph

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
PhynixxXAResource(String xaId, TransactionManager transactionManager, PhynixxXAResourceFactory<C> xaResourceFactory)
          TODO timeOut ueber einen Listener steuern und konfigierbar machen
 
Method Summary
 void addXAResourceListener(IPhynixxXAResourceListener listener)
           
 void close()
          finds the transactional branch of the current XAResource associated with die XID

Close this XA XAResourceProgressState.

 void commit(Xid xid, boolean onePhase)
           
 void conditionViolated()
          called when the current XAresource is expired (time out occurred) The current Impl. does nothing but marked the associated TX as rollback only The underlying core connection are not treated ....
 void end(Xid xid, int flags)
          This method ends the work performed on behalf of a transaction branch.
 boolean equals(Object obj)
           
 void forget(Xid xid)
          finds the transactional branch of the current XAResource associated with die XID and closes it without commit or explicit rollback
 Object getId()
           
 int getTransactionTimeout()
           
 IPhynixxXAConnection<C> getXAConnection()
          accessing the XAConnection forces the XAResource to enlist to the Transaction.
 int hashCode()
           
 boolean isClosed()
           
 boolean isSameRM(XAResource xaResource)
          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 .
 boolean isSupportsTimeOut()
           
 int prepare(Xid xid)
          finds the transactional branch of the current XAResource associated with die XID

Prepares to perform a commit.

 Xid[] recover(int flags)
          the system is recovered by the xaResourceFactory representing the persistence management system,
 void removeXAResourceListener(IPhynixxXAResourceListener<C> listener)
           
 void rollback(Xid xid)
           
 void setSupportsTimeOut(boolean supportsTimeOut)
           
 boolean setTransactionTimeout(int seconds)
          This method sets the transaction timeout value for this XAResource instance.
 void start(Xid xid, int flags)
          transaction branch is interchangeably with transaction context

situation : XAResource is associtaed with XID(1) flags=TMNOFLAGS with XID(1) result : XAResource creates a new transactional context

situation : XAResource is associtaed with XID(1) flags=TMJOIN/TNRESUME with XID(1) (may be different in branch) result : XAResource joins the transactional context with the XAResource already associated with XID(1) If TMRESUME is specified, start is to resume a suspended transaction branch specified in xid.

 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PhynixxXAResource

public PhynixxXAResource(String xaId,
                         TransactionManager transactionManager,
                         PhynixxXAResourceFactory<C> xaResourceFactory)
TODO timeOut ueber einen Listener steuern und konfigierbar machen

Method Detail

conditionViolated

public void conditionViolated()
called when the current XAresource is expired (time out occurred) The current Impl. does nothing but marked the associated TX as rollback only The underlying core connection are not treated ....

There are two different situation that have to be handled If the connection expires because of a long running method call the connection isn't treated and the XAResource is marked as rollback only. The rollback is done by the Transactionmanager. If the TX expires because the Transactionmanagers doesn't answer, the underlying connection is rolledback and the XAResource is marked as rollback only (N.B. rolling back the connection marks the XAResource as heuristically rolled back)


isSupportsTimeOut

public boolean isSupportsTimeOut()

setSupportsTimeOut

public void setSupportsTimeOut(boolean supportsTimeOut)

getXAConnection

public IPhynixxXAConnection<C> getXAConnection()
accessing the XAConnection forces the XAResource to enlist to the Transaction. getXAConnection() must be called in the appropriate TransactionContext

Specified by:
getXAConnection in interface IPhynixxXAResource<C extends IPhynixxConnection>
Returns:

isClosed

public boolean isClosed()

start

public void start(Xid xid,
                  int flags)
           throws XAException
transaction branch is interchangeably with transaction context

situation : XAResource is associtaed with XID(1) flags=TMNOFLAGS with XID(1) result : XAResource creates a new transactional context

situation : XAResource is associtaed with XID(1) flags=TMJOIN/TNRESUME with XID(1) (may be different in branch) result : XAResource joins the transactional context with the XAResource already associated with XID(1) If TMRESUME is specified, start is to resume a suspended transaction branch specified in xid.

This method starts work on behalf of a transaction branch.

If TMJOIN is specified, start is for joining an exisiting transaction branch xid.

If neither TMJOIN nor TMRESUME is specified and the transaction branch specified in xid already exists, the resource manager throw the XAException with XAER_DUPID error code.

If the XAResource has a current connection and flags ==TMJOIN/TMRESUME, the current connection is substituted by the connection of the existing TX.

Specified by:
start in interface XAResource
Parameters:
xid - A global transaction identifier to be associated with the resource.
flags - One of TMNOFLAGS, TMJOIN, or TMRESUME.
Throws:
XAException

commit

public void commit(Xid xid,
                   boolean onePhase)
            throws XAException
Specified by:
commit in interface XAResource
Throws:
XAException

prepare

public int prepare(Xid xid)
            throws XAException
finds the transactional branch of the current XAResource associated with die XID

Prepares to perform a commit. May actually perform a commit in the flag commitOnPrepare is set to true.

This method is called to ask the resource manager to prepare for a transaction commit of the transaction specified in xid.

Specified by:
prepare in interface XAResource
Parameters:
xid - A global transaction identifier.
Returns:
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 throwing an appropriate XAException in the prepare method.
Throws:
XAException - An error has occurred. Possible exception values are: XA_RB*, XAER_RMERR, XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or XAER_PROTO.

rollback

public void rollback(Xid xid)
              throws XAException
Specified by:
rollback in interface XAResource
Throws:
XAException

end

public void end(Xid xid,
                int flags)
         throws XAException
This method ends the work performed on behalf of a transaction branch.

The resource manager dissociates the XA resource from the transaction branch specified and let the transaction be completed. If TMSUSPEND is specified in flags, the transaction branch is temporarily suspended in incomplete state. The transaction context is in suspended state and must be resumed via start with TMRESUME specified.

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

the spec doesn't no fix the order of commit/rollback and end and we have to take of both orders. If end comes before rollback/commit, the transactional branch has to be freeze. If rollback/commit comes before end, the transactional branch has to be closed

If TMSUCCESS is specified, the portion of work has completed successfully. end is called in Transaction.delistResource

Specified by:
end in interface XAResource
Parameters:
xid - A global transaction identifier.
flags - If true, the resource manager should use a one-phase commit protocol to commit the work done on behalf of xid.
Throws:
XAException

forget

public void forget(Xid xid)
            throws XAException
finds the transactional branch of the current XAResource associated with die XID and closes it without commit or explicit rollback

Specified by:
forget in interface XAResource
Parameters:
xid -
Throws:
XAException

getTransactionTimeout

public int getTransactionTimeout()
                          throws XAException
Specified by:
getTransactionTimeout in interface XAResource
Throws:
XAException

isSameRM

public boolean isSameRM(XAResource xaResource)
                 throws XAException
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 .

The resource manager is reresented by the ResourceFactory.

Specified by:
isSameRM in interface XAResource
Parameters:
xaResource - An XAResource object.
Returns:
true if same RM instance; otherwise false.
Throws:
XAException

close

public void close()
finds the transactional branch of the current XAResource associated with die XID

Close this XA XAResourceProgressState. All depending Connection are closed


recover

public Xid[] recover(int flags)
              throws XAException
the system is recovered by the xaResourceFactory representing the persistence management system,

Specified by:
recover in interface XAResource
Throws:
XAException

setTransactionTimeout

public boolean setTransactionTimeout(int seconds)
                              throws XAException
This method sets the 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 transaction timeout value to be set explicitly, this method returns false.

Specified by:
setTransactionTimeout in interface XAResource
Parameters:
seconds - An positive integer specifying the timout value in seconds. Zero resets the transaction timeout value to the default one used by the resource manager. A negative value results in XAExceptio to be thrown with XAER_INVAL error code.
Throws:
XAException - An error has occurred. Possible exception values are: XAER_RMERR, XAER_RMFAIL, or XAER_INVAL.

equals

public final boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public final int hashCode()
Overrides:
hashCode in class Object

getId

public Object getId()

toString

public String toString()
Overrides:
toString in class Object

addXAResourceListener

public void addXAResourceListener(IPhynixxXAResourceListener listener)

removeXAResourceListener

public void removeXAResourceListener(IPhynixxXAResourceListener<C> listener)


Copyright © 2015. All rights reserved.