Search in sources :

Example 1 with Transaction

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);
        }
    }
}
Also used : Transaction(io.narayana.lra.coordinator.domain.model.Transaction)

Example 2 with Transaction

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();
    }
}
Also used : Transaction(io.narayana.lra.coordinator.domain.model.Transaction) IllegalLRAStateException(io.narayana.lra.client.IllegalLRAStateException) GenericLRAException(io.narayana.lra.client.GenericLRAException) InvalidLRAIdException(io.narayana.lra.client.InvalidLRAIdException) MalformedURLException(java.net.MalformedURLException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) NotFoundException(javax.ws.rs.NotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 3 with Transaction

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);
}
Also used : Transaction(io.narayana.lra.coordinator.domain.model.Transaction) LRAStatus(io.narayana.lra.coordinator.domain.model.LRAStatus) IllegalLRAStateException(io.narayana.lra.client.IllegalLRAStateException)

Example 4 with 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();
}
Also used : Transaction(io.narayana.lra.coordinator.domain.model.Transaction) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LRARecord(io.narayana.lra.coordinator.domain.model.LRARecord)

Example 5 with Transaction

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);
}
Also used : LRARecoveryModule(io.narayana.lra.coordinator.internal.LRARecoveryModule) Transaction(io.narayana.lra.coordinator.domain.model.Transaction)

Aggregations

Transaction (io.narayana.lra.coordinator.domain.model.Transaction)8 IllegalLRAStateException (io.narayana.lra.client.IllegalLRAStateException)3 InvalidLRAIdException (io.narayana.lra.client.InvalidLRAIdException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MalformedURLException (java.net.MalformedURLException)2 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)2 CompensatorStatus (io.narayana.lra.annotation.CompensatorStatus)1 GenericLRAException (io.narayana.lra.client.GenericLRAException)1 LRARecord (io.narayana.lra.coordinator.domain.model.LRARecord)1 LRAStatus (io.narayana.lra.coordinator.domain.model.LRAStatus)1 LRARecoveryModule (io.narayana.lra.coordinator.internal.LRARecoveryModule)1 GET (javax.ws.rs.GET)1 NotFoundException (javax.ws.rs.NotFoundException)1 Path (javax.ws.rs.Path)1