Search in sources :

Example 1 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.

the class TransactionLog method getIds.

/**
 * Get a list object ids for a given object type
 *
 * @param ids holder for the returned uids
 * @param objectType The type of object to search in the recoveryStore for
 * @return all objects of the given type
 * @throws ObjectStoreException the recoveryStore implementation was unable retrieve all types of objects
 */
public Collection<Uid> getIds(Collection<Uid> ids, String objectType) throws ObjectStoreException {
    if (ids == null)
        ids = new ArrayList<Uid>();
    InputObjectState types = new InputObjectState();
    if (recoveryStore.allTypes(types)) {
        String theName;
        try {
            boolean endOfList = false;
            while (!endOfList) {
                theName = types.unpackString();
                if (theName.compareTo("") == 0)
                    endOfList = true;
                else {
                    if (objectType != null && !theName.equals(objectType))
                        continue;
                    InputObjectState uids = new InputObjectState();
                    if (recoveryStore.allObjUids(theName, uids)) {
                        Uid theUid = new Uid(Uid.nullUid());
                        try {
                            boolean endOfUids = false;
                            while (!endOfUids) {
                                theUid = UidHelper.unpackFrom(uids);
                                if (theUid.equals(Uid.nullUid()))
                                    endOfUids = true;
                                else
                                    ids.add(theUid);
                            }
                        } catch (Exception e) {
                        // end of uids!
                        }
                    }
                    System.out.println();
                }
            }
        } catch (Exception e) {
            System.err.println(e);
        // end of list!
        }
    }
    return ids;
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) Uid(com.arjuna.ats.arjuna.common.Uid) ArrayList(java.util.ArrayList) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException)

Example 2 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.

the class BaseTest method readObjectStoreRecord.

protected static OSRecordHolder readObjectStoreRecord(String type) {
    try {
        RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
        InputObjectState states = new InputObjectState();
        if (recoveryStore.allObjUids(type, states) && states.notempty()) {
            Uid uid = UidHelper.unpackFrom(states);
            if (uid.notEquals(Uid.nullUid())) {
                InputObjectState ios = recoveryStore.read_committed(uid, type);
                return new OSRecordHolder(uid, type, ios);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) Uid(com.arjuna.ats.arjuna.common.Uid) RecoveryStore(com.arjuna.ats.arjuna.objectstore.RecoveryStore) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) HttpResponseException(org.jboss.jbossts.star.provider.HttpResponseException)

Example 3 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.

the class BaseTest method clearObjectStore.

private static void clearObjectStore(String type) {
    try {
        RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
        InputObjectState states = new InputObjectState();
        if (recoveryStore.allObjUids(type, states) && states.notempty()) {
            boolean finished = false;
            do {
                Uid uid = UidHelper.unpackFrom(states);
                if (uid.notEquals(Uid.nullUid())) {
                    recoveryStore.remove_committed(uid, type);
                } else {
                    finished = true;
                }
            } while (!finished);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) Uid(com.arjuna.ats.arjuna.common.Uid) RecoveryStore(com.arjuna.ats.arjuna.objectstore.RecoveryStore) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) HttpResponseException(org.jboss.jbossts.star.provider.HttpResponseException)

Example 4 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.

the class RecoveryManager method recoverParticipants.

private void recoverParticipants() {
    if (ParticipantsManagerFactory.getInstance().getBaseUrl() != null) {
        final RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
        final InputObjectState states = new InputObjectState();
        try {
            if (recoveryStore.allObjUids(PARTICIPANT_INFORMATION_RECORD_TYPE, states)) {
                Uid uid;
                while ((uid = UidHelper.unpackFrom(states)).notEquals(Uid.nullUid())) {
                    final ParticipantInformation participantInformation = recreateParticipantInformation(recoveryStore, uid);
                    if (participantInformation != null) {
                        ParticipantsContainer.getInstance().addParticipantInformation(participantInformation.getId(), participantInformation);
                    }
                }
            }
        } catch (ObjectStoreException e) {
            LOG.warn(e.getMessage(), e);
        } catch (IOException e) {
            LOG.warn(e.getMessage(), e);
        }
    } else {
        LOG.warn("Participants cannot be loaded from the object store, because base URL was not set.");
    }
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) Uid(com.arjuna.ats.arjuna.common.Uid) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) IOException(java.io.IOException) RecoveryStore(com.arjuna.ats.arjuna.objectstore.RecoveryStore)

Example 5 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.

the class RecoveryManager method recreateParticipantInformation.

private ParticipantInformation recreateParticipantInformation(final RecoveryStore recoveryStore, final Uid uid) throws ObjectStoreException, IOException {
    final InputObjectState inputObjectState = recoveryStore.read_committed(uid, PARTICIPANT_INFORMATION_RECORD_TYPE);
    final String id = inputObjectState.unpackString();
    if (ParticipantsContainer.getInstance().getParticipantInformation(id) != null) {
        // Participant is already loaded.
        return null;
    }
    final String applicationId = inputObjectState.unpackString();
    if (!deserializers.containsKey(applicationId)) {
        // There is no appropriate deserializer.
        return null;
    }
    final String status = inputObjectState.unpackString();
    final String recoveryUrl = inputObjectState.unpackString();
    final Participant participant = recreateParticipant(inputObjectState, applicationId);
    if (participant == null) {
        // Deserializer failed to recreate participant.
        return null;
    }
    final ParticipantInformation participantInformation = new ParticipantInformation(id, applicationId, recoveryUrl, participant, status);
    if (!synchronizeParticipantUrlWithCoordinator(participantInformation)) {
        try {
            participant.rollback();
            removeParticipantInformation(participantInformation);
        // TODO is it OK to leave participant not rolled back in case of Exception?
        } catch (HeuristicException e) {
            LOG.warn(e.getMessage(), e);
        } catch (ParticipantException e) {
            LOG.warn(e.getMessage(), e);
        }
        return null;
    }
    return participantInformation;
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) HeuristicException(org.jboss.narayana.rest.integration.api.HeuristicException) Participant(org.jboss.narayana.rest.integration.api.Participant) PersistableParticipant(org.jboss.narayana.rest.integration.api.PersistableParticipant) ParticipantException(org.jboss.narayana.rest.integration.api.ParticipantException)

Aggregations

InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)133 Uid (com.arjuna.ats.arjuna.common.Uid)83 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)55 Test (org.junit.Test)47 ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)42 IOException (java.io.IOException)30 RecoveryStore (com.arjuna.ats.arjuna.objectstore.RecoveryStore)23 ObjectStoreEnvironmentBean (com.arjuna.ats.arjuna.common.ObjectStoreEnvironmentBean)17 XidImple (com.arjuna.ats.jta.xa.XidImple)9 XAException (javax.transaction.xa.XAException)9 ArrayList (java.util.ArrayList)8 ParticipantStore (com.arjuna.ats.arjuna.objectstore.ParticipantStore)7 Xid (javax.transaction.xa.Xid)6 SubordinateAtomicAction (com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.SubordinateAtomicAction)5 Date (java.util.Date)5 Vector (java.util.Vector)5 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)4 HashedActionStore (com.arjuna.ats.internal.arjuna.objectstore.HashedActionStore)4 NullActionStore (com.arjuna.ats.internal.arjuna.objectstore.NullActionStore)4 TransactionImple (com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple)4