Search in sources :

Example 6 with NotPrepared

use of org.omg.CosTransactions.NotPrepared in project narayana by jbosstm.

the class JavaIdlRCDefaultServant method replay_completion.

public Status replay_completion(Resource res) throws SystemException, NotPrepared {
    if (jtsLogger.logger.isDebugEnabled()) {
        jtsLogger.logger.debug("JavaIdlRCDefaultServant::replay_completion)");
    }
    try {
        // Begin New
        org.omg.CORBA.Object obj = _ourOrb.resolve_initial_references("POACurrent");
        org.omg.PortableServer.Current poa_current = org.omg.PortableServer.CurrentHelper.narrow(obj);
        byte[] objectId = poa_current.get_object_id();
        // End New
        String objectIdString = new String(objectId);
        String poaName = poa_current.get_POA().the_name();
        if (objectIdString.startsWith(poaName)) {
            // strip off the POA name prefix from the object name - the remainder encodes our Uids
            int index = poaName.length();
            if (objectIdString.length() > index)
                index += 1;
            objectIdString = objectIdString.substring(index);
        }
        // convert that to the structured id
        RecoveryCoordinatorId recovCoId = RecoveryCoordinatorId.reconstruct(objectIdString);
        if (jtsLogger.logger.isDebugEnabled()) {
            jtsLogger.logger.debug("JavaIdlDefaultServant replay_completion for Id " + recovCoId);
        }
        // and do the real replay
        return GenericRecoveryCoordinator.replay_completion(recovCoId, res);
    }/**
     */
     catch (NotPrepared exp) {
        throw exp;
    }/**/
     catch (Exception ex) {
        jtsLogger.i18NLogger.warn_orbspecific_jacorb_recoverycoordinators_JacOrbRCDefaultServant_3(ex);
        return Status.StatusUnknown;
    }
}
Also used : RecoveryCoordinatorId(com.arjuna.ats.internal.jts.orbspecific.recovery.recoverycoordinators.RecoveryCoordinatorId) NotPrepared(org.omg.CosTransactions.NotPrepared) SystemException(org.omg.CORBA.SystemException)

Example 7 with NotPrepared

use of org.omg.CosTransactions.NotPrepared in project narayana by jbosstm.

the class JacOrbRCDefaultServant method replay_completion.

public Status replay_completion(Resource res) throws SystemException, NotPrepared {
    if (jtsLogger.logger.isDebugEnabled()) {
        jtsLogger.logger.debug("JacOrbDefaultServant::replay_completion)");
    }
    try {
        // Begin New
        org.omg.CORBA.Object obj = _ourOrb.resolve_initial_references("POACurrent");
        org.omg.PortableServer.Current poa_current = org.omg.PortableServer.CurrentHelper.narrow(obj);
        byte[] objectId = poa_current.get_object_id();
        // End New
        String objectIdString = new String(objectId, StandardCharsets.UTF_8);
        // convert that to the structured id
        RecoveryCoordinatorId recovCoId = RecoveryCoordinatorId.reconstruct(objectIdString);
        if (jtsLogger.logger.isDebugEnabled()) {
            jtsLogger.logger.debug("JacOrbDefaultServant replay_completion for Id " + recovCoId);
        }
        // and do the real replay
        return GenericRecoveryCoordinator.replay_completion(recovCoId, res);
    }/**
     */
     catch (NotPrepared exp) {
        throw exp;
    }/**/
     catch (Exception ex) {
        jtsLogger.i18NLogger.warn_orbspecific_jacorb_recoverycoordinators_JacOrbRCDefaultServant_3(ex);
        return Status.StatusUnknown;
    }
}
Also used : RecoveryCoordinatorId(com.arjuna.ats.internal.jts.orbspecific.recovery.recoverycoordinators.RecoveryCoordinatorId) NotPrepared(org.omg.CosTransactions.NotPrepared) SystemException(org.omg.CORBA.SystemException)

Example 8 with NotPrepared

use of org.omg.CosTransactions.NotPrepared in project narayana by jbosstm.

the class GenericRecoveryCoordinator method replay_completion.

/**
 * Respond to a replay_completion request for the RecoveryCoordinator
 * identified by parameter id.
 */
protected static Status replay_completion(RecoveryCoordinatorId id, Resource res) throws SystemException, NotPrepared {
    if (jtsLogger.logger.isDebugEnabled()) {
        jtsLogger.logger.debug("GenericRecoveryCoordinator(" + id._RCUid + ").replay_completion(" + (res != null ? "resource supplied)" : "null resource)"));
    }
    Status currentStatus = Status.StatusUnknown;
    /* 
	 * First check to see if the transaction is active by asking the 
	 * per-process contact.
	 * If alive, return the status reported by the
	 * transaction.  If not alive then try and recover the
	 * transaction from the intentions list.  
	 */
    boolean transactionActive = true;
    try {
        currentStatus = get_status(id._actionUid, id._originalProcessUid);
    } catch (Inactive e) {
        // original process is dead.
        transactionActive = false;
    }
    if (currentStatus == Status.StatusNoTransaction) {
        /*
	     * There is no intentions list, so the transaction either
	     * committed or rolled back. However, this routine is only
	     * ever called by replay_completion, which means that there
	     * is a resource (hopefully one which was participating in
	     * the transaction) that is in doubt as to the
	     * transaction's outcome. If the transaction had committed,
	     * then this resource would know of the outcome. Therefore,
	     * it must have rolled back!
	     */
        /*
	     * Unfortunately the last statement is wrong. There is a timing
	     * issue here: the resource recovery may be doing an upcall while
	     * the downcall (from coordinator recovery) is going on and
	     * removing the log. What can then happen is that a resource may
	     * see a commit folled by a rollback.
	     */
        currentStatus = Status.StatusRolledBack;
    }
    if (!transactionActive) {
        // original process is dead, so reasonable for us to try to
        // recover
        /*
	     * The RecoveredTransactionReplayer is a threaded object
	     * so we can get the status and return it while the
	     * replayer does the phase 2 commit in a new thread.  
	     */
        String tranType = ((id._isServerTransaction) ? ServerTransaction.typeName() : ArjunaTransactionImple.typeName());
        try {
            if (id._isServerTransaction && (StoreManager.getRecoveryStore().currentState(id._actionUid, ServerTransaction.typeName() + "/JCA") != StateStatus.OS_UNKNOWN)) {
                tranType = tranType + "/JCA";
            }
        } catch (ObjectStoreException e) {
        // Can't read store
        }
        com.arjuna.ats.internal.jts.recovery.transactions.RecoveredTransactionReplayer replayer = new com.arjuna.ats.internal.jts.recovery.transactions.RecoveredTransactionReplayer(id._actionUid, tranType);
        // this will cause the activatation attempt
        currentStatus = replayer.getStatus();
        if ((replayer.getRecoveryStatus() != com.arjuna.ats.internal.jts.recovery.transactions.RecoveryStatus.ACTIVATE_FAILED) && (res != null)) {
            if (jtsLogger.logger.isDebugEnabled()) {
                jtsLogger.logger.debug("GenericRecoveryCoordinator - swapping Resource for RC " + id._RCUid);
            }
            replayer.swapResource(id._RCUid, res);
        }
        if (replayer.getRecoveryStatus() != com.arjuna.ats.internal.jts.recovery.transactions.RecoveryStatus.ACTIVATE_FAILED) {
            replayer.replayPhase2();
        } else {
            replayer.tidyup();
            /*
		 * The transaction didn't activate so we have a
		 * rollback situation but we can't rollback the
		 * resource that we have been given through the
		 * intentions list but we can issue rollback
		 * directly. This is configurable through the System
		 * properties.
		 */
            currentStatus = Status.StatusRolledBack;
        }
    }
    if (currentStatus == Status.StatusRolledBack) {
        if (_issueRecoveryRollback) {
            ResourceCompletor resourceCompletor = new ResourceCompletor(res, ResourceCompletor.ROLLBACK);
            resourceCompletor.start();
        }
    }
    if (currentStatus == Status.StatusActive)
        throw new NotPrepared();
    return currentStatus;
}
Also used : StateStatus(com.arjuna.ats.arjuna.objectstore.StateStatus) Status(org.omg.CosTransactions.Status) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) ResourceCompletor(com.arjuna.ats.internal.jts.recovery.recoverycoordinators.ResourceCompletor) NotPrepared(org.omg.CosTransactions.NotPrepared) Inactive(org.omg.CosTransactions.Inactive)

Example 9 with NotPrepared

use of org.omg.CosTransactions.NotPrepared in project narayana by jbosstm.

the class RecoveredServerTransaction method getStatusFromParent.

private Status getStatusFromParent() {
    org.omg.CosTransactions.Status theStatus = org.omg.CosTransactions.Status.StatusUnknown;
    // This variable is applied with Orbix
    int not_exist_count;
    if ((super._recoveryCoordinator != null) && (get_status() == org.omg.CosTransactions.Status.StatusPrepared)) {
        ServerControl sc = new ServerControl((ServerTransaction) this);
        ServerRecoveryTopLevelAction tla = new ServerRecoveryTopLevelAction(sc);
        if (tla.valid()) {
            try {
                theStatus = super._recoveryCoordinator.replay_completion(tla.getReference());
                if (jtsLogger.logger.isDebugEnabled()) {
                    jtsLogger.logger.debug("RecoveredServerTransaction.getStatusFromParent - replay_completion status = " + Utility.stringStatus(theStatus));
                }
            } catch (TRANSIENT ex_trans) {
                /*
                     * A failure that might not occur again if the request is retried. Not definite.
                     */
                jtsLogger.i18NLogger.warn_recovery_transactions_RecoveredServerTransaction_10(get_uid());
                theStatus = Status.StatusUnknown;
            }// What here what should be done for Orbix2000
             catch (OBJECT_NOT_EXIST ex) {
                // i believe this state should be notran - ots explicitly
                // objnotexist is
                // rollback
                theStatus = org.omg.CosTransactions.Status.StatusRolledBack;
                if (jtsLogger.logger.isDebugEnabled()) {
                    jtsLogger.logger.debug("RecoveredServerTransaction.getStatusFromParent -" + " replay_completion got object_not_exist = " + Utility.stringStatus(theStatus));
                }
            } catch (NotPrepared ex1) {
                jtsLogger.i18NLogger.warn_recovery_transactions_RecoveredServerTransaction_12();
                theStatus = Status.StatusActive;
            } catch (Exception e) {
                // Unknown error, so better to do nothing at this stage.
                jtsLogger.i18NLogger.warn_recovery_transactions_RecoveredServerTransaction_13(e);
            }
        } else {
            jtsLogger.i18NLogger.warn_recovery_transactions_RecoveredServerTransaction_14(get_uid());
        }
        // Make sure we "delete" these objects when we are finished
        // with them or there will be a memory leak. If they are deleted
        // "early", and the root coordinator needs them then it will find
        // them unavailable, and will have to retry recovery later.
        sc = null;
        tla = null;
    } else {
        if (jtsLogger.logger.isDebugEnabled()) {
            jtsLogger.logger.debug("RecoveredServerTransaction:getStatusFromParent - " + "no recovcoord or status not prepared");
        }
    }
    return theStatus;
}
Also used : ServerControl(com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl) OBJECT_NOT_EXIST(org.omg.CORBA.OBJECT_NOT_EXIST) Status(org.omg.CosTransactions.Status) ServerRecoveryTopLevelAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerRecoveryTopLevelAction) TRANSIENT(org.omg.CORBA.TRANSIENT) NotPrepared(org.omg.CosTransactions.NotPrepared) SystemException(org.omg.CORBA.SystemException) IOException(java.io.IOException) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException)

Example 10 with NotPrepared

use of org.omg.CosTransactions.NotPrepared in project narayana by jbosstm.

the class RCTest method test.

@Test
public void test() {
    boolean shouldCommit = true;
    boolean passed = false;
    Coordinator coord = null;
    ORB myORB = null;
    RootOA myOA = null;
    try {
        myORB = ORB.getInstance("test");
        myOA = OA.getRootOA(myORB);
        myORB.initORB(new String[] {}, null);
        myOA.initOA();
        ORBManager.setORB(myORB);
        ORBManager.setPOA(myOA);
        CurrentImple current = OTSImpleManager.current();
        AtomicResource aImpl = new AtomicResource(shouldCommit);
        Resource atomicObject = aImpl.getReference();
        System.out.println("beginning top-level transaction.");
        current.begin();
        Control myControl = current.get_control();
        assertNotNull(myControl);
        System.out.println("getting coordinator");
        coord = myControl.get_coordinator();
        myControl = null;
        System.out.println("registering resources.");
        RecoveryCoordinator rc = null;
        try {
            rc = coord.register_resource(atomicObject);
        } catch (Exception ex) {
            fail("Failed to register resources: " + ex);
            ex.printStackTrace();
        }
        if (rc == null)
            System.out.println("No recovery coordinator reference.");
        else {
            Status s = Status.StatusUnknown;
            try {
                System.out.println("Attempting to use recovery coordinator.");
                s = rc.replay_completion(atomicObject);
            } catch (NotPrepared e) {
                s = Status.StatusActive;
            } catch (Exception ex) {
                fail("Caught: " + ex);
                ex.printStackTrace();
            }
            System.out.println("Got: " + com.arjuna.ats.jts.utils.Utility.stringStatus(s));
            if (s == Status.StatusActive)
                passed = true;
        }
        System.out.println("committing top-level transaction.");
        if (shouldCommit)
            current.commit(true);
        else
            current.rollback();
        if (rc == null)
            System.out.println("No recovery coordinator reference.");
        else {
            Status s = Status.StatusUnknown;
            try {
                System.out.println("Attempting to use recovery coordinator.");
                s = rc.replay_completion(atomicObject);
            } catch (NotPrepared e) {
                s = Status.StatusActive;
            } catch (Exception ex) {
                fail("Caught: " + ex);
            }
            System.out.println("Got: " + com.arjuna.ats.jts.utils.Utility.stringStatus(s));
            if (passed && (s == Status.StatusRolledBack))
                passed = true;
            else
                passed = false;
        }
    } catch (TRANSACTION_ROLLEDBACK e1) {
        System.out.println("\nTransaction RolledBack exception");
    } catch (HeuristicMixed e2) {
        System.out.println("\nTransaction HeuristicMixed exception");
    } catch (HeuristicHazard e3) {
        System.out.println("\nTransaction HeuristicHazard exception");
    } catch (Exception e4) {
        System.out.println("Caught unexpected exception: " + e4);
    }
    System.out.println("Trying to determing final transaction outcome.");
    org.omg.CosTransactions.Status status = Status.StatusUnknown;
    try {
        if (coord != null) {
            status = coord.get_status();
            coord = null;
        } else
            System.out.println("\nCould not determine action status.");
    } catch (SystemException ex1) {
    // assume invalid reference - tx may have been garbage collected
    } catch (Exception e5) {
        System.out.println("Caught unexpected exception:" + e5);
    }
    System.out.println("\nFinal action status: " + com.arjuna.ats.jts.utils.Utility.stringStatus(status));
    assertTrue(passed);
    myOA.destroy();
    myORB.shutdown();
}
Also used : Status(org.omg.CosTransactions.Status) AtomicResource(com.hp.mwtests.ts.jts.orbspecific.resources.AtomicResource) Resource(org.omg.CosTransactions.Resource) RootOA(com.arjuna.orbportability.RootOA) AtomicResource(com.hp.mwtests.ts.jts.orbspecific.resources.AtomicResource) RecoveryCoordinator(org.omg.CosTransactions.RecoveryCoordinator) Coordinator(org.omg.CosTransactions.Coordinator) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) SystemException(org.omg.CORBA.SystemException) NotPrepared(org.omg.CosTransactions.NotPrepared) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard) Control(org.omg.CosTransactions.Control) SystemException(org.omg.CORBA.SystemException) Status(org.omg.CosTransactions.Status) RecoveryCoordinator(org.omg.CosTransactions.RecoveryCoordinator) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) HeuristicMixed(org.omg.CosTransactions.HeuristicMixed) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Aggregations

NotPrepared (org.omg.CosTransactions.NotPrepared)10 SystemException (org.omg.CORBA.SystemException)7 Status (org.omg.CosTransactions.Status)4 ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)3 RecoveryCoordinatorId (com.arjuna.ats.internal.jts.orbspecific.recovery.recoverycoordinators.RecoveryCoordinatorId)3 HeuristicHazard (org.omg.CosTransactions.HeuristicHazard)3 HeuristicMixed (org.omg.CosTransactions.HeuristicMixed)3 StateStatus (com.arjuna.ats.arjuna.objectstore.StateStatus)2 ServerControl (com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl)2 ServerRecoveryTopLevelAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerRecoveryTopLevelAction)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 OBJECT_NOT_EXIST (org.omg.CORBA.OBJECT_NOT_EXIST)2 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)2 TRANSIENT (org.omg.CORBA.TRANSIENT)2 HeuristicRollback (org.omg.CosTransactions.HeuristicRollback)2 Uid (com.arjuna.ats.arjuna.common.Uid)1 XAResourceRecord (com.arjuna.ats.internal.jta.resources.jts.orbspecific.XAResourceRecord)1 TransactionImple (com.arjuna.ats.internal.jta.transaction.jts.TransactionImple)1 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)1