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;
}
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;
}
}
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;
}
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;
}
Aggregations