FileDocCategorySizeDatePackage
ATSubCoordinator.javaAPI DocExample21953Tue May 29 16:57:16 BST 2007com.sun.xml.ws.tx.at

ATSubCoordinator

public class ATSubCoordinator extends ATCoordinator
author
jf39279

Fields Summary
private static com.sun.xml.ws.tx.common.TxLogger
logger
final com.sun.enterprise.transaction.TransactionImport
importTm
private ATParticipant
rootVolatileParticipant
private ATParticipant
rootDurableParticipant
private boolean
guardTimeout
private boolean
forgotten
private Xid
xid
private javax.resource.spi.XATerminator
xaTerminator
Constructors Summary
public ATSubCoordinator(com.sun.xml.ws.tx.coordinator.CoordinationContextInterface context, com.sun.xml.ws.tx.webservice.member.coord.CreateCoordinationContextType request)
Creates a new instance of ATSubCoordinator

    
               
         
        super(context, request);
        assert getContext().getRootRegistrationService() != null;
    
public ATSubCoordinator(com.sun.xml.ws.tx.coordinator.CoordinationContextInterface context)

        super(context);
        assert getContext().getRootRegistrationService() != null;
    
Methods Summary
public voidaddRegistrant(com.sun.xml.ws.tx.coordinator.Registrant registrant, javax.xml.ws.WebServiceContext wsContext)

        //
        if (registerWithRootRegistrationService(registrant)) {
            // registrant is either volatile or durable participant with subordinate coordinator's parent coordinator.
            // do not add this participant to ATSubCoordinator list of participants it is managing.
            return;
        }
        super.addRegistrant(registrant, wsContext);
        switch (registrant.getProtocol()) {
            case VOLATILE:
                registerWithVolatileParent();
                break;

            case DURABLE:
                registerWithDurableParent();
                break;

            case COMPLETION:
                throw new UnsupportedOperationException("can not register for completion with subordinate coordinator");
        }
    
public voidafterCompletion(int i)

        // Ensure that afterCompletion disabled for subordinate coordinator    
        throw new UnsupportedOperationException("No afterCompletion for subordinate coordinator");
    
public voidbeforeCompletion()
Subordinate Coordinator does not use this mechanism. Ensure it is not called.

        // Ensure that beforeCompletion disabled for subordinate coordinator
        // Subordinate coordinator should not be registered with TransactionSynchronizationRegistry.
        throw new UnsupportedOperationException("No beforeCompletion for subordinate coordinator");
    
public voidbeginImportTransaction()
Import a transactional context from an external transaction manager via WS-AT Coordination Context that was propagated in a SOAP request message.

see
#endImportTransaction()

        Transaction currentTxn = null;
        
        try {    
            importTm.recreate(getCoordinationXid(), getExpires());
        } catch (IllegalStateException ex) {
            String message = LocalizationMessages.IMPORT_TRANSACTION_FAILED_0028(getIdValue(),
                                                                                 getCoordinationXid().toString());
            logger.warning("beginImportTransaction", message, ex);
            throw new WebServiceException(message, ex);
        } 
        try{  
            currentTxn = tm.getTransaction();
        } catch (SystemException ex) {
            String message = LocalizationMessages.IMPORT_TXN_GET_TXN_FAILED_0030(getIdValue());
            logger.warning("beginImportTransaction", message, ex);
            throw new WebServiceException(message, ex);
        }     
        assert currentTxn != null;
        setTransaction(currentTxn);
        tm.setCoordinationContext(getContext());
    
public voidcommit(javax.transaction.xa.Xid xid, boolean onePhase)

        if (logger.isLogging(Level.FINER)) {
            logger.entering("XAResource_commit(xid=" + xid + " ,onePhase=" + onePhase + ")");
        }
        // TODO: Commit AT Subordinate Coordinator state so it can be recovered in case of failure.
        //       Only durable participants need to be recoverable.

        // This coordinator commits when root ws-at coordinator sends a prepare to this subordinate
        // coordinator that is a participant to that coordinator.
        if (logger.isLogging(Level.FINER)) {
            logger.exiting("XAResource_commit");
        }
    
public voidendImportTransaction()
Ends the importing of an external transaction.

Post-condition: terminates beginImportTransaction.

see
#beginImportTransaction()

 
        if (transaction != null) {
            try {
                importTm.release(getCoordinationXid());
            } catch (Error e) {
                logger.warning("endImportTransaction",
                        LocalizationMessages.EXCEPTION_RELEASING_IMPORTED_TRANSACTION_0029(), e);
            }
            setTransaction(null);
        }
    
public booleanexpirationGuard()

        synchronized (this) {
            return guardTimeout;
        }
    
public voidforget(java.lang.String partId)

        if (rootVolatileParticipant != null && rootVolatileParticipant.getIdValue().equals(partId)) {
            rootVolatileParticipant = null;
            if (logger.isLogging(Level.FINE)) {
                logger.fine("forget", "forgot volatile participant link to parent " + getCoordIdPartId(partId));
            }
            if (!hasOutstandingParticipants()) {
                forget();
            }
            return;
        }
        if (rootDurableParticipant != null && rootDurableParticipant.getIdValue().equals(partId)) {
            rootDurableParticipant = null;
            if (logger.isLogging(Level.FINE)) {
                logger.fine("forget", "forgot durable participant link to parent " + getCoordIdPartId(partId));
            }
            if (!hasOutstandingParticipants()) {
                forget();
            }
            return;
        }

        // see if just a regular participant of this coordinator
        super.forget(partId);
    
