Search in sources :

Example 1 with PersistableParticipant

use of com.arjuna.wst.PersistableParticipant in project narayana by jbosstm.

the class PersistableParticipantHelper method save_state.

/**
 * Save the resource state.
 * @param os The output object stream.
 * @param resource The resource to persist.
 * @return true if successful, false otherwise.
 */
public static boolean save_state(final OutputObjectState os, final Object resource) {
    if (resource != null) {
        try {
            if (resource instanceof Serializable) {
                os.packBoolean(true);
                final ByteArrayOutputStream baos = new ByteArrayOutputStream();
                final ObjectOutputStream oos = new ObjectOutputStream(baos);
                oos.writeObject(resource);
                oos.flush();
                os.packBytes(baos.toByteArray());
            } else if (resource instanceof PersistableParticipant) {
                final PersistableParticipant participant = (PersistableParticipant) resource;
                os.packBoolean(false);
                os.packString(resource.getClass().getName());
                participant.saveState(os);
            } else {
                wstxLogger.i18NLogger.error_mwlabs_wst_util_PersistableParticipantHelper_1();
                return false;
            }
            return true;
        } catch (final Throwable th) {
            wstxLogger.i18NLogger.error_mwlabs_wst_util_PersistableParticipantHelper_2(th);
            return false;
        }
    } else
        return false;
}
Also used : Serializable(java.io.Serializable) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) PersistableParticipant(com.arjuna.wst.PersistableParticipant)

Example 2 with PersistableParticipant

use of com.arjuna.wst.PersistableParticipant in project narayana by jbosstm.

the class PersistableParticipantHelper method restore_state.

/**
 * Restore the resource state.
 * @param is The input object stream.
 * @return The resource if successful, null otherwise.
 */
public static Object restore_state(final InputObjectState ios) {
    try {
        final boolean serializable = ios.unpackBoolean();
        if (serializable) {
            final ByteArrayInputStream bais = new ByteArrayInputStream(ios.unpackBytes());
            final ObjectInputStream ois = new ObjectInputStream(bais);
            return ois.readObject();
        } else {
            final String className = ios.unpackString();
            // returns Class not instance
            final Class resourceClass = ClassLoaderHelper.forName(PersistableParticipantHelper.class, className);
            final Object resource = resourceClass.newInstance();
            ((PersistableParticipant) resource).restoreState(ios);
            return resource;
        }
    } catch (final Throwable th) {
        wstxLogger.i18NLogger.error_mwlabs_wst_util_PersistableParticipantHelper_3(th);
        return null;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInputStream(java.io.ObjectInputStream) PersistableParticipant(com.arjuna.wst.PersistableParticipant)

Example 3 with PersistableParticipant

use of com.arjuna.wst.PersistableParticipant in project narayana by jbosstm.

the class XTSBASubordinateRecoveryModule method recreateCoordinatorCompletionParticipant.

public BusinessAgreementWithCoordinatorCompletionParticipant recreateCoordinatorCompletionParticipant(String id, byte[] recoveryState) throws Exception {
    if (id.startsWith(SubordinateBACoordinator.PARTICIPANT_PREFIX)) {
        if (!id.endsWith("_CCP")) {
            // throw an exception because we don't expect participant completion participants at present
            throw new Exception("XTSBASubordinateRecoveryModule : invalid name for subordinate WS-BA coordinator coordinator completion participant participant " + id);
        }
        // ok, try to recreate the participant
        InputObjectState ios = new InputObjectState();
        ios.setBuffer(recoveryState);
        String className = ios.unpackString();
        Class participantClass = this.getClass().getClassLoader().loadClass(className);
        BusinessAgreementWithCoordinatorCompletionParticipant participant = (BusinessAgreementWithCoordinatorCompletionParticipant) participantClass.newInstance();
        ((PersistableParticipant) participant).restoreState(ios);
        return participant;
    }
    return null;
}
Also used : BusinessAgreementWithCoordinatorCompletionParticipant(com.arjuna.wst.BusinessAgreementWithCoordinatorCompletionParticipant) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) PersistableParticipant(com.arjuna.wst.PersistableParticipant)

Example 4 with PersistableParticipant

use of com.arjuna.wst.PersistableParticipant in project narayana by jbosstm.

the class XTSATSubordinateRecoveryModule method recreate.

public Durable2PCParticipant recreate(String id, byte[] recoveryState) throws Exception {
    if (id.startsWith(SubordinateATCoordinator.PARTICIPANT_PREFIX)) {
        InputObjectState ios = new InputObjectState();
        ios.setBuffer(recoveryState);
        String className = ios.unpackString();
        Class participantClass = this.getClass().getClassLoader().loadClass(className);
        Durable2PCParticipant participant = (Durable2PCParticipant) participantClass.newInstance();
        ((PersistableParticipant) participant).restoreState(ios);
        return participant;
    }
    return null;
}
Also used : Durable2PCParticipant(com.arjuna.wst.Durable2PCParticipant) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) PersistableParticipant(com.arjuna.wst.PersistableParticipant)

Aggregations

PersistableParticipant (com.arjuna.wst.PersistableParticipant)4 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)2 BusinessAgreementWithCoordinatorCompletionParticipant (com.arjuna.wst.BusinessAgreementWithCoordinatorCompletionParticipant)1 Durable2PCParticipant (com.arjuna.wst.Durable2PCParticipant)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 Serializable (java.io.Serializable)1