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();
}
}
Aggregations