Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.arjuna.wst11.stub;
  
  import com.arjuna.wst.*;
 
A coordinator completion participant registered on behalf of an interposed WS-BA coordinator in order to ensure that durable participants in the interposed transaction are completed, closed or cancelled when requested from the parent transaction.
 
 {
     {
         this. = coordinator;
         this. = coordinator.get_uid().stringForm();
         this. = false;
         this. = null;
     }
 
     {
         this. = null;
         this. = null;
         this. = true;
         this. = null;
     }

    
set the participant manager for this stub. this cannot be supplied to the constructor because it refers to the engine which drives this participant and the engine can only be created once the participant has been created. it is needed in order to be able to send a fail upward to the parent coordinator during complete processing. it is not needed during close or compensate processing which is ok because we cannot save and restore it anyway.

Parameters:
manager the manager for this participant
 
     public void setManager(BAParticipantManager manager)
     {
         this. = manager;
     }
 
     public void complete() throws WrongStateExceptionSystemException {
         if (!) {
             // the coordinator will send complete to all participants and then
             // also run phase one commit. the former may throw an exception.
             // if the latter succeeds the tx state will be COMMITTING whereas
             // if it fails it will be ABORTED.
             try {
                 .complete();
             } catch (com.arjuna.mw.wsas.exceptions.WrongStateException wse) {
                 throw new WrongStateException(wse.getMessage());
             } catch (com.arjuna.mw.wsas.exceptions.SystemException se) {
                 throw new SystemException(se.getMessage());
             }
             // if status is COMMITTING then we return allowing the participant to be logged
             // if status is ABORTED then the participant must fail avoiding any logging
 
             if (.status() == .) {
             } else {
                 // null out the manager so we don't attempt to save it to the log
                  = null;
             }
         } else {
             // we should never get asked to complete a recovered activity
             throw new WrongStateException();
         }
     }
 
     public void close() throws WrongStateExceptionSystemException {
         if (!) {
             int result;
             try {
                 result = .close();
             } catch (com.arjuna.mw.wsas.exceptions.SystemException se) {
                 throw new SystemException(se.getMessage());
             }
             if (result != .) {
                 throw new SystemException("failed to close subordinate transaction " + );
             }
         } else {
             XTSBARecoveryManager recoveryManager = null;
             boolean isRecoveryScanStarted = false;
             if ( == null) {
                 // try fetching coordinator from the recovery manager
                recoveryManager = XTSBARecoveryManager.getRecoveryManager();
                // check whether recovery has started before we check for the presence
                // of the subordinate coordinator
                isRecoveryScanStarted = recoveryManager.isSubordinateCoordinatorRecoveryStarted();
                 = SubordinateBACoordinator.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
                    try {
                        .close();
                        SubordinateBACoordinator.removeActiveProxy();
                    } catch (com.arjuna.mw.wsas.exceptions.SystemException e) {
                        // throw an exception causing the commit to be retried later
                        throw new SystemException();
                    }
                    status = .status();
                }
                // TODO -- check if this is really necessary given the catch above?
                // 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();
                }
            }
        }
    }
    public void cancel() throws FaultedExceptionWrongStateExceptionSystemException {
        if (!) {
            int result = .cancel();
            if (result != .) {
                throw new FaultedException("failed to compensate subordinate transaction " + );
            }
        } else {
            XTSBARecoveryManager recoveryManager = null;
            boolean isRecoveryScanStarted = false;
            if ( == null) {
                // try fetching coordinator from the recovery manager
                recoveryManager = XTSBARecoveryManager.getRecoveryManager();
                // check whether recovery has started before we check for the presence
                // of the subordinate coordinator
                isRecoveryScanStarted = recoveryManager.isSubordinateCoordinatorRecoveryStarted();
                 = SubordinateBACoordinator.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
                    .cancel();
                    SubordinateBACoordinator.removeActiveProxy();
                }
                // 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();
                } else if (status != .) {
                    throw new FaultedException();
                }
            }
        }
    }
    public void compensate() throws FaultedExceptionWrongStateExceptionSystemException {
        if (!) {
            int result = .cancel();
            // test result and throw a SystemException if the compensate was delayed
        } else {
            XTSBARecoveryManager recoveryManager = null;
            boolean isRecoveryScanStarted = false;
            if ( == null) {
                // try fetching coordinator from the recovery manager
                recoveryManager = XTSBARecoveryManager.getRecoveryManager();
                // check whether recovery has started before we check for the presence
                // of the subordinate coordinator
                isRecoveryScanStarted = recoveryManager.isSubordinateCoordinatorRecoveryStarted();
                 = SubordinateBACoordinator.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
                    .cancel();
                    SubordinateBACoordinator.removeActiveProxy();
                    status = .status();
                }
                // TODO -- check if this is really necessary given the catch above?
                // 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();
                } else if (status != .) {
                    throw new FaultedException();
                }
            }
        }
    }

    
this should never get called

    public String status() throws SystemException
    {
        return null;
    }

    
this should never get called

    public void unknown() throws SystemException
    {
    }

    
this should never get called

    public void error() throws SystemException
    {
    }

    
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();
            SubordinateBACoordinator.addActiveProxy();
            return true;
        } catch (IOException e) {
            return false;
        }
    }
    /*
     * this participant implements the PersistableBAParticipant interface so it can save its state.
     * recovery is managed by an XTS recovery module
     * @return
     * @throws Exception
     */
    public byte[] getRecoveryState() throws Exception {
        OutputObjectState oos = new OutputObjectState();
        oos.packString(this.getClass().getName());
        this.saveState(oos);
        return oos.buffer();
    }
    private String coordinatorId;
    private boolean recovered;
    private BAParticipantManager manager;
New to GrepCode? Check out our FAQ X