com.sun.xml.ws.tx.at
Class ATCoordinator

java.lang.Object
  extended by com.sun.xml.ws.tx.coordinator.Coordinator
      extended by com.sun.xml.ws.tx.at.ATCoordinator
All Implemented Interfaces:
javax.transaction.Synchronization, javax.transaction.xa.XAResource
Direct Known Subclasses:
ATSubCoordinator

public class ATCoordinator
extends Coordinator
implements javax.transaction.Synchronization, javax.transaction.xa.XAResource

Atomic Transaction Coordinator

Coordinator States: NONE, ACTIVE, Volatile2PCPrepare, Durable2PCPrepare, Committing, Aborting

Relationship between ATCoordinator and Java Transaction Manager. ATCoordinator is registered as an XAResource with Java Transaction Manager. This enables Java Transaction Manager to be root transaction manager that for ATCoordinator durable 2pc participants. ATCoordinator registers for Transaction Synchronization if it has volatile participants. This enables volatile participants to be prepared BEFORE durable 2pc participants are prepared.

Coordination Context expires specifies the period, measured from the point in time at which the context was first created or received, after which a transaction MAY be terminated solely due to its length of operation. From that point forward, the coordinator MAY elect to unilaterally roll back the transaction, so long as it has not made a commit decision.

Since:
1.0

Field Summary
static java.net.URI localCoordinationProtocolServiceURI
           
static javax.xml.ws.EndpointReference localCoordinatorProtocolService
           
protected static TransactionManagerImpl tm
           
protected  javax.transaction.Transaction transaction
           
 
Fields inherited from interface javax.transaction.xa.XAResource
TMENDRSCAN, TMFAIL, TMJOIN, TMNOFLAGS, TMONEPHASE, TMRESUME, TMSTARTRSCAN, TMSUCCESS, TMSUSPEND, XA_OK, XA_RDONLY
 
Constructor Summary
ATCoordinator(CoordinationContextInterface context)
          Construct a new Coordinator object from the specified context.
ATCoordinator(CoordinationContextInterface context, CreateCoordinationContextType request)
          Construct a new Coordinator object from the specified context and soap request.
 
Method Summary
 void aborted(java.lang.String participantId)
           
 void addRegistrant(Registrant registrant, javax.xml.ws.WebServiceContext wsContext)
          Add the specified Registrant to the list of registrants for this coordinated activity.
 void afterCompletion(int i)
           
 void beforeCompletion()
          Register this with TransactionSynchronizationRegistery.
 void commit(javax.transaction.xa.Xid xid, boolean onePhase)
           
 void committed(java.lang.String participantId)
           
 void end(javax.transaction.xa.Xid xid, int flags)
           
 boolean expirationGuard()
          Return false if it is okay to rollback the transaction.
 void expire()
          Release resources held by this coordinator.
 void forget()
          Release all resources associated with this coordinator
 void forget(ATParticipant part)
           
 void forget(java.lang.String partId)
           
 void forget(javax.transaction.xa.Xid xid)
          forget everything about this transaction.
 ATCompletion getCompletionRegistrant()
          Get the completion registrant.
protected  java.lang.String getCoordIdPartId(Registrant registrant)
           
protected  java.lang.String getCoordIdPartId(java.lang.String participantId)
           
 javax.xml.ws.EndpointReference getCoordinatorProtocolServiceForRegistrant(Registrant r)
          Return the Coordinator Protocol Service EPR for registrant r.
 java.util.Collection<ATParticipant> getDurableParticipants()
          Return a Collection of durable 2pc participants.
 java.util.Collection<ATParticipant> getDurableParticipantsSnapshot()
           
 javax.xml.ws.EndpointReference getParentCoordinatorRegistrationEPR()
           
 Registrant getRegistrant(java.lang.String id)
          Get the registrant with the specified id or null if it does not exist.
 java.util.List<Registrant> getRegistrants()
          Get the list of Registrants for this coordinated activity.
 javax.transaction.Transaction getTransaction()
           
 int getTransactionTimeout()
           
 java.util.Collection<ATParticipant> getVolatileParticipants()
          Return a Collection of volatile 2pc participants.
 java.util.Collection<ATParticipant> getVolatileParticipantsSnapshot()
           
