Search in sources :

Example 6 with Transaction

use of org.jboss.jbossts.star.resource.Transaction in project narayana by jbosstm.

the class Coordinator method deleteParticipant.

/**
 * Performing DELETE on participant's recovery URL removes participant from the transaction.
 *
 * @param enlistmentId The resource reference
 * @return HTTP status code
 */
@DELETE
@Path(RC_SEGMENT + "/{RecCoordId}")
public Response deleteParticipant(@PathParam("RecCoordId") String enlistmentId) {
    log.tracef("coordinator: participant leaving via Delete: recovery-coordinator/%s", enlistmentId);
    HashMap<String, String> p = participants.get(enlistmentId);
    Transaction txn;
    if (p == null || (txn = transactions.get(p.get(TxLinkNames.TRANSACTION))) == null)
        return Response.status(HttpURLConnection.HTTP_NOT_FOUND).build();
    if (txn.forgetParticipant(p.get(TxLinkNames.PARTICIPANT_RESOURCE)))
        return Response.status(HttpURLConnection.HTTP_OK).build();
    return Response.status(HttpURLConnection.HTTP_CONFLICT).build();
}
Also used : RecoveringTransaction(org.jboss.jbossts.star.resource.RecoveringTransaction) Transaction(org.jboss.jbossts.star.resource.Transaction)

Example 7 with Transaction

use of org.jboss.jbossts.star.resource.Transaction in project narayana by jbosstm.

the class Coordinator method getTransactionStatus.

/**
 * Performing a GET on the transaction url returns its status
 * @see org.jboss.jbossts.star.util.TxStatusMediaType#TX_ACTIVE
 *  etc for the format of the returned content
 * @param info request context
 * @param id URL template parameter for the id of the transaction
 * @return content representing the status of the transaction
 */
@GET
@Path(TxSupport.TX_SEGMENT + "{id}")
@Produces(TxMediaType.TX_STATUS_MEDIA_TYPE)
public Response getTransactionStatus(@Context UriInfo info, @PathParam("id") String id) {
    log.tracef("coordinator: status: transaction-coordinator/%s", id);
    Transaction txn = getTransaction(id);
    Response.ResponseBuilder builder = Response.ok(TxSupport.toStatusContent(txn.getStatus()));
    return addTransactionHeaders(builder, info, txn, false).build();
}
Also used : Response(javax.ws.rs.core.Response) RecoveringTransaction(org.jboss.jbossts.star.resource.RecoveringTransaction) Transaction(org.jboss.jbossts.star.resource.Transaction)

Example 8 with Transaction

use of org.jboss.jbossts.star.resource.Transaction in project narayana by jbosstm.

the class Coordinator method beginTransaction.

/**
 * Performing a POST on Transaction Manager URL @see TxSupport.TX_SEGMENT with no content
 * as shown below will start a new transaction with a default timeout.
 * A successful invocation will return 201 and the Location header MUST contain the URI
 * of the newly created transaction resource, which we will refer to as the transaction-coordinator
 * in the rest of this specification. Two related URLs MUST also be returned,
 * one for use by the terminator of the transaction (typically referred to as the client)
 * and one used for registering durable participation in the transaction (typically referred
 * to as the server). These linked URLs can be of arbitrary format.
 * The rel names for the links are:
 * @see org.jboss.jbossts.star.util.TxLinkNames#TERMINATOR and @see TxLinkNames#PARTICIPANT
 *
 * @param info uri context
 * @param headers http headers
 * @param content empty if no transaction timeout is required otherwise the number of milliseconds
 * after which the transaction is eligible for being timed out. The content should have the format
 * TxSupport#TIMEOUT_PROPERTY milliseconds
 * @return http status code
 */
@SuppressWarnings({ "UnusedDeclaration" })
@POST
@Path(TxSupport.TX_SEGMENT)
@Consumes(TxMediaType.POST_MEDIA_TYPE)
public // @Produces("application/vnd.rht.txstatus+text;version=0.1")
Response beginTransaction(@Context UriInfo info, @Context HttpHeaders headers, @DefaultValue("") String content) {
    log.tracef("coordinator: POST /transaction-manager content: %s", content);
    Transaction tx = new Transaction(this, "coordinator");
    // default is 0 - never timeout
    int timeout = TxSupport.getIntValue(content, TxMediaType.TIMEOUT_PROPERTY, 0);
    String uid = tx.get_uid().fileStringForm();
    log.tracef("coordinator: timeout=%d", timeout);
    transactions.put(uid, tx);
    // round up the timeout from milliseconds to seconds
    if (timeout != 0) {
        if (timeout < 0)
            timeout = 0;
        else
            timeout /= 1000;
    }
    int status = tx.begin(timeout);
    try {
        if (status == ActionStatus.RUNNING) {
            active.incrementAndGet();
            URI uri1 = TxSupport.getUri(info, info.getPathSegments().size(), uid);
            Response.ResponseBuilder builder = Response.created(uri1);
            return addTransactionHeaders(builder, info, tx, true).build();
        }
        throw new TransactionStatusException("Transaction failed to start: " + status);
    } catch (Exception e) {
        log.debugf(e, "begin");
        throw new TransactionStatusException("Transaction failed to start: " + e);
    } finally {
        AtomicAction.suspend();
    }
}
Also used : Response(javax.ws.rs.core.Response) RecoveringTransaction(org.jboss.jbossts.star.resource.RecoveringTransaction) Transaction(org.jboss.jbossts.star.resource.Transaction) URI(java.net.URI) TransactionStatusException(org.jboss.jbossts.star.provider.TransactionStatusException) TransactionStatusException(org.jboss.jbossts.star.provider.TransactionStatusException) ResourceNotFoundException(org.jboss.jbossts.star.provider.ResourceNotFoundException)

Aggregations

RecoveringTransaction (org.jboss.jbossts.star.resource.RecoveringTransaction)8 Transaction (org.jboss.jbossts.star.resource.Transaction)8 URI (java.net.URI)2 Response (javax.ws.rs.core.Response)2 UriBuilder (javax.ws.rs.core.UriBuilder)1 ResourceNotFoundException (org.jboss.jbossts.star.provider.ResourceNotFoundException)1 TransactionStatusException (org.jboss.jbossts.star.provider.TransactionStatusException)1