use of io.narayana.lra.coordinator.domain.model.Transaction in project narayana by jbosstm.
the class LRAService method lraTrace.
private void lraTrace(URL lraId, String reason) {
if (LRALogger.logger.isTraceEnabled()) {
LRALogger.logger.tracef("LRAServicve.forget %s failed%n", lraId);
if (lras.containsKey(lraId)) {
Transaction lra = lras.get(lraId);
LRALogger.logger.tracef("LRAServicve: %s (%s) in state %s: %s%n", reason, lra.getClientId(), ActionStatus.stringForm(lra.status()), lra.getId());
} else {
LRALogger.logger.tracef("LRAServicve: %s not found: %s%n", reason, lraId);
}
}
}
use of io.narayana.lra.coordinator.domain.model.Transaction in project narayana by jbosstm.
the class LRAService method leave.
public int leave(URL lraId, String compensatorUrl) {
lraTrace(lraId, "leave LRA");
Transaction transaction = getTransaction(lraId);
if (!transaction.isActive())
return Response.Status.PRECONDITION_FAILED.getStatusCode();
try {
if (!transaction.forgetParticipant(compensatorUrl))
if (LRALogger.logger.isInfoEnabled())
LRALogger.logger.infof("LRAServicve.forget %s failed%n", lraId);
return Response.Status.OK.getStatusCode();
} catch (Exception e) {
return Response.Status.BAD_REQUEST.getStatusCode();
}
}
use of io.narayana.lra.coordinator.domain.model.Transaction in project narayana by jbosstm.
the class LRAService method endLRA.
public LRAStatus endLRA(URL lraId, boolean compensate, boolean fromHierarchy) {
lraTrace(lraId, "end LRA");
Transaction transaction = getTransaction(lraId);
if (!transaction.isActive() && !transaction.isRecovering() && transaction.isTopLevel())
throw new IllegalLRAStateException(lraId.toString(), "LRA is closing or closed", "endLRA");
transaction.end(compensate);
if (transaction.currentLRA() != null)
if (LRALogger.logger.isInfoEnabled())
LRALogger.logger.infof("LRAServicve.endLRA LRA %s ended but is still associated with %s%n", lraId, transaction.currentLRA().get_uid().fileStringForm());
finished(transaction, fromHierarchy);
if (transaction.isTopLevel()) {
// forget any nested LRAs
// instruct compensators to clean up
transaction.forgetAllParticipants();
}
return new LRAStatus(transaction);
}
use of io.narayana.lra.coordinator.domain.model.Transaction in project narayana by jbosstm.
the class LRAService method joinLRA.
public synchronized int joinLRA(StringBuilder recoveryUrl, URL lra, long timeLimit, String compensatorUrl, String linkHeader, String recoveryUrlBase, String compensatorData) {
if (lra == null)
lraTrace(null, "Error missing LRA header in join request");
lraTrace(lra, "join LRA");
Transaction transaction = getTransaction(lra);
if (timeLimit < 0)
timeLimit = 0;
if (!transaction.isActive())
return Response.Status.PRECONDITION_FAILED.getStatusCode();
LRARecord participant;
try {
participant = transaction.enlistParticipant(lra, linkHeader != null ? linkHeader : compensatorUrl, recoveryUrlBase, timeLimit, compensatorData);
} catch (UnsupportedEncodingException e) {
return Response.Status.PRECONDITION_FAILED.getStatusCode();
}
if (// probably already closing or cancelling
participant == null || participant.getRecoveryCoordinatorURL() == null)
return Response.Status.PRECONDITION_FAILED.getStatusCode();
String recoveryURL = participant.getRecoveryCoordinatorURL().toExternalForm();
updateRecoveryURL(lra, participant.getParticipantURL(), recoveryURL, false);
recoveryUrl.append(recoveryURL);
return Response.Status.OK.getStatusCode();
}
use of io.narayana.lra.coordinator.domain.model.Transaction in project narayana by jbosstm.
the class LRAService method enableRecovery.
/**
* When the deployment is loaded register for recovery
*
* @param init a javax.servlet.ServletContext
*/
void enableRecovery(@Observes @Initialized(ApplicationScoped.class) Object init) {
assert lraRecoveryModule == null;
if (LRALogger.logger.isDebugEnabled())
LRALogger.logger.debugf("LRAServicve.enableRecovery%n");
lraRecoveryModule = new LRARecoveryModule(this);
RecoveryManager.manager().addModule(lraRecoveryModule);
Implementations.install();
lraRecoveryModule.getRecoveringLRAs(recoveringLRAs);
for (Transaction transaction : recoveringLRAs.values()) transaction.getRecoveryCoordinatorUrls(participants);
}
Aggregations