/** * Attempt to import a transaction, which subsequently may be controlled by its XID or by the returned handle. * * @param xid the XID of the transaction to import (must not be {@code null}) * @param timeout the transaction timeout to use, if new * @return the transaction import result (not {@code null}) * @throws XAException if a problem occurred while importing the transaction */ @NotNull public ImportResult<LocalTransaction> findOrImportTransaction(Xid xid, int timeout) throws XAException { return Assert.assertNotNull(findOrImportTransaction(xid, timeout, false)); }
private ImportResult<LocalTransaction> getImportedTransaction(final Xid xid) throws XAException { final ImportResult<LocalTransaction> result = transactionContext.findOrImportTransaction(xid, 0, true); if (result == null) { throw Log.log.noTransactionXa(XAException.XAER_NOTA); } final LocalTransaction transaction = result.getTransaction(); if (! transaction.isImported()) { throw Log.log.noTransactionXa(XAException.XAER_NOTA); } return result; } }
/** * <p> * Interception of register work call to get transaction being imported to wildfly transacton client. * <p> * For importing a transaction Wildfly transaction client eventually calls {@link SubordinationManager} * as Narayana {@link XATerminator}s do. This wrapping then let wildfly transacton client to register the transaction * for itself, wildfly transacton client then import transaction to Narayana too and finally this method * uses Narayana's {@link XATerminator} to register all {@link Work}s binding.<br> * Narayana's {@link XATerminator} tries to import transaction too but as transaction is already * imported it just gets instance of transaction already imported via call of wildfly transacton client. */ @Override public void registerWork(Work work, Xid xid, long timeout) throws WorkCompletedException { try { // jca provides timeout in milliseconds, SubordinationManager expects seconds int timeout_seconds = (int) timeout/1000; // unlimited timeout for jca means -1 which fails in wfly client if(timeout_seconds <= 0) timeout_seconds = ContextTransactionManager.getGlobalDefaultTransactionTimeout(); localTransactionContext.findOrImportTransaction(xid, timeout_seconds); } catch (XAException xae) { throw TransactionLogger.ROOT_LOGGER.cannotFindOrImportInflowTransaction(xid, work, xae); } jbossXATerminator.registerWork(work, xid, timeout); }
ExceptionSupplier<ImportResult<?>, SystemException> readTransaction(final DataInput input) throws IOException { final int type = input.readUnsignedByte(); if (type == 0) { return null; } else if (type == 1) { // remote user transaction final int id = input.readInt(); final int timeout = PackedInteger.readPackedInteger(input); return () -> new ImportResult<Transaction>(transactionServer.getOrBeginTransaction(id, timeout), SubordinateTransactionControl.EMPTY, false); } else if (type == 2) { final int fmt = PackedInteger.readPackedInteger(input); final byte[] gtid = new byte[input.readUnsignedByte()]; input.readFully(gtid); final byte[] bq = new byte[input.readUnsignedByte()]; input.readFully(bq); final int timeout = PackedInteger.readPackedInteger(input); return () -> { try { return transactionServer.getTransactionService().getTransactionContext().findOrImportTransaction(new SimpleXid(fmt, gtid, bq), timeout); } catch (XAException e) { throw new SystemException(e.getMessage()); } }; } else { throw Logs.REMOTING.invalidTransactionType(type); } }
/** * <p> * Start work gets imported transaction and assign it to current thread. * <p> * This method mimics behavior of Narayana's {@link JBossXATerminator}. */ @Override public void startWork(Work work, Xid xid) throws WorkCompletedException { LocalTransaction transaction = null; try { ImportResult<LocalTransaction> transactionImportResult = localTransactionContext.findOrImportTransaction(xid, 0); transaction = transactionImportResult.getTransaction(); ContextTransactionManager.getInstance().resume(transaction); } catch (XAException xae) { throw TransactionLogger.ROOT_LOGGER.cannotFindOrImportInflowTransaction(xid, work, xae); } catch (InvalidTransactionException ite) { throw TransactionLogger.ROOT_LOGGER.importedInflowTransactionIsInactive(xid, work, ite); } catch (SystemException se) { throw TransactionLogger.ROOT_LOGGER.cannotResumeInflowTransactionUnexpectedError(transaction, work, se); } }
try { final boolean onePhaseCopy = o.booleanValue(); final ImportResult<LocalTransaction> importResult = localTransactionContext.findOrImportTransaction(x, 0, ! onePhaseCopy); if (importResult == null) { writeExceptionResponse(M_RESP_XA_COMMIT, invId, new XAException(XAException.XAER_NOTA));
transactionSupplier = () -> { try { return transactionServer.getTransactionService().getTransactionContext().findOrImportTransaction(((XidTransactionID) transactionId).getXid(), 0); } catch (XAException e) { throw new SystemException(e.getMessage());
} else { try { ImportResult<LocalTransaction> result = localTransactionContext.findOrImportTransaction(txConfig.getXid(), txConfig.getRemainingTime()); transaction = result.getTransaction(); } catch (XAException e) {
@Override public final void handleRequest(HttpServerExchange exchange) throws Exception { ContentType contentType = ContentType.parse(exchange.getRequestHeaders().getFirst(Headers.CONTENT_TYPE)); if (contentType == null || contentType.getVersion() != 1 || !contentType.getType().equals(TransactionConstants.XID)) { exchange.setStatusCode(StatusCodes.BAD_REQUEST); HttpRemoteTransactionMessages.MESSAGES.debugf("Exchange %s has incorrect or missing content type", exchange); return; } try { Unmarshaller unmarshaller = MARSHALLER_FACTORY.createUnmarshaller(createMarshallingConf()); unmarshaller.start(new InputStreamByteInput(exchange.getInputStream())); int formatId = unmarshaller.readInt(); int len = unmarshaller.readInt(); byte[] globalId = new byte[len]; unmarshaller.readFully(globalId); len = unmarshaller.readInt(); byte[] branchId = new byte[len]; unmarshaller.readFully(branchId); SimpleXid simpleXid = new SimpleXid(formatId, globalId, branchId); unmarshaller.finish(); ImportResult<LocalTransaction> transaction = transactionContext.findOrImportTransaction(simpleXid, 0); transaction.getTransaction().performFunction((ExceptionBiFunction<ImportResult<LocalTransaction>, HttpServerExchange, Void, Exception>) (o, exchange2) -> { handleImpl(exchange2, o); return null; }, transaction, exchange); } catch (Exception e) { sendException(exchange, StatusCodes.INTERNAL_SERVER_ERROR, e); } }
final ImportResult<LocalTransaction> importResult = localTransactionContext.findOrImportTransaction(x, 0, true); if (importResult == null) { writeExceptionResponse(M_RESP_XA_RB_ONLY, i, new XAException(XAException.XAER_NOTA));
final ImportResult<LocalTransaction> importResult = localTransactionContext.findOrImportTransaction(x, 0, true); if (importResult == null) { writeExceptionResponse(M_RESP_XA_FORGET, i, new XAException(XAException.XAER_NOTA));
final ImportResult<LocalTransaction> importResult = localTransactionContext.findOrImportTransaction(x, 0, true); if (importResult == null) { writeExceptionResponse(M_RESP_XA_BEFORE, i, new XAException(XAException.XAER_NOTA));
final ImportResult<LocalTransaction> importResult = localTransactionContext.findOrImportTransaction(x, 0, true); if (importResult == null) { writeExceptionResponse(M_RESP_XA_ROLLBACK, i, new XAException(XAException.XAER_NOTA));
final ImportResult<LocalTransaction> importResult = localTransactionContext.findOrImportTransaction(x, 0, true); if (importResult == null) { writeExceptionResponse(M_RESP_XA_PREPARE, invId, new XAException(XAException.XAER_NOTA));
final TransactionID transactionID = TransactionID.createTransactionID(bytes); if (transactionID instanceof XidTransactionID) try { final SubordinateTransactionControl control = transactionServer.getTransactionService().getTransactionContext().findOrImportTransaction(((XidTransactionID) transactionID).getXid(), 0).getControl(); switch (code) { case Protocol.TXN_COMMIT_REQUEST: {
/** * Attempt to import a transaction, which subsequently may be controlled by its XID or by the returned handle. * * @param xid the XID of the transaction to import (must not be {@code null}) * @param timeout the transaction timeout to use, if new * @return the transaction import result (not {@code null}) * @throws XAException if a problem occurred while importing the transaction */ @NotNull public ImportResult<LocalTransaction> findOrImportTransaction(Xid xid, int timeout) throws XAException { return Assert.assertNotNull(findOrImportTransaction(xid, timeout, false)); }
/** * Attempt to import a transaction, which subsequently may be controlled by its XID or by the returned handle. * * @param xid the XID of the transaction to import (must not be {@code null}) * @param timeout the transaction timeout to use, if new * @return the transaction import result (not {@code null}) * @throws XAException if a problem occurred while importing the transaction */ @NotNull public ImportResult<LocalTransaction> findOrImportTransaction(Xid xid, int timeout) throws XAException { return Assert.assertNotNull(findOrImportTransaction(xid, timeout, false)); }
private ImportResult<LocalTransaction> getImportedTransaction(final Xid xid) throws XAException { final ImportResult<LocalTransaction> result = transactionContext.findOrImportTransaction(xid, 0, true); if (result == null) { throw Log.log.noTransactionXa(XAException.XAER_NOTA); } final LocalTransaction transaction = result.getTransaction(); if (! transaction.isImported()) { throw Log.log.noTransactionXa(XAException.XAER_NOTA); } return result; } }
private ImportResult<LocalTransaction> getImportedTransaction(final Xid xid) throws XAException { final ImportResult<LocalTransaction> result = transactionContext.findOrImportTransaction(xid, 0, true); if (result == null) { throw Log.log.noTransactionXa(XAException.XAER_NOTA); } final LocalTransaction transaction = result.getTransaction(); if (! transaction.isImported()) { throw Log.log.noTransactionXa(XAException.XAER_NOTA); } return result; } }
/** * <p> * Start work gets imported transaction and assign it to current thread. * <p> * This method mimics behavior of Narayana's {@link JBossXATerminator}. */ @Override public void startWork(Work work, Xid xid) throws WorkCompletedException { LocalTransaction transaction = null; try { ImportResult<LocalTransaction> transactionImportResult = localTransactionContext.findOrImportTransaction(xid, 0); transaction = transactionImportResult.getTransaction(); ContextTransactionManager.getInstance().resume(transaction); } catch (XAException xae) { throw TransactionLogger.ROOT_LOGGER.cannotFindOrImportInflowTransaction(xid, work, xae); } catch (InvalidTransactionException ite) { throw TransactionLogger.ROOT_LOGGER.importedInflowTransactionIsInactive(xid, work, ite); } catch (SystemException se) { throw TransactionLogger.ROOT_LOGGER.cannotResumeInflowTransactionUnexpectedError(transaction, work, se); } }