static WSATCoordinator getWSATCoordinatorService()
           
 boolean hasOutstandingParticipants()
           
 void initiateCommit()
           
 void initiateDurableCommit()
           
 void initiateDurablePrepare()
          TODO: Each PREPARED/READONLY Volatile ATParticipant should check if it is time to start the durable 2PC phase by calling this method.
 void initiateDurableRollback()
           
 void initiateRollback()
           
 void initiateVolatileCommit()
           
 void initiateVolatilePrepare()
          Send 2PC prepare to all volatile participants

Volatile 2PC prepare constraint from 2004 WS-AT, section 3.3.1 the root coordinator begins the prepare phase of all participants registered for the Volatile 2PC protocol.

 void initiateVolatileRollback()
           
 boolean isSameRM(javax.transaction.xa.XAResource xAResource)
           
 boolean isSubordinateCoordinator()
           
 int prepare(javax.transaction.xa.Xid xid)
          Synchronous prepare request invoked by JTS coordinator as part of its 2PC protocol.
 void prepared(java.lang.String participantId)
           
 void prepared(java.lang.String participantId, javax.xml.ws.EndpointReference unknownParticipantReplyEPR)
           
 void readonly(java.lang.String participantId)
           
 javax.transaction.xa.Xid[] recover(int i)
           
protected  boolean registerWithDurableParent()
          Enlist with parent of ATCoordinator which is JTA transaction manager.
protected  void registerWithVolatileParent()
           
 void removeRegistrant(java.lang.String id)
          Remove the registrant with the specified id
 void replay(java.lang.String participantId)
          Implement inbound event replay for Atomic Transaction 2PC Protocol(Coordinator View).
 void resumeTransaction()
           
 void rollback(javax.transaction.xa.Xid xid)
           
 void setTransaction(javax.transaction.Transaction txn)
          Set once field.
 boolean setTransactionTimeout(int i)
           
 void start(javax.transaction.xa.Xid xid, int flags)
           
 javax.transaction.Transaction suspendTransaction()
           
protected  void waitForCommitOrRollbackResponse(Protocol protocol)
           
protected  void waitForDurablePrepareResponse()
          Wait for all Durable participants to respond to prepare.
protected  void waitForVolatilePrepareResponse()
          Wait for all volatile participants to respond to prepare.
 
Methods inherited from class com.sun.xml.ws.tx.coordinator.Coordinator
getContext, getExpires, getId, getIdValue, getRequest, isExpired, isSubordinate, registerWithRootRegistrationService, setExpired, setExpires
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

localCoordinationProtocolServiceURI

public static final java.net.URI localCoordinationProtocolServiceURI

tm

protected static final TransactionManagerImpl tm

transaction

protected javax.transaction.Transaction transaction

localCoordinatorProtocolService

public static final javax.xml.ws.EndpointReference localCoordinatorProtocolService
Constructor Detail

ATCoordinator

public ATCoordinator(CoordinationContextInterface context,
                     CreateCoordinationContextType request)
Construct a new Coordinator object from the specified context and soap request.

This method is an entry point for the Activation service's createCoordinationContext operation. This entry point probably won't be used much, or not at all if we choose not to publish the operation (which is optional in the WS-Coordination spec).

Parameters:
context - The coordination context
request - The soap request

ATCoordinator

public ATCoordinator(CoordinationContextInterface context)
Construct a new Coordinator object from the specified context.

This constructor will be the main entry point for activity within the AppServer.

Parameters:
context - The coordination context
Method Detail

setTransaction

public void setTransaction(javax.transaction.Transaction txn)
Set once field.


getTransaction

public javax.transaction.Transaction getTransaction()

getRegistrants

public java.util.List<Registrant> getRegistrants()
Get the list of Registrants for this coordinated activity.

