Search in sources :

Example 1 with TransactionStatusException

use of org.jboss.jbossts.star.provider.TransactionStatusException 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

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