private void commit(LocalTransactionId tx, ConnectionContext connectionContext, Message message) throws Exception { if (tx != null) { connectionContext.getBroker().commitTransaction(connectionContext, tx, true); connectionContext.getTransactions().remove(tx); connectionContext.setTransaction(null); message.setTransactionId(null); } }
public void beginTransaction(ConnectionContext context, TransactionId xid) throws Exception { // the transaction may have already been started. if (xid.isXATransaction()) { XATransaction transaction = null; synchronized (xaTransactions) { transaction = xaTransactions.get(xid); if (transaction != null) { return; } transaction = new XATransaction(transactionStore, (XATransactionId)xid, this, context.getConnectionId()); xaTransactions.put(xid, transaction); } } else { Map<TransactionId, Transaction> transactionMap = context.getTransactions(); Transaction transaction = transactionMap.get(xid); if (transaction != null) { throw new JMSException("Transaction '" + xid + "' has already been started."); } transaction = new LocalTransaction(transactionStore, (LocalTransactionId)xid, context); transactionMap.put(xid, transaction); } }
public Transaction getTransaction(ConnectionContext context, TransactionId xid, boolean mightBePrepared) throws JMSException, XAException { Transaction transaction = null; if (xid.isXATransaction()) { synchronized (xaTransactions) { transaction = xaTransactions.get(xid); } } else { transaction = context.getTransactions().get(xid); } if (transaction != null) { return transaction; } if (xid.isXATransaction()) { XAException e = XATransaction.newXAException("Transaction '" + xid + "' has not been started.", XAException.XAER_NOTA); throw e; } else { throw new JMSException("Transaction '" + xid + "' has not been started."); } }
public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception { for (Iterator<Transaction> iter = context.getTransactions().values().iterator(); iter.hasNext();) { try { Transaction transaction = iter.next(); transaction.rollback(); } catch (Exception e) { LOG.warn("ERROR Rolling back disconnected client's transactions: ", e); } iter.remove(); } synchronized (xaTransactions) { // first find all txs that belongs to the connection ArrayList<XATransaction> txs = new ArrayList<XATransaction>(); for (XATransaction tx : xaTransactions.values()) { if (tx.getConnectionId() != null && tx.getConnectionId().equals(info.getConnectionId()) && !tx.isPrepared()) { txs.add(tx); } } // then remove them // two steps needed to avoid ConcurrentModificationException, from removeTransaction() for (XATransaction tx : txs) { try { tx.rollback(); } catch (Exception e) { LOG.warn("ERROR Rolling back disconnected client's xa transactions: ", e); } } } next.removeConnection(context, info, error); }
@Override public void rollback() throws XAException, IOException { if (LOG.isDebugEnabled()) { LOG.debug("rollback: " + xid + " syncCount: " + size()); } setState(Transaction.FINISHED_STATE); context.getTransactions().remove(xid); transactionStore.rollback(getTransactionId()); try { fireAfterRollback(); } catch (Throwable e) { LOG.warn("POST ROLLBACK FAILED: ", e); XAException xae = new XAException("POST ROLLBACK FAILED"); xae.errorCode = XAException.XAER_RMERR; xae.initCause(e); throw xae; } }
private Transaction getActiveTransaction(Command command) { Transaction transaction = null; try { if (command instanceof Message) { Message messageSend = (Message) command; ProducerId producerId = messageSend.getProducerId(); ProducerBrokerExchange producerExchange = getProducerBrokerExchange(producerId); transaction = producerExchange.getConnectionContext().getTransactions().get(messageSend.getTransactionId()); } else if (command instanceof MessageAck) { MessageAck messageAck = (MessageAck) command; ConsumerBrokerExchange consumerExchange = getConsumerBrokerExchange(messageAck.getConsumerId()); if (consumerExchange != null) { transaction = consumerExchange.getConnectionContext().getTransactions().get(messageAck.getTransactionId()); } } } catch(Exception ignored){ LOG.trace("failed to find active transaction for command: " + command, ignored); } return transaction; }
context.getTransactions().remove(xid); try { transactionStore.commit(getTransactionId(), false, preCommitTask, postCommitTask);
private LocalTransactionId beginLocalTransaction(int numDestinations, ConnectionContext connectionContext, Message message) throws Exception { LocalTransactionId result = null; if (transactedSend && numDestinations > 1 && message.isPersistent() && message.getTransactionId() == null) { result = new LocalTransactionId(new ConnectionId(message.getMessageId().getProducerId().toString()), message.getMessageId().getProducerSequenceId()); connectionContext.getBroker().beginTransaction(connectionContext, result); connectionContext.setTransaction(connectionContext.getTransactions().get(result)); message.setTransactionId(result); } return result; }
private void commit(LocalTransactionId tx, ConnectionContext connectionContext, Message message) throws Exception { if (tx != null) { connectionContext.getBroker().commitTransaction(connectionContext, tx, true); connectionContext.getTransactions().remove(tx); connectionContext.setTransaction(null); message.setTransactionId(null); } }
private void commit(LocalTransactionId tx, ConnectionContext connectionContext, Message message) throws Exception { if (tx != null) { connectionContext.getBroker().commitTransaction(connectionContext, tx, true); connectionContext.getTransactions().remove(tx); connectionContext.setTransaction(null); message.setTransactionId(null); } }
public Transaction getTransaction(ConnectionContext context, TransactionId xid, boolean mightBePrepared) throws JMSException, XAException { Transaction transaction = null; if (xid.isXATransaction()) { synchronized (xaTransactions) { transaction = xaTransactions.get(xid); } } else { transaction = context.getTransactions().get(xid); } if (transaction != null) { return transaction; } if (xid.isXATransaction()) { XAException e = XATransaction.newXAException("Transaction '" + xid + "' has not been started.", XAException.XAER_NOTA); throw e; } else { throw new JMSException("Transaction '" + xid + "' has not been started."); } }
private void commit(LocalTransactionId tx, ConnectionContext connectionContext, Message message) throws Exception { if (tx != null) { connectionContext.getBroker().commitTransaction(connectionContext, tx, true); connectionContext.getTransactions().remove(tx); connectionContext.setTransaction(null); message.setTransactionId(null); } }
public Transaction getTransaction(ConnectionContext context, TransactionId xid, boolean mightBePrepared) throws JMSException, XAException { Transaction transaction = null; if (xid.isXATransaction()) { synchronized (xaTransactions) { transaction = xaTransactions.get(xid); } } else { transaction = context.getTransactions().get(xid); } if (transaction != null) { return transaction; } if (xid.isXATransaction()) { XAException e = XATransaction.newXAException("Transaction '" + xid + "' has not been started.", XAException.XAER_NOTA); throw e; } else { throw new JMSException("Transaction '" + xid + "' has not been started."); } }
private Transaction getActiveTransaction(Command command) { Transaction transaction = null; try { if (command instanceof Message) { Message messageSend = (Message) command; ProducerId producerId = messageSend.getProducerId(); ProducerBrokerExchange producerExchange = getProducerBrokerExchange(producerId); transaction = producerExchange.getConnectionContext().getTransactions().get(messageSend.getTransactionId()); } else if (command instanceof MessageAck) { MessageAck messageAck = (MessageAck) command; ConsumerBrokerExchange consumerExchange = getConsumerBrokerExchange(messageAck.getConsumerId()); if (consumerExchange != null) { transaction = consumerExchange.getConnectionContext().getTransactions().get(messageAck.getTransactionId()); } } } catch(Exception ignored){ LOG.trace("failed to find active transaction for command: " + command, ignored); } return transaction; }
private Transaction getActiveTransaction(Command command) { Transaction transaction = null; try { if (command instanceof Message) { Message messageSend = (Message) command; ProducerId producerId = messageSend.getProducerId(); ProducerBrokerExchange producerExchange = getProducerBrokerExchange(producerId); transaction = producerExchange.getConnectionContext().getTransactions().get(messageSend.getTransactionId()); } else if (command instanceof MessageAck) { MessageAck messageAck = (MessageAck) command; ConsumerBrokerExchange consumerExchange = getConsumerBrokerExchange(messageAck.getConsumerId()); if (consumerExchange != null) { transaction = consumerExchange.getConnectionContext().getTransactions().get(messageAck.getTransactionId()); } } } catch(Exception ignored){ LOG.trace("failed to find active transaction for command: " + command, ignored); } return transaction; }
@Override public void rollback() throws XAException, IOException { if (LOG.isDebugEnabled()) { LOG.debug("rollback: " + xid + " syncCount: " + size()); } setState(Transaction.FINISHED_STATE); context.getTransactions().remove(xid); transactionStore.rollback(getTransactionId()); try { fireAfterRollback(); } catch (Throwable e) { LOG.warn("POST ROLLBACK FAILED: ", e); XAException xae = new XAException("POST ROLLBACK FAILED"); xae.errorCode = XAException.XAER_RMERR; xae.initCause(e); throw xae; } }
public Transaction getTransaction(ConnectionContext context, TransactionId xid, boolean mightBePrepared) throws JMSException, XAException { Map transactionMap = null; synchronized (xaTransactions) { transactionMap = xid.isXATransaction() ? xaTransactions : context.getTransactions(); } Transaction transaction = (Transaction)transactionMap.get(xid); if (transaction != null) { return transaction; } if (xid.isXATransaction()) { XAException e = new XAException("Transaction '" + xid + "' has not been started."); e.errorCode = XAException.XAER_NOTA; throw e; } else { throw new JMSException("Transaction '" + xid + "' has not been started."); } }
private LocalTransactionId beginLocalTransaction(int numDestinations, ConnectionContext connectionContext, Message message) throws Exception { LocalTransactionId result = null; if (transactedSend && numDestinations > 1 && message.isPersistent() && message.getTransactionId() == null) { result = new LocalTransactionId(new ConnectionId(message.getMessageId().getProducerId().toString()), message.getMessageId().getProducerSequenceId()); connectionContext.getBroker().beginTransaction(connectionContext, result); connectionContext.setTransaction(connectionContext.getTransactions().get(result)); message.setTransactionId(result); } return result; }
private LocalTransactionId beginLocalTransaction(int numDestinations, ConnectionContext connectionContext, Message message) throws Exception { LocalTransactionId result = null; if (transactedSend && numDestinations > 1 && message.isPersistent() && message.getTransactionId() == null) { result = new LocalTransactionId(new ConnectionId(message.getMessageId().getProducerId().toString()), message.getMessageId().getProducerSequenceId()); connectionContext.getBroker().beginTransaction(connectionContext, result); connectionContext.setTransaction(connectionContext.getTransactions().get(result)); message.setTransactionId(result); } return result; }
private LocalTransactionId beginLocalTransaction(int numDestinations, ConnectionContext connectionContext, Message message) throws Exception { LocalTransactionId result = null; if (transactedSend && numDestinations > 1 && message.isPersistent() && message.getTransactionId() == null) { result = new LocalTransactionId(new ConnectionId(message.getMessageId().getProducerId().toString()), message.getMessageId().getProducerSequenceId()); connectionContext.getBroker().beginTransaction(connectionContext, result); connectionContext.setTransaction(connectionContext.getTransactions().get(result)); message.setTransactionId(result); } return result; }