Search in sources :

Example 1 with RemoteTransaction

use of com.sun.messaging.jmq.jmsserver.data.RemoteTransaction in project openmq by eclipse-ee4j.

the class RemoteTransactionManager method replayTransactionEvent.

@Override
void replayTransactionEvent(TransactionEvent txnEvent, HashSet dstLoadedSet) throws BrokerException, IOException {
    if (Store.getDEBUG()) {
        Globals.getLogger().log(Logger.DEBUG, getPrefix() + " replayTransactionEvent");
    }
    RemoteTransactionEvent remoteTxnEvent = (RemoteTransactionEvent) txnEvent;
    // replay to store on commit
    RemoteTransaction remoteTxn = remoteTxnEvent.remoteTransaction;
    int state = remoteTxn.getState();
    TransactionUID tid = remoteTxn.getTid();
    if (remoteTxnEvent.getSubType() == RemoteTransactionEvent.Type2PPrepareEvent) {
        // in prepared txn store and resetting the transaction log
        if (incompleteStored.containsKey(tid)) {
            if (Store.getDEBUG()) {
                String msg = getPrefix() + " found matching txn in prepared store on replay " + remoteTxn;
                Globals.getLogger().log(Logger.DEBUG, msg);
            }
        } else {
            addToIncompleteUnstored(remoteTxn);
        }
    } else if (remoteTxnEvent.getSubType() == RemoteTransactionEvent.Type2PCompleteEvent) {
        // we are completing a transaction
        // the transaction could be
        // a) unstored (prepare replayed earlier)
        // b) stored incomplete (prepare occurred before last checkpoint,
        // completion not written to prepared store yet)
        // This should therefore be the last entry in log.
        // c) stored complete (prepare occurred before last checkpoint,
        // and failure occurred after completion stored in prepared store
        BaseTransaction existingWork = null;
        if (incompleteUnstored.containsKey(tid)) {
            // a) unstored (prepare replayed earlier)
            existingWork = removeFromIncompleteUnstored(tid);
        } else if (incompleteStored.containsKey(tid)) {
            // b) stored incomplete (prepare occurred before last checkpoint,
            // completion not written to prepared store yet)
            existingWork = removeFromIncompleteStored(tid);
            updateStoredState(tid, state);
            addToCompleteStored(existingWork);
        } else if (completeStored.containsKey(tid)) {
            // c) stored complete (prepare occurred before last checkpoint,
            // and failure occurred after completion stored in prepared store
            existingWork = completeStored.get(tid);
        }
        if (existingWork != null) {
            RemoteTransaction remoteTransaction = (RemoteTransaction) existingWork;
            if (state == TransactionState.COMMITTED) {
                TransactionAcknowledgement[] txnAcks = remoteTransaction.getTxnAcks();
                DestinationUID[] destIds = remoteTransaction.getDestIds();
                transactionLogManager.transactionLogReplayer.replayRemoteAcks(txnAcks, destIds, tid, dstLoadedSet);
            }
        } else {
            logger.log(Logger.ERROR, "Could not find prepared work for completing two-phase transaction " + remoteTxn.getTid());
        }
    }
}
Also used : TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) RemoteTransaction(com.sun.messaging.jmq.jmsserver.data.RemoteTransaction) BaseTransaction(com.sun.messaging.jmq.jmsserver.data.BaseTransaction)

Example 2 with RemoteTransaction

use of com.sun.messaging.jmq.jmsserver.data.RemoteTransaction in project openmq by eclipse-ee4j.

the class RemoteTransaction2PCompleteEvent method readFromBytes.

@Override
void readFromBytes(byte[] data) throws IOException, BrokerException {
    ByteArrayInputStream bais = new ByteArrayInputStream(data);
    DataInputStream dis = new DataInputStream(bais);
    remoteTransaction = new RemoteTransaction();
    dis.skip(2);
    remoteTransaction.getTransactionDetails().readContent(dis);
    dis.close();
    bais.close();
}
Also used : RemoteTransaction(com.sun.messaging.jmq.jmsserver.data.RemoteTransaction) ByteArrayInputStream(java.io.ByteArrayInputStream) DataInputStream(java.io.DataInputStream)

Example 3 with RemoteTransaction

use of com.sun.messaging.jmq.jmsserver.data.RemoteTransaction in project openmq by eclipse-ee4j.

the class RemoteTransaction2PPrepareEvent method readFromBytes.

@Override
public void readFromBytes(byte[] data) throws IOException, BrokerException {
    ByteArrayInputStream bais = new ByteArrayInputStream(data);
    DataInputStream dis = new DataInputStream(bais);
    remoteTransaction = new RemoteTransaction();
    dis.skip(2);
    remoteTransaction.getTransactionDetails().readContent(dis);
    int objectBodySize = dis.readInt();
    byte[] objectBody = new byte[objectBodySize];
    dis.read(objectBody);
    ByteArrayInputStream bais2 = new ByteArrayInputStream(objectBody);
    ObjectInputStream ois = new FilteringObjectInputStream(bais2);
    try {
        remoteTransaction.setTransactionState((TransactionState) ois.readObject());
        remoteTransaction.setTxnHomeBroker((BrokerAddress) ois.readObject());
        remoteTransaction.setTxnAcks((TransactionAcknowledgement[]) ois.readObject());
        remoteTransaction.setDestIds((DestinationUID[]) ois.readObject());
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    ois.close();
    bais2.close();
    dis.close();
    bais.close();
}
Also used : RemoteTransaction(com.sun.messaging.jmq.jmsserver.data.RemoteTransaction) TransactionAcknowledgement(com.sun.messaging.jmq.jmsserver.data.TransactionAcknowledgement) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) ByteArrayInputStream(java.io.ByteArrayInputStream) FilteringObjectInputStream(com.sun.messaging.jmq.util.io.FilteringObjectInputStream) DataInputStream(java.io.DataInputStream) FilteringObjectInputStream(com.sun.messaging.jmq.util.io.FilteringObjectInputStream) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

RemoteTransaction (com.sun.messaging.jmq.jmsserver.data.RemoteTransaction)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInputStream (java.io.DataInputStream)2 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)1 BaseTransaction (com.sun.messaging.jmq.jmsserver.data.BaseTransaction)1 TransactionAcknowledgement (com.sun.messaging.jmq.jmsserver.data.TransactionAcknowledgement)1 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)1 FilteringObjectInputStream (com.sun.messaging.jmq.util.io.FilteringObjectInputStream)1 ObjectInputStream (java.io.ObjectInputStream)1