/** * Begin a new, local transaction on behalf of a local peer. * * @param timeout the transaction timeout to use for this transaction * @return the local transaction (not {@code null}) * @throws SystemException if the transaction creation failed for some reason, one of the possible reasons being * suspended server * @throws SecurityException if the caller is not authorized to create a local transaction in this context */ @NotNull public LocalTransaction beginTransaction(final int timeout) throws SystemException, SecurityException { return beginTransaction(timeout, false); }
/** * Begin a new, local transaction on behalf of a local or remote peer. * * @param timeout the transaction timeout to use for this transaction * @param failOnSuspend {@code true} to fail if the server is suspended, {@code false} to begin the transaction even if the server is suspended * @return the local transaction (not {@code null}) * @throws SystemException if the transaction creation failed for some reason, one of the possible reasons being * suspended server * @throws SecurityException if the caller is not authorized to create a local transaction in this context */ @NotNull public LocalTransaction beginTransaction(final int timeout, final boolean failOnSuspend) throws SystemException, SecurityException { return beginTransaction(timeout, failOnSuspend, CreationListener.CreatedBy.TRANSACTION_MANAGER); }
void begin(CreationListener.CreatedBy createdBy) throws NotSupportedException, SystemException { final State state = stateRef.get(); if (state.transaction != null) { throw Log.log.nestedNotSupported(); } resume(LocalTransactionContext.getCurrent().beginTransaction(state.getTimeout(), false, createdBy)); }
@NotNull public LocalTransaction getOrBeginTransaction(int id, int timeout) throws SystemException { final LocalTxn txn = txns.get(id); if (txn != null) { return txn.getTransaction(); } boolean ok = false; LocalTransaction transaction = transactionService.getTransactionContext().beginTransaction(timeout, true); try { final LocalTxn appearing = txns.putIfAbsent(new LocalTxn(id, transaction)); if (appearing != null) { return appearing.getTransaction(); } ok = true; return transaction; } finally { if (! ok) { safeRollback(transaction); } } }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { try { String timeoutString = exchange.getRequestHeaders().getFirst(TransactionConstants.TIMEOUT); if (timeoutString == null) { exchange.setStatusCode(StatusCodes.BAD_REQUEST); HttpRemoteTransactionMessages.MESSAGES.debugf("Exchange %s is missing %s header", exchange, TransactionConstants.TIMEOUT); return; } final Integer timeout = Integer.parseInt(timeoutString); exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, TransactionConstants.NEW_TRANSACTION.toString()); final LocalTransaction transaction = transactionContext.beginTransaction(timeout); final Xid xid = xidResolver.apply(transaction); final ByteArrayOutputStream out = new ByteArrayOutputStream(); Marshaller marshaller = MARSHALLER_FACTORY.createMarshaller(createMarshallingConf()); marshaller.start(new NoFlushByteOutput(Marshalling.createByteOutput(out))); marshaller.writeInt(xid.getFormatId()); marshaller.writeInt(xid.getGlobalTransactionId().length); marshaller.write(xid.getGlobalTransactionId()); marshaller.writeInt(xid.getBranchQualifier().length); marshaller.write(xid.getBranchQualifier()); marshaller.finish(); exchange.getResponseSender().send(ByteBuffer.wrap(out.toByteArray())); } catch (Exception e) { sendException(exchange, StatusCodes.INTERNAL_SERVER_ERROR, e); } } }
/** * Begin a new, local transaction on behalf of a local peer. * * @param timeout the transaction timeout to use for this transaction * @return the local transaction (not {@code null}) * @throws SystemException if the transaction creation failed for some reason, one of the possible reasons being * suspended server * @throws SecurityException if the caller is not authorized to create a local transaction in this context */ @NotNull public LocalTransaction beginTransaction(final int timeout) throws SystemException, SecurityException { return beginTransaction(timeout, false); }
/** * Begin a new, local transaction on behalf of a local peer. * * @param timeout the transaction timeout to use for this transaction * @return the local transaction (not {@code null}) * @throws SystemException if the transaction creation failed for some reason, one of the possible reasons being * suspended server * @throws SecurityException if the caller is not authorized to create a local transaction in this context */ @NotNull public LocalTransaction beginTransaction(final int timeout) throws SystemException, SecurityException { return beginTransaction(timeout, false); }
/** * Begin a new, local transaction on behalf of a local or remote peer. * * @param timeout the transaction timeout to use for this transaction * @param failOnSuspend {@code true} to fail if the server is suspended, {@code false} to begin the transaction even if the server is suspended * @return the local transaction (not {@code null}) * @throws SystemException if the transaction creation failed for some reason, one of the possible reasons being * suspended server * @throws SecurityException if the caller is not authorized to create a local transaction in this context */ @NotNull public LocalTransaction beginTransaction(final int timeout, final boolean failOnSuspend) throws SystemException, SecurityException { return beginTransaction(timeout, failOnSuspend, CreationListener.CreatedBy.TRANSACTION_MANAGER); }
/** * Begin a new, local transaction on behalf of a local or remote peer. * * @param timeout the transaction timeout to use for this transaction * @param failOnSuspend {@code true} to fail if the server is suspended, {@code false} to begin the transaction even if the server is suspended * @return the local transaction (not {@code null}) * @throws SystemException if the transaction creation failed for some reason, one of the possible reasons being * suspended server * @throws SecurityException if the caller is not authorized to create a local transaction in this context */ @NotNull public LocalTransaction beginTransaction(final int timeout, final boolean failOnSuspend) throws SystemException, SecurityException { return beginTransaction(timeout, failOnSuspend, CreationListener.CreatedBy.TRANSACTION_MANAGER); }
void begin(CreationListener.CreatedBy createdBy) throws NotSupportedException, SystemException { final State state = stateRef.get(); if (state.transaction != null) { throw Log.log.nestedNotSupported(); } resume(LocalTransactionContext.getCurrent().beginTransaction(state.getTimeout(), false, createdBy)); }
void begin(CreationListener.CreatedBy createdBy) throws NotSupportedException, SystemException { final State state = stateRef.get(); if (state.transaction != null) { throw Log.log.nestedNotSupported(); } resume(LocalTransactionContext.getCurrent().beginTransaction(state.getTimeout(), false, createdBy)); }
@NotNull public LocalTransaction getOrBeginTransaction(int id, int timeout) throws SystemException { final LocalTxn txn = txns.get(id); if (txn != null) { return txn.getTransaction(); } boolean ok = false; LocalTransaction transaction = transactionService.getTransactionContext().beginTransaction(timeout, true); try { final LocalTxn appearing = txns.putIfAbsent(new LocalTxn(id, transaction)); if (appearing != null) { return appearing.getTransaction(); } ok = true; return transaction; } finally { if (! ok) { safeRollback(transaction); } } }
@NotNull public LocalTransaction getOrBeginTransaction(int id, int timeout) throws SystemException { final LocalTxn txn = txns.get(id); if (txn != null) { return txn.getTransaction(); } boolean ok = false; LocalTransaction transaction = transactionService.getTransactionContext().beginTransaction(timeout, true); try { final LocalTxn appearing = txns.putIfAbsent(new LocalTxn(id, transaction)); if (appearing != null) { return appearing.getTransaction(); } ok = true; return transaction; } finally { if (! ok) { safeRollback(transaction); } } }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { try { String timeoutString = exchange.getRequestHeaders().getFirst(TransactionConstants.TIMEOUT); if (timeoutString == null) { exchange.setStatusCode(StatusCodes.BAD_REQUEST); HttpRemoteTransactionMessages.MESSAGES.debugf("Exchange %s is missing %s header", exchange, TransactionConstants.TIMEOUT); return; } final Integer timeout = Integer.parseInt(timeoutString); exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, TransactionConstants.NEW_TRANSACTION.toString()); final LocalTransaction transaction = transactionContext.beginTransaction(timeout); final Xid xid = xidResolver.apply(transaction); final ByteArrayOutputStream out = new ByteArrayOutputStream(); Marshaller marshaller = MARSHALLER_FACTORY.createMarshaller(createMarshallingConf()); marshaller.start(new NoFlushByteOutput(Marshalling.createByteOutput(out))); marshaller.writeInt(xid.getFormatId()); marshaller.writeInt(xid.getGlobalTransactionId().length); marshaller.write(xid.getGlobalTransactionId()); marshaller.writeInt(xid.getBranchQualifier().length); marshaller.write(xid.getBranchQualifier()); marshaller.finish(); exchange.getResponseSender().send(ByteBuffer.wrap(out.toByteArray())); } catch (Exception e) { sendException(exchange, StatusCodes.INTERNAL_SERVER_ERROR, e); } } }