The returned list is unmodifiable (read-only). Add new Registrants with the addRegistrant(com.sun.xml.ws.tx.coordinator.Registrant, javax.xml.ws.WebServiceContext) api instead.

Specified by:
getRegistrants in class Coordinator
Returns:
the list of Registrant objects

registerWithVolatileParent

protected void registerWithVolatileParent()

registerWithDurableParent

protected boolean registerWithDurableParent()
                                     throws javax.transaction.RollbackException,
                                            javax.transaction.SystemException
Enlist with parent of ATCoordinator which is JTA transaction manager.

Throws:
javax.transaction.RollbackException
javax.transaction.SystemException

addRegistrant

public void addRegistrant(Registrant registrant,
                          javax.xml.ws.WebServiceContext wsContext)
Add the specified Registrant to the list of registrants for this coordinated activity.

Specified by:
addRegistrant in class Coordinator
Parameters:
registrant - The Registrant
wsContext - the web service context of the incoming message or null if it isn't available

getRegistrant

public Registrant getRegistrant(java.lang.String id)
Get the registrant with the specified id or null if it does not exist.

Specified by:
getRegistrant in class Coordinator
Parameters:
id - the registrant id
Returns:
the Registrant object or null if the id does not exist

removeRegistrant

public void removeRegistrant(java.lang.String id)
Description copied from class: Coordinator
Remove the registrant with the specified id

Specified by:
removeRegistrant in class Coordinator
Parameters:
id - the registrant id

getVolatileParticipants

public java.util.Collection<ATParticipant> getVolatileParticipants()
Return a Collection of volatile 2pc participants.

This Collection is modifiable.

Returns:
A modifiable Collection of the volatile 2pc participants

getVolatileParticipantsSnapshot

public java.util.Collection<ATParticipant> getVolatileParticipantsSnapshot()

getDurableParticipants

public java.util.Collection<ATParticipant> getDurableParticipants()
Return a Collection of durable 2pc participants.

This Collection is modifiable.

Returns:
A modifiable Collection of the durable 2pc participants

getDurableParticipantsSnapshot

public java.util.Collection<ATParticipant> getDurableParticipantsSnapshot()

getCompletionRegistrant

public ATCompletion getCompletionRegistrant()
Get the completion registrant.

Returns:
The completion registrant

initiateVolatilePrepare

public void initiateVolatilePrepare()
Send 2PC prepare to all volatile participants

Volatile 2PC prepare constraint from 2004 WS-AT, section 3.3.1 the root coordinator begins the prepare phase of all participants registered for the Volatile 2PC protocol. All participants registered for this protocol must respond before a Prepare is issued to a participant registered for Durable 2PC. Further participants may register with the coordinator until the coordinator issues a Prepare to any durable participant.


waitForVolatilePrepareResponse

protected void waitForVolatilePrepareResponse()
Wait for all volatile participants to respond to prepare.

Volatile participant state is set before this method returns.


initiateDurablePrepare

public void initiateDurablePrepare()
TODO: Each PREPARED/READONLY Volatile ATParticipant should check if it is time to start the durable 2PC phase by calling this method.


waitForDurablePrepareResponse

protected void waitForDurablePrepareResponse()
Wait for all Durable participants to respond to prepare.

Durable participant state is set before this method returns.


initiateCommit

public void initiateCommit()

initiateDurableCommit

public void initiateDurableCommit()

initiateVolatileCommit

public void initiateVolatileCommit()

initiateRollback

public void initiateRollback()

initiateDurableRollback

public void initiateDurableRollback()

initiateVolatileRollback

public void initiateVolatileRollback()

beforeCompletion

public void beforeCompletion()
Register this with TransactionSynchronizationRegistery. This should get called by JTS transaction system before 2PC Participants and XAResources are prepared.

Specified by:
beforeCompletion in interface javax.transaction.Synchronization

afterCompletion

public void afterCompletion(int i)
Specified by:
afterCompletion in interface javax.transaction.Synchronization

waitForCommitOrRollbackResponse

protected void waitForCommitOrRollbackResponse(Protocol protocol)

