Search in sources :

Example 1 with Vote

use of org.jboss.narayana.rest.integration.api.Vote in project narayana by jbosstm.

the class InboundBridgeParticipant method commitOnePhase.

@Override
public void commitOnePhase() {
    if (LOG.isTraceEnabled()) {
        LOG.trace("InboundBridgeParticipant.commitOnePhase: xid=" + xid);
    }
    startBridge();
    final Vote outcome = prepareSubordinate();
    if (LOG.isTraceEnabled()) {
        LOG.trace("InboundBridgeParticipant.commitOnePhase: xid=" + xid + ", outcome=" + outcome);
    }
    if (outcome instanceof Prepared) {
        try {
            commitSubordinate();
        } catch (HeuristicException e) {
        }
    }
    cleanup();
}
Also used : HeuristicException(org.jboss.narayana.rest.integration.api.HeuristicException) Vote(org.jboss.narayana.rest.integration.api.Vote) Prepared(org.jboss.narayana.rest.integration.api.Prepared)

Example 2 with Vote

use of org.jboss.narayana.rest.integration.api.Vote in project narayana by jbosstm.

the class InboundBridgeParticipant method prepare.

@Override
public Vote prepare() {
    if (LOG.isTraceEnabled()) {
        LOG.trace("InboundBridgeParticipant.prepare: xid=" + xid);
    }
    startBridge();
    final Vote outcome = prepareSubordinate();
    if (!(outcome instanceof Prepared)) {
        cleanup();
    } else {
        stopBridge();
    }
    if (LOG.isTraceEnabled()) {
        LOG.trace("InboundBridgeParticipant.prepare: xid=" + xid + ", outcome=" + outcome.getClass().getName());
    }
    return outcome;
}
Also used : Vote(org.jboss.narayana.rest.integration.api.Vote) Prepared(org.jboss.narayana.rest.integration.api.Prepared)

Example 3 with Vote

use of org.jboss.narayana.rest.integration.api.Vote in project narayana by jbosstm.

the class ParticipantResource method terminate.

@PUT
@Consumes(TxMediaType.TX_STATUS_MEDIA_TYPE)
@Produces(TxMediaType.TX_STATUS_MEDIA_TYPE)
public Response terminate(@PathParam("participantId") final String participantId, final String content) throws HeuristicException {
    if (LOG.isTraceEnabled()) {
        LOG.trace("PUT request on ParticipantResource. ParticipantId: " + participantId + ", content: " + content);
    }
    final ParticipantInformation participantInformation = ParticipantsContainer.getInstance().getParticipantInformation(participantId);
    if (participantInformation == null) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("Participant with id " + participantId + " was not found.");
        }
        return Response.status(404).build();
    }
    String status = TxSupport.getStatus(content);
    if (TxStatus.isPrepare(status)) {
        if (!canPrepare(participantInformation)) {
            return Response.status(412).build();
        }
        Vote vote = prepare(participantInformation);
        return voteToResponse(vote);
    } else if (TxStatus.isCommit(status)) {
        if (!canCommit(participantInformation)) {
            return Response.status(412).build();
        }
        commit(participantInformation);
        return Response.ok().entity(TxSupport.toStatusContent(TxStatus.TransactionCommitted.name())).build();
    } else if (TxStatus.isCommitOnePhase(status)) {
        if (!canCommitOnePhase(participantInformation)) {
            return Response.status(412).build();
        }
        commitOnePhase(participantInformation);
        return Response.ok().entity(TxSupport.toStatusContent(TxStatus.TransactionCommittedOnePhase.name())).build();
    } else if (TxStatus.isAbort(status)) {
        rollback(participantInformation);
        return Response.ok().entity(TxSupport.toStatusContent(TxStatus.TransactionRolledBack.name())).build();
    }
    return Response.status(400).build();
}
Also used : Vote(org.jboss.narayana.rest.integration.api.Vote) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 4 with Vote

use of org.jboss.narayana.rest.integration.api.Vote in project narayana by jbosstm.

the class ParticipantResource method prepare.

private Vote prepare(final ParticipantInformation participantInformation) throws HeuristicException {
    if (isHeuristic(participantInformation)) {
        return prepareHeuristic(participantInformation);
    }
    participantInformation.setStatus(TxStatus.TransactionPreparing.name());
    final Vote vote;
    try {
        vote = participantInformation.getParticipant().prepare();
    } catch (ParticipantException e) {
        participantInformation.setStatus(TxStatus.TransactionActive.name());
        throw e;
    }
    if (vote instanceof Aborted) {
        rollback(participantInformation);
    } else if (vote instanceof Prepared) {
        participantInformation.setStatus(TxStatus.TransactionPrepared.name());
        RecoveryManager.getInstance().persistParticipantInformation(participantInformation);
    } else if (vote instanceof ReadOnly) {
        readOnly(participantInformation);
    }
    return vote;
}
Also used : ReadOnly(org.jboss.narayana.rest.integration.api.ReadOnly) Vote(org.jboss.narayana.rest.integration.api.Vote) Prepared(org.jboss.narayana.rest.integration.api.Prepared) ParticipantException(org.jboss.narayana.rest.integration.api.ParticipantException) Aborted(org.jboss.narayana.rest.integration.api.Aborted)

Example 5 with Vote

use of org.jboss.narayana.rest.integration.api.Vote in project narayana by jbosstm.

the class TransactionalService method enlistParticipant.

@POST
public String enlistParticipant(@QueryParam("participantEnlistmentUrl") final String participantEnlistmentUrl, @QueryParam("vote") final String stringVote, @Context final UriInfo uriInfo) {
    final Vote vote = stringVoteToVote(stringVote);
    final LoggingParticipant participant = new LoggingParticipant(vote);
    return ParticipantsManagerFactory.getInstance().enlist(APPLICATION_ID, participantEnlistmentUrl, participant).toString();
}
Also used : Vote(org.jboss.narayana.rest.integration.api.Vote) POST(javax.ws.rs.POST)

Aggregations

Vote (org.jboss.narayana.rest.integration.api.Vote)5 Prepared (org.jboss.narayana.rest.integration.api.Prepared)3 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1 Produces (javax.ws.rs.Produces)1 Aborted (org.jboss.narayana.rest.integration.api.Aborted)1 HeuristicException (org.jboss.narayana.rest.integration.api.HeuristicException)1 ParticipantException (org.jboss.narayana.rest.integration.api.ParticipantException)1 ReadOnly (org.jboss.narayana.rest.integration.api.ReadOnly)1