Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.arjuna.wst11.stub;
  
  import com.arjuna.wst.*;
  
 
A durable participant registered on behalf of an interposed WS-AT coordinator in order to ensure that durable participants in the subtransaction prepared, committed and aborted at the right time.
 
 {
    
normal constructor used when the subordinate coordinator is registered as a durable participant with its parent coordinator.

Parameters:
coordinator
 
     {
         this. = coordinator;
         this. = coordinator.get_uid().stringForm();
         this. = false;
     }

    
empty constructor for use only during recovery
 
     public SubordinateDurable2PCStub()
     {
         this. = null;
         this. = null;
         this. = true;
     }

    
This will be called when the parent coordinator is preparing its durable participants and should ensure that the interposed cooordinator does the same.

Returns:
the Vote returned by the subordinate coordinator.
Throws:
com.arjuna.wst.WrongStateException if the subordinate coordinator does the same
com.arjuna.wst.SystemException if the subordinate coordinator does the same
 
     public Vote prepare() throws WrongStateExceptionSystemException {
         switch (.prepare())
         {
             case .:
                 return new Prepared();
             case .:
                 return new ReadOnly();
             case .:
             default:
                 return new Aborted();
         }
     }

    
this will be called when the parent coordinator commits its durable participants and should ensure that the interposed cooordinator does the same

 
 
     public void commit() throws WrongStateExceptionSystemException {
         if (!isRecovered()) {
             .commit();
         } else {
             XTSATRecoveryManager recoveryManager = null;
             boolean isRecoveryScanStarted = false;
             if ( == null) {
                 // try fetching coordinator from the recovery manager
                 recoveryManager = XTSATRecoveryManager.getRecoveryManager();
                 // check whether recovery has started before we check for the presence
                 // of the subordinate coordinator
                 isRecoveryScanStarted = recoveryManager.isSubordinateCoordinatorRecoveryStarted();
                  = SubordinateATCoordinator.getRecoveredCoordinator();
             }
             if ( == null) {
                 // hmm, still null -- see if we have finished recovery scanning
                 if (!isRecoveryScanStarted) {
                     // the subtransaction may still be waiting to be resolved
                     // throw an exception causing the commit to be retried later
                     throw new SystemException();
                 }
                 // ok we have no transaction to commit so assume we already committed it and
                 // return without error
             } else if(!.isActivated()) {
                 // the transaction was logged but has not yet been recovered successfully
                 // throw an exception causing the commit to be retried later
                     throw new SystemException();
             } else {
                int status = .status();
                if (status == . || status == .) {
                    // ok, the commit process was not previously initiated so start it now
                    .commit();
                    SubordinateATCoordinator.removeActiveProxy();
                    status = .status();
                }
                // check that we are not still committing because of a comms timeout
                if (status == .) {
                    // throw an exception causing the commit to be retried later
                    throw new SystemException();
                }
            }
        }
    }

    
this will be called when the parent coordinator rolls back its durable participants and should ensure that the interposed cooordinator does the same

    public void rollback() throws WrongStateExceptionSystemException {
        if (!isRecovered()) {
            .rollback();
        } else {
            // first check whether crashed coordinators have been recovered
            XTSATRecoveryManager recoveryManager = XTSATRecoveryManager.getRecoveryManager();
            boolean isRecoveryScanStarted = recoveryManager.isSubordinateCoordinatorRecoveryStarted();
            // now look for a subordinate coordinator with the right id
             = SubordinateATCoordinator.getRecoveredCoordinator();
            if ( == null) {
                if (!isRecoveryScanStarted) {
                    // the subtransaction may still be waiting to be resolved
                    // throw an exception causing the rollback to be retried later
                    throw new SystemException();
                }
            } else if(!.isActivated()) {
                // the transaction was logged but has not yet been recovered successfully
                // throw an exception causing the rollback to be retried later
                    throw new SystemException();
            } else {
                int status = .status();
                if ((status ==  .) ||
                        (status == .) ||
                        (status == .) ||
                        (status == .)) {
                    // ok, the rollback process was not previously initiated so start it now
                    .rollback();
                    SubordinateATCoordinator.removeActiveProxy();
                    status = .status();
                }
            }
        }
    }

    
this should never get called

    public void unknown() throws SystemException {
        .unknown();
    }

    
this should never get called

    public void error() throws SystemException {
        .error();
    }

    
Save the state of the particpant to the specified input object stream.

Parameters:
oos The output output stream.
Returns:
true if persisted, false otherwise.
    public boolean saveState(OutputObjectState oos) {
        // we need to save the id of the subordinate coordinator so we can identify it again
        // when we are recreated
        try {
            oos.packString();
            return true;
        } catch (IOException e) {
            return false;
        }
    }

    
Restore the state of the particpant from the specified input object stream.

Parameters:
ios The Input object stream.
Returns:
true if restored, false otherwise.
    public boolean restoreState(InputObjectState ios) {
        // restore the subordinate coordinator id so we can check to ensure it has been committed
        try {
             = ios.unpackString();
            SubordinateATCoordinator.addActiveProxy();
            return true;
        } catch (IOException e) {
            return false;
        }
    }

    
test if this participant is recovered
    public boolean isRecovered()
    {
        return ;
    }

    
the interposed coordinator
    private SubordinateATCoordinator coordinator;

    
the interposed coordinator's id
    private String coordinatorId;

    
a flag indicating whether this participant has been recovered
    private boolean recovered;

    
this participant implements the PersistableATarticipant interface so it can save its state. recovery is managed by an XTS recovery module

Returns:
Throws:
java.lang.Exception
    public byte[] getRecoveryState() throws Exception {
        OutputObjectState oos = new OutputObjectState();
        oos.packString(this.getClass().getName());
        this.saveState(oos);
        return oos.buffer();
    }
New to GrepCode? Check out our FAQ X