public voidforget()

        synchronized(this) {
            if (forgotten) {
                return;
            } else {
                forgotten = true;
            }
            if (rootVolatileParticipant != null){
                rootVolatileParticipant.forget();
                rootVolatileParticipant = null;
            }
            if (rootDurableParticipant != null){
                rootDurableParticipant.forget();
                rootDurableParticipant = null;
            }
            CoordinationXid.forget(this.getIdValue());
            super.forget();
        }
    
public javax.transaction.xa.XidgetCoordinationXid()


       
        if (xid == null) {
            xid = CoordinationXid.lookupOrCreate(getContext().getIdentifier());
        }
        return xid;
    
public com.sun.xml.ws.tx.coordinator.RegistrantgetRegistrant(java.lang.String id)
Get the registrant with the specified id or null if it does not exist.

param
id the registrant id
return
the Registrant object or null if the id does not exist

        Registrant result = super.getRegistrant(id);

        // check subordinate participants
        if (result == null && rootVolatileParticipant != null &&
            rootVolatileParticipant.getIdValue().equals(id)) {
                result = rootVolatileParticipant;
        }
        if (result == null && rootDurableParticipant != null &&
            rootDurableParticipant.getIdValue().equals(id)) {
                result = rootDurableParticipant;
        }

        return result;
    
private javax.resource.spi.XATerminatorgetXATerminator()


       
        if (xaTerminator == null) {
            xaTerminator = importTm.getXATerminator();
        }
        return xaTerminator;
    
public booleanhasOutstandingParticipants()

        return rootDurableParticipant != null || rootVolatileParticipant != null || super.hasOutstandingParticipants();
    
public booleanisSubordinateCoordinator()

        return true;
    
public intprepare(javax.transaction.xa.Xid xid)
Synchronous prepare request from subordinate coordinator.

Prepare this coordinator and return result of preparation.

        if (logger.isLogging(Level.FINER)) {
            logger.entering("XAResource_prepare(xid=" + xid + ")");
        }
        int result = 0;
        result = XA_OK;
        // TODO: Prepare AT Subordinate Coordinator state so it can be recovered in case of failure.
        //       Only durable participants need to be recoverable.

        // This coordinator prepares when root ws-at coordinator sends a prepare to this subordinate
        // coordinator that is a participant to that coordinator.
        if (logger.isLogging(Level.FINER)) {
            logger.exiting("XAResource_prepare", result);
        }
        return result;
    
protected booleanregisterWithDurableParent()

        boolean result = false;
        if (rootDurableParticipant == null) {
            if (logger.isLogging(Level.FINE)) {
                logger.fine("ATSubCoordinator.registerWithDurableParent", "register durable2PC with coordId:" +
                        getIdValue());
            }
            rootDurableParticipant = new ATParticipant(this, new DurableParticipant());
            try {
                rootDurableParticipant.register();
                result = true;
            } catch (Exception e) {
                // TODO: ROBUSTNESS retry register when it fails 
                logger.severe("registerWithDurableParent", LocalizationMessages.REG_WITH_DURABLE_FAILED_0022(getCoordIdPartId(rootDurableParticipant)));
            }
        }
        return result;
    
public booleanregisterWithRootRegistrationService(com.sun.xml.ws.tx.coordinator.Registrant participant)
Represent all volatile and durable participants for this subordinate coordinator through two special participants of SubordinateCoordinator. They are the only participants that parent coordinator is aware of.

        // Note: intended instance comparision, not object comparison
        if (participant == rootVolatileParticipant || participant == rootDurableParticipant) {
            return true;
        } else {
            return super.registerWithRootRegistrationService(participant);
        }
    
protected voidregisterWithVolatileParent()

        if (rootVolatileParticipant == null) {
            if (logger.isLogging(Level.FINE)) {
                logger.fine("ATSubCoordinator.registerWithVolatileParent", "register volatile2PC with coordId:" +
                        getIdValue());
            }
            rootVolatileParticipant = new ATParticipant(this, new VolatileParticipant());
            rootVolatileParticipant.register();
        }
    
public voidremoveRegistrant(java.lang.String id)

        forget(id);
    
public voidrollback(javax.transaction.xa.Xid xid)

        if (logger.isLogging(Level.FINER)) {
            logger.entering("XAResource_rollback(xid=" + xid + ")");
        }
        // TODO: Rollack AT Subordinate Coordinator state.
        //       Only durable participants require to be rolled back.

        // This coordinator rolls back when root ws-at coordinator sends a abort to this subordinate
        // coordinator that is a participant to that coordinator.
        if (logger.isLogging(Level.FINER)) {
            logger.exiting("XAResource_rollback");
        }
    
public voidsetTransaction(javax.transaction.Transaction txn)

        super.setTransaction(txn);
        if (txn == null) {
            xaTerminator = null;
        } else if (xaTerminator == null) {
            xaTerminator = importTm.getXATerminator();
        }