prepare

public int prepare(javax.transaction.xa.Xid xid)
            throws javax.transaction.xa.XAException
Synchronous prepare request invoked by JTS coordinator as part of its 2PC protocol.

Prepare this coordinator and return result of preparation.

Specified by:
prepare in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

commit

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

rollback

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

recover

public javax.transaction.xa.Xid[] recover(int i)
                                   throws javax.transaction.xa.XAException
Specified by:
recover in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

setTransactionTimeout

public boolean setTransactionTimeout(int i)
                              throws javax.transaction.xa.XAException
Specified by:
setTransactionTimeout in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

start

public void start(javax.transaction.xa.Xid xid,
                  int flags)
           throws javax.transaction.xa.XAException
Specified by:
start in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

end

public void end(javax.transaction.xa.Xid xid,
                int flags)
         throws javax.transaction.xa.XAException
Specified by:
end in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

forget

public void forget(javax.transaction.xa.Xid xid)
            throws javax.transaction.xa.XAException
forget everything about this transaction.

Recovers resources held by a transaction. After a transaction is committed or aborted, it is forgotten.

Specified by:
forget in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

getTransactionTimeout

public int getTransactionTimeout()
                          throws javax.transaction.xa.XAException
Specified by:
getTransactionTimeout in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

isSameRM

public boolean isSameRM(javax.transaction.xa.XAResource xAResource)
                 throws javax.transaction.xa.XAException
Specified by:
isSameRM in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

prepared

public void prepared(java.lang.String participantId)

prepared

public void prepared(java.lang.String participantId,
                     javax.xml.ws.EndpointReference unknownParticipantReplyEPR)

committed

public void committed(java.lang.String participantId)

readonly

public void readonly(java.lang.String participantId)

aborted

public void aborted(java.lang.String participantId)

replay

public void replay(java.lang.String participantId)
Implement inbound event replay for Atomic Transaction 2PC Protocol(Coordinator View).


isSubordinateCoordinator

public boolean isSubordinateCoordinator()

getParentCoordinatorRegistrationEPR

public javax.xml.ws.EndpointReference getParentCoordinatorRegistrationEPR()

getWSATCoordinatorService

public static WSATCoordinator getWSATCoordinatorService()

getCoordIdPartId

protected java.lang.String getCoordIdPartId(Registrant registrant)

getCoordIdPartId

protected java.lang.String getCoordIdPartId(java.lang.String participantId)

forget

public void forget(ATParticipant part)

forget

public void forget(java.lang.String partId)

getCoordinatorProtocolServiceForRegistrant

public javax.xml.ws.EndpointReference getCoordinatorProtocolServiceForRegistrant(Registrant r)
Description copied from class: Coordinator
Return the Coordinator Protocol Service EPR for registrant r.

Specified by:
getCoordinatorProtocolServiceForRegistrant in class Coordinator
Parameters:
r - registrant
Returns:
the CPS EPT for the specified registrant

expirationGuard

public boolean expirationGuard()
Return false if it is okay to rollback the transaction. Do not allow transaction expiration after Phase 2 begins.

Specified by:
expirationGuard in class Coordinator
Returns:
true if the coordinator should NOT expire, false otherwise.

expire

public void expire()
Description copied from class: Coordinator
Release resources held by this coordinator.

This method will be automatically invoked once if the activity has a non-zero expiration.

During expiration, the coordinator will iterate over all of its registrants and tell them to expire. Depending on their state, registrants will either expire or not. A coordinator will not completely expire until all of its registrants have expired.

Overrides:
expire in class Coordinator

forget

public void forget()
Description copied from class: Coordinator
Release all resources associated with this coordinator

Overrides:
forget in class Coordinator

resumeTransaction

public void resumeTransaction()
                       throws javax.xml.ws.WebServiceException
Throws:
javax.xml.ws.WebServiceException

suspendTransaction

public javax.transaction.Transaction suspendTransaction()

hasOutstandingParticipants

public boolean hasOutstandingParticipants()