Search in sources :

Example 1 with AbstractRecord

use of com.arjuna.ats.arjuna.coordinator.AbstractRecord in project narayana by jbosstm.

the class Transaction method findParticipant.

private RESTRecord findParticipant(String participantUrl) {
    if (pendingList != null) {
        RecordListIterator i = new RecordListIterator(pendingList);
        AbstractRecord r;
        while ((r = i.iterate()) != null) {
            if (r instanceof RESTRecord) {
                RESTRecord rr = (RESTRecord) r;
                if (rr.getParticipantURI().equals(participantUrl))
                    return rr;
            }
        }
    }
    return null;
}
Also used : RecordListIterator(com.arjuna.ats.arjuna.coordinator.RecordListIterator) AbstractRecord(com.arjuna.ats.arjuna.coordinator.AbstractRecord)

Example 2 with AbstractRecord

use of com.arjuna.ats.arjuna.coordinator.AbstractRecord in project narayana by jbosstm.

the class Transaction method findLRAParticipant.

private LRARecord findLRAParticipant(String participantUrl, boolean remove, RecordList list) {
    if (list != null) {
        RecordListIterator i = new RecordListIterator(list);
        AbstractRecord r;
        if (participantUrl.indexOf(',') != -1)
            participantUrl = LRARecord.extractCompensator(participantUrl);
        while ((r = i.iterate()) != null) {
            if (r instanceof LRARecord) {
                LRARecord rr = (LRARecord) r;
                // can't use == because this may be a recovery scenario
                if (rr.getCompensator().equals(participantUrl)) {
                    if (remove)
                        list.remove(rr);
                    return rr;
                }
            }
        }
    }
    return null;
}
Also used : RecordListIterator(com.arjuna.ats.arjuna.coordinator.RecordListIterator) AbstractRecord(com.arjuna.ats.arjuna.coordinator.AbstractRecord)

Example 3 with AbstractRecord

use of com.arjuna.ats.arjuna.coordinator.AbstractRecord in project narayana by jbosstm.

the class Transaction method save_list.

private boolean save_list(OutputObjectState os, int ot, RecordList list) {
    if (list != null && list.size() > 0) {
        AbstractRecord first, temp;
        first = temp = list.getFront();
        while (temp != null) {
            list.putRear(temp);
            if (!temp.doSave())
                return false;
            try {
                os.packInt(temp.typeIs());
                if (!temp.save_state(os, ot))
                    return false;
            } catch (IOException e) {
                return false;
            }
            temp = list.getFront();
            if (temp == first) {
                list.putFront(temp);
                temp = null;
            }
        }
    }
    try {
        os.packInt(RecordType.NONE_RECORD);
    } catch (IOException e) {
        return false;
    }
    return true;
}
Also used : AbstractRecord(com.arjuna.ats.arjuna.coordinator.AbstractRecord) IOException(java.io.IOException)

Example 4 with AbstractRecord

use of com.arjuna.ats.arjuna.coordinator.AbstractRecord in project narayana by jbosstm.

the class ActionBean method setStatus.

/**
 * Request a change in status of a participant. For example if a record has a
 * heuristic status then this method could be used to move it back into the
 * prepared state so that the recovery system can replay phase 2 of the
 * commitment protocol
 * @param logrec the record whose status is to be changed
 * @param newStatus the desired status
 * @return true if the status was changed
 */
public boolean setStatus(LogRecordWrapper logrec, ParticipantStatus newStatus) {
    ParticipantStatus lt = logrec.getListType();
    AbstractRecord targRecord = logrec.getRecord();
    RecordList oldList = ra.getRecords(lt);
    RecordList newList = ra.getRecords(newStatus);
    // move the record from currList to targList
    if (oldList.remove(targRecord)) {
        if (newList.insert(targRecord)) {
            if (lt.equals(ParticipantStatus.HEURISTIC)) {
                switch(newStatus) {
                    case FAILED:
                        ra.clearHeuristicDecision(TwoPhaseOutcome.FINISH_ERROR);
                        break;
                    case PENDING:
                        ra.clearHeuristicDecision(TwoPhaseOutcome.NOT_PREPARED);
                        break;
                    case PREPARED:
                        ra.clearHeuristicDecision(TwoPhaseOutcome.PREPARE_OK);
                        break;
                    case READONLY:
                        ra.clearHeuristicDecision(TwoPhaseOutcome.PREPARE_READONLY);
                        break;
                    default:
                        break;
                }
            }
            ra.doUpdateState();
            return true;
        }
    }
    return false;
}
Also used : RecordList(com.arjuna.ats.arjuna.coordinator.RecordList) AbstractRecord(com.arjuna.ats.arjuna.coordinator.AbstractRecord)

Example 5 with AbstractRecord

use of com.arjuna.ats.arjuna.coordinator.AbstractRecord in project narayana by jbosstm.

the class ArjunaTransactionImple method register_resource.

/**
 * Resources are only registered with the current transaction, whereas
 * subtransaction aware resources are registered with their parents when the
 * current transaction ends.
 */
public RecoveryCoordinator register_resource(Resource r) throws SystemException, Inactive {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ArjunaTransactionImple::register_resource ( " + r + " ) - called for " + get_uid());
    }
    if (r == null)
        throw new BAD_PARAM(0, CompletionStatus.COMPLETED_NO);
    currentStatus = determineStatus(this);
    if (currentStatus != Status.StatusActive) {
        if (jtsLogger.logger.isTraceEnabled()) {
            jtsLogger.logger.trace("ArjunaTransactionImple::register_resource - transaction not active: " + Utility.stringStatus(currentStatus));
        }
        if (currentStatus == Status.StatusMarkedRollback) {
            throw new TRANSACTION_ROLLEDBACK(ExceptionCodes.MARKED_ROLLEDBACK, CompletionStatus.COMPLETED_NO);
        } else
            throw new Inactive();
    }
    AbstractRecord corbaRec = null;
    BasicAction registerIn = this;
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ArjunaTransactionImple " + get_uid() + " ::register_resource: ");
    }
    // 
    // Creation of recovery coordinator (DBI)
    // 
    // 
    // Pack the params:
    // [0] = Transaction* this
    // 
    int index = 0;
    Object[] params = new Object[10];
    params[index++] = this;
    RecoveryCoordinator recoveryCoordinator = null;
    Uid recoveryCoordinatorUid = null;
    try {
        recoveryCoordinator = RecoveryCreator.createRecoveryCoordinator(r, params);
        if (recoveryCoordinator == null)
            throw new BAD_OPERATION("RecoveryCoordinator " + jtsLogger.i18NLogger.get_orbspecific_coordinator_rcnotcreated());
    } catch (NO_IMPLEMENT ex) {
        /*
			 * This is legal, and is meant to show that this ORB or
			 * configuration simply doesn't support crash recovery.
			 */
        recoveryCoordinator = null;
    } catch (SystemException e) {
        jtsLogger.i18NLogger.warn_orbspecific_coordinator_rccreate(get_uid(), e);
        try {
            rollback_only();
        } catch (Inactive ex1) {
        } catch (SystemException ex2) {
            jtsLogger.i18NLogger.warn_orbspecific_coordinator_rbofail("ArjunaTransactionImple.register_resource", get_uid(), ex2);
            throw ex2;
        }
        throw e;
    }
    if (recoveryCoordinator != null) {
        // 
        // We got a RecoveryCoordinator, so unpack the other return values:
        // [0] = RecoveryCoordinator Uid*
        // 
        index = 0;
        recoveryCoordinatorUid = (Uid) params[index++];
    } else {
        // 
        // We didn't get a RecoveryCoordinator, so we don't assume that
        // the other return values have been populated.
        // 
        recoveryCoordinatorUid = Uid.nullUid();
    }
    try {
        SubtransactionAwareResource staResource = org.omg.CosTransactions.SubtransactionAwareResourceHelper.narrow(r);
        if (staResource != null) {
            if (jtsLogger.logger.isTraceEnabled()) {
                jtsLogger.logger.trace("ArjunaTransactionImple::register_resource for " + get_uid() + " - subtransaction aware resource: YES");
            }
            /*
				 * If here the narrow was ok so we have a subtran aware
				 * resource.
				 */
            Coordinator coord = null;
            if (parentHandle != null) {
                /*
					 * If we are a SubTranResource then we get registered with
					 * the current transaction and its parents upon completion.
					 * The first parameter to the record indicates whether we
					 * should be propagated (registered) with the parent
					 * transaction.
					 */
                coord = parentHandle.get_coordinator();
            }
            corbaRec = createOTSRecord(true, r, coord, recoveryCoordinatorUid);
            coord = null;
            staResource = null;
        } else
            throw new BAD_PARAM(0, CompletionStatus.COMPLETED_NO);
    } catch (BAD_PARAM ex) {
        if (jtsLogger.logger.isTraceEnabled()) {
            jtsLogger.logger.trace("ArjunaTransactionImple::register_resource for " + get_uid() + " - subtransaction aware resource: NO");
        }
        if (jtsLogger.logger.isTraceEnabled()) {
            jtsLogger.logger.trace("ArjunaTransactionImple " + get_uid() + " ::register_resource: Simple resource - " + ex);
        }
        corbaRec = createOTSRecord(true, r, null, recoveryCoordinatorUid);
    } catch (Unavailable e1) {
        throw new Inactive();
    } catch (SystemException e2) {
        if (jtsLogger.logger.isTraceEnabled()) {
            jtsLogger.logger.trace("ArjunaTransactionImple::register_resource for " + get_uid() + " : catch (SystemException) - " + e2);
        }
        throw e2;
    } catch (Exception e3) {
        if (jtsLogger.logger.isTraceEnabled()) {
            jtsLogger.logger.trace("ArjunaTransactionImple::register_resource for " + get_uid() + " : catch (...) - " + e3);
        }
        throw new UNKNOWN(e3.toString(), ExceptionCodes.UNKNOWN_EXCEPTION, CompletionStatus.COMPLETED_NO);
    }
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ArjunaTransactionImple::register_resource for " + get_uid() + " : try end");
    }
    if (registerIn.add(corbaRec) != AddOutcome.AR_ADDED) {
        corbaRec = null;
        throw new INVALID_TRANSACTION(ExceptionCodes.ADD_FAILED, CompletionStatus.COMPLETED_NO);
    } else {
        if (jtsLogger.logger.isTraceEnabled()) {
            jtsLogger.logger.trace("ArjunaTransactionImple::register_resource for " + get_uid() + " : resource registered");
        }
    }
    return recoveryCoordinator;
}
Also used : NO_IMPLEMENT(org.omg.CORBA.NO_IMPLEMENT) SubtransactionAwareResource(org.omg.CosTransactions.SubtransactionAwareResource) BasicAction(com.arjuna.ats.arjuna.coordinator.BasicAction) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) BAD_PARAM(org.omg.CORBA.BAD_PARAM) OTSAbstractRecord(com.arjuna.ArjunaOTS.OTSAbstractRecord) AbstractRecord(com.arjuna.ats.arjuna.coordinator.AbstractRecord) UidCoordinator(com.arjuna.ArjunaOTS.UidCoordinator) RecoveryCoordinator(org.omg.CosTransactions.RecoveryCoordinator) Coordinator(org.omg.CosTransactions.Coordinator) SystemException(org.omg.CORBA.SystemException) SynchronizationUnavailable(org.omg.CosTransactions.SynchronizationUnavailable) SubtransactionsUnavailable(org.omg.CosTransactions.SubtransactionsUnavailable) Unavailable(org.omg.CosTransactions.Unavailable) Uid(com.arjuna.ats.arjuna.common.Uid) SystemException(org.omg.CORBA.SystemException) Inactive(org.omg.CosTransactions.Inactive) RecoveryCoordinator(org.omg.CosTransactions.RecoveryCoordinator) BAD_OPERATION(org.omg.CORBA.BAD_OPERATION) UNKNOWN(org.omg.CORBA.UNKNOWN) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK)

Aggregations

AbstractRecord (com.arjuna.ats.arjuna.coordinator.AbstractRecord)31 RecordListIterator (com.arjuna.ats.arjuna.coordinator.RecordListIterator)10 Coordinator (org.omg.CosTransactions.Coordinator)5 RecordTypeMap (com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap)4 OTSAbstractRecord (com.arjuna.ArjunaOTS.OTSAbstractRecord)3 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)3 Uid (com.arjuna.ats.arjuna.common.Uid)3 BasicAction (com.arjuna.ats.arjuna.coordinator.BasicAction)3 LastResourceRecord (com.arjuna.ats.internal.arjuna.abstractrecords.LastResourceRecord)3 BAD_PARAM (org.omg.CORBA.BAD_PARAM)3 UidCoordinator (com.arjuna.ArjunaOTS.UidCoordinator)2 IOException (java.io.IOException)2 Enumeration (java.util.Enumeration)2 Test (org.junit.Test)2 SystemException (org.omg.CORBA.SystemException)2 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)2 UNKNOWN (org.omg.CORBA.UNKNOWN)2 Inactive (org.omg.CosTransactions.Inactive)2 RecoveryCoordinator (org.omg.CosTransactions.RecoveryCoordinator)2 SubtransactionsUnavailable (org.omg.CosTransactions.SubtransactionsUnavailable)2