/** * @return a new object instance */ public DataStructure createObject() { return new TransactionInfo(); }
@Override public void onResponse(Command response) { ConnectionId connectionId = info.getConnectionId(); ConnectionState cs = connectionStates.get(connectionId); if (cs != null) { cs.removeTransactionState(info.getTransactionId()); } } }
/** * Un-marshal an object instance from the data input stream * * @param o the object to un-marshal * @param dataIn the data input stream to build the object from * @throws IOException */ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn) throws IOException { super.looseUnmarshal(wireFormat, o, dataIn); TransactionInfo info = (TransactionInfo)o; info.setConnectionId((org.apache.activemq.command.ConnectionId) looseUnmarsalCachedObject(wireFormat, dataIn)); info.setTransactionId((org.apache.activemq.command.TransactionId) looseUnmarsalCachedObject(wireFormat, dataIn)); info.setType(dataIn.readByte()); }
/** * Write the booleans that this object uses to a BooleanStream */ public void looseMarshal(OpenWireFormat wireFormat, Object o, DataOutput dataOut) throws IOException { TransactionInfo info = (TransactionInfo)o; super.looseMarshal(wireFormat, o, dataOut); looseMarshalCachedObject(wireFormat, (DataStructure)info.getConnectionId(), dataOut); looseMarshalCachedObject(wireFormat, (DataStructure)info.getTransactionId(), dataOut); dataOut.writeByte(info.getType()); } }
@Override public Response processRollbackTransaction(TransactionInfo info) throws Exception { TransportConnectionState cs = lookupConnectionState(info.getConnectionId()); context = cs.getContext(); cs.removeTransactionState(info.getTransactionId()); broker.rollbackTransaction(context, info.getTransactionId()); return null; }
@Override public Xid[] recover(int flag) throws XAException { LOG.debug("recover({})", flag); XATransactionId[] answer; if (XAResource.TMNOFLAGS == flag) { // signal next in cursor scan, which for us is always the end b/c we don't maintain any cursor state // allows looping scan to complete answer = new XATransactionId[0]; } else { TransactionInfo info = new TransactionInfo(getConnectionId(), null, TransactionInfo.RECOVER); try { this.connection.checkClosedOrFailed(); this.connection.ensureConnectionInfoSent(); DataArrayResponse receipt = (DataArrayResponse) this.connection.syncSendPacket(info); DataStructure[] data = receipt.getData(); if (data instanceof XATransactionId[]) { answer = (XATransactionId[]) data; } else { answer = new XATransactionId[data.length]; System.arraycopy(data, 0, answer, 0, data.length); } } catch (JMSException e) { throw toXAException(e); } } LOG.debug("recover({})={}", flag, answer); return answer; }
@Override public void forget(Xid xid) throws XAException { LOG.debug("Forget: {}", xid); // We allow interleaving multiple transactions, so // we don't limit forget to the associated xid. XATransactionId x; if (xid == null) { throw new XAException(XAException.XAER_PROTO); } if (equals(associatedXid, xid)) { // TODO determine if this can happen... I think not. x = (XATransactionId)transactionId; } else { x = new XATransactionId(xid); } TransactionInfo info = new TransactionInfo(getConnectionId(), x, TransactionInfo.FORGET); try { // Tell the server to forget the transaction. this.connection.syncSendPacket(info); } catch (JMSException e) { throw toXAException(e); } synchronized(ENDED_XA_TRANSACTION_CONTEXTS) { ENDED_XA_TRANSACTION_CONTEXTS.remove(x); } }
if (lastCommand instanceof TransactionInfo) { TransactionInfo transactionInfo = (TransactionInfo) lastCommand; if (transactionInfo.getType() == TransactionInfo.COMMIT_ONE_PHASE) { if (LOG.isDebugEnabled()) { LOG.debug("rolling back potentially completed tx: " + transactionState.getId()); response.setException(new TransactionRolledBackException("Transaction completion in doubt due to failover. Forcing rollback of " + command.getTransactionId())); response.setCorrelationId(command.getCommandId()); transport.getTransportListener().onCommand(response);
@Override public Response processForgetTransaction(TransactionInfo info) throws Exception { TransportConnectionState cs = lookupConnectionState(info.getConnectionId()); context = cs.getContext(); broker.forgetTransaction(context, info.getTransactionId()); return null; }
@Override public Response processCommitTransactionOnePhase(TransactionInfo info) throws Exception { TransportConnectionState cs = lookupConnectionState(info.getConnectionId()); context = cs.getContext(); cs.removeTransactionState(info.getTransactionId()); broker.commitTransaction(context, info.getTransactionId(), true); return null; }
/** * Start a local transaction. * @throws javax.jms.JMSException on internal error */ public void begin() throws JMSException { if (isInXATransaction()) { throw new TransactionInProgressException("Cannot start local transaction. XA transaction is already in progress."); } if (transactionId == null) { synchronizations = null; beforeEndIndex = 0; setRollbackOnly(false); this.transactionId = new LocalTransactionId(getConnectionId(), localTransactionIdGenerator.getNextSequenceId()); TransactionInfo info = new TransactionInfo(getConnectionId(), transactionId, TransactionInfo.BEGIN); this.connection.ensureConnectionInfoSent(); this.connection.asyncSendPacket(info); // Notify the listener that the tx was started. if (localTransactionEventListener != null) { localTransactionEventListener.beginEvent(); } LOG.debug("Begin:{}", transactionId); } }
/** * Write the booleans that this object uses to a BooleanStream */ public int tightMarshal1(OpenWireFormat wireFormat, Object o, BooleanStream bs) throws IOException { TransactionInfo info = (TransactionInfo)o; int rc = super.tightMarshal1(wireFormat, o, bs); rc += tightMarshalCachedObject1(wireFormat, (DataStructure)info.getConnectionId(), bs); rc += tightMarshalCachedObject1(wireFormat, (DataStructure)info.getTransactionId(), bs); return rc + 1; }
transactionId, (synchronizations != null ? synchronizations.size() : 0)); TransactionInfo info = new TransactionInfo(getConnectionId(), transactionId, TransactionInfo.COMMIT_ONE_PHASE); this.transactionId = null; this.connection.syncSendPacket(info); if (localTransactionEventListener != null) { localTransactionEventListener.commitEvent(); LOG.info("commit failed for transaction {}", info.getTransactionId(), cause); if (localTransactionEventListener != null) { localTransactionEventListener.rollbackEvent();
@Override public Response processBeginTransaction(TransactionInfo info) throws Exception { TransportConnectionState cs = lookupConnectionState(info.getConnectionId()); context = null; if (cs != null) { context = cs.getContext(); } if (cs == null) { throw new NullPointerException("Context is null"); } // Avoid replaying dup commands if (cs.getTransactionState(info.getTransactionId()) == null) { cs.addTransactionState(info.getTransactionId()); broker.beginTransaction(context, info.getTransactionId()); } return null; }
transactionId, (synchronizations != null ? synchronizations.size() : 0)); TransactionInfo info = new TransactionInfo(getConnectionId(), transactionId, TransactionInfo.ROLLBACK); this.transactionId = null; this.connection.syncSendPacket(info, this.connection.isClosing() ? this.connection.getCloseTimeout() : 0);
@Override public Response processPrepareTransaction(TransactionInfo info) throws Exception { TransportConnectionState cs = lookupConnectionState(info.getConnectionId()); context = null; if (cs != null) { throw new NullPointerException("Context is null"); TransactionState transactionState = cs.getTransactionState(info.getTransactionId()); if (transactionState == null) { throw new IllegalStateException("Cannot prepare a transaction that had not been started or previously returned XA_RDONLY: " + info.getTransactionId()); int result = broker.prepareTransaction(context, info.getTransactionId()); transactionState.setPreparedResult(result); if (result == XAResource.XA_RDONLY) { cs.removeTransactionState(info.getTransactionId());
@Override public Response processRecoverTransactions(TransactionInfo info) throws Exception { TransportConnectionState cs = lookupConnectionState(info.getConnectionId()); context = cs.getContext(); TransactionId[] preparedTransactions = broker.getPreparedTransactions(context); return new DataArrayResponse(preparedTransactions); }
/** * Write the booleans that this object uses to a BooleanStream */ public void looseMarshal(OpenWireFormat wireFormat, Object o, DataOutput dataOut) throws IOException { TransactionInfo info = (TransactionInfo)o; super.looseMarshal(wireFormat, o, dataOut); looseMarshalCachedObject(wireFormat, (DataStructure)info.getConnectionId(), dataOut); looseMarshalCachedObject(wireFormat, (DataStructure)info.getTransactionId(), dataOut); dataOut.writeByte(info.getType()); } }
x = new XATransactionId(xid); this.connection.checkClosedOrFailed(); this.connection.ensureConnectionInfoSent(); TransactionInfo info = new TransactionInfo(getConnectionId(), x, TransactionInfo.ROLLBACK); this.connection.syncSendPacket(info);
} else { x = new XATransactionId(xid); TransactionInfo info = new TransactionInfo(getConnectionId(), x, TransactionInfo.PREPARE); IntegerResponse response = (IntegerResponse)this.connection.syncSendPacket(info); if (XAResource.XA_RDONLY == response.getResult()) {