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;
}
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;
}
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();
}
}
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.");
}
}
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;
}
Aggregations