Search in sources :

Example 6 with TransactionState

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

the class Destination method txnSize.

public int txnSize(Set<PacketReference> msgset, DestinationInfo dinfo) {
    Set<PacketReference> msgs = msgset;
    if (msgs == null) {
        synchronized (destMessages) {
            msgs = new HashSet<>(destMessages.values());
        }
    }
    Iterator<PacketReference> itr = msgs.iterator();
    int cnt = 0;
    TransactionList tl = DL.getTransactionList();
    while (itr.hasNext()) {
        PacketReference ref = itr.next();
        TransactionUID tid = ref.getTransactionID();
        if (tid == null) {
            continue;
        }
        TransactionState ts = tl.retrieveState(tid, true);
        if (ts == null || ts.getState() == TransactionState.COMMITTED) {
            continue;
        }
        cnt++;
        if (dinfo != null) {
            dinfo.nTxnMessages++;
            dinfo.nTxnMessageBytes += ref.getSize();
        }
    }
    return cnt;
}
Also used : TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList)

Example 7 with TransactionState

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

the class TransactionUtil method getState.

public static Integer getState(TransactionUID tid) {
    TransactionList[] tls = Globals.getDestinationList().getTransactionList(null);
    // PART
    TransactionList tl = tls[0];
    TransactionState ts;
    if (tl == null) {
        return (null);
    }
    ts = tl.retrieveState(tid);
    if (ts == null) {
        return (null);
    }
    return (Integer.valueOf(toExternalTransactionState(ts.getState())));
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList)

Example 8 with TransactionState

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

the class TransactionDAOImpl method getTransactionInfo.

/**
 * Get the TransactionInfo object.
 *
 * @param conn database connection
 * @param txnUID the transaction ID
 * @return TransactionInfo object
 */
@Override
public TransactionInfo getTransactionInfo(Connection conn, TransactionUID txnUID) throws BrokerException {
    TransactionInfo txnInfo = null;
    long id = txnUID.longValue();
    boolean myConn = false;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    Exception myex = null;
    try {
        // Get a connection
        DBManager dbMgr = DBManager.getDBManager();
        if (conn == null) {
            conn = dbMgr.getConnection(true);
            myConn = true;
        }
        pstmt = dbMgr.createPreparedStatement(conn, selectTxnInfoSQL);
        pstmt.setLong(1, id);
        rs = pstmt.executeQuery();
        if (rs.next()) {
            int type = rs.getInt(1);
            int state = rs.getInt(2);
            TransactionState txnState = (TransactionState) Util.readObject(rs, 3);
            // update state in TransactionState object
            txnState.setState(state);
            BrokerAddress txnHomeBroker = (BrokerAddress) Util.readObject(rs, 4);
            TransactionBroker[] txnBrokers = (TransactionBroker[]) Util.readObject(rs, 5);
            txnInfo = new TransactionInfo(txnState, txnHomeBroker, txnBrokers, type);
        } else {
            throw new BrokerException(br.getKString(BrokerResources.E_TRANSACTIONID_NOT_FOUND_IN_STORE, String.valueOf(id)), Status.NOT_FOUND);
        }
    } catch (Exception e) {
        myex = e;
        try {
            if ((conn != null) && !conn.getAutoCommit()) {
                conn.rollback();
            }
        } catch (SQLException rbe) {
            logger.log(Logger.ERROR, BrokerResources.X_DB_ROLLBACK_FAILED, rbe);
        }
        Exception ex;
        if (e instanceof BrokerException) {
            throw (BrokerException) e;
        } else if (e instanceof SQLException) {
            ex = DBManager.wrapSQLException("[" + selectTxnInfoSQL + "]", (SQLException) e);
        } else {
            ex = e;
        }
        BrokerException be = new BrokerException(br.getKString(BrokerResources.X_LOAD_TRANSACTION_FAILED, txnUID), ex);
        be.setSQLRecoverable(true);
        throw be;
    } finally {
        if (myConn) {
            Util.close(rs, pstmt, conn, myex);
        } else {
            Util.close(rs, pstmt, null, myex);
        }
    }
    return txnInfo;
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) IOException(java.io.IOException) BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress) TransactionBroker(com.sun.messaging.jmq.jmsserver.data.TransactionBroker) TransactionInfo(com.sun.messaging.jmq.jmsserver.persist.api.TransactionInfo)

Example 9 with TransactionState

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

the class RollbackCommitHandler method handle.

/**
 * Handle the incomming administration message.
 *
 * @param con The Connection the message came in on.
 * @param cmd_msg The administration message
 * @param cmd_props The properties from the administration message
 */
@Override
public boolean handle(IMQConnection con, Packet cmd_msg, Hashtable cmd_props) {
    if (DEBUG) {
        logger.log(Logger.DEBUG, this.getClass().getName() + ": " + "Rollback/Commit transaction " + cmd_props);
    }
    // Get the admin request message type
    int requestType = ((Integer) cmd_props.get(MessageType.JMQ_MESSAGE_TYPE)).intValue();
    int status = Status.OK;
    String errMsg = null;
    TransactionUID tid = null;
    TransactionState ts = null;
    TransactionHandler thandler = null;
    // Get the packet handler that handles transaction packets
    if (parent.adminPktRtr != null) {
        thandler = (TransactionHandler) parent.adminPktRtr.getHandler(PacketType.ROLLBACK_TRANSACTION);
    }
    Long id = (Long) cmd_props.get(MessageType.JMQ_TRANSACTION_ID);
    // only applies to rollback request
    Boolean v = (Boolean) cmd_props.get(MessageType.JMQ_PROCESS_ACTIVE_CONSUMERS);
    boolean processActiveConsumers = (v != null && v.booleanValue());
    HAMonitorService hamonitor = Globals.getHAMonitorService();
    if (hamonitor != null && hamonitor.inTakeover()) {
        status = Status.ERROR;
        errMsg = rb.getString(rb.E_CANNOT_PROCEED_TAKEOVER_IN_PROCESS);
        logger.log(Logger.ERROR, this.getClass().getName() + ": " + errMsg);
    }
    if (id != null) {
        tid = new TransactionUID(id.longValue());
    } else {
        status = Status.BAD_REQUEST;
    }
    if (status == Status.OK) {
        TransactionList[] tls = DL.getTransactionList(null);
        TransactionList tl = null;
        for (int i = 0; i < tls.length; i++) {
            tl = tls[i];
            ts = tl.retrieveState(tid);
            if (ts == null) {
                continue;
            }
            break;
        }
        if (ts == null) {
            // Specified transaction did not exist
            status = Status.NOT_FOUND;
            errMsg = rb.getString(rb.E_NO_SUCH_TRANSACTION, tid);
        } else if (requestType == MessageType.COMMIT_TRANSACTION && ts.getState() != TransactionState.PREPARED) {
            status = Status.PRECONDITION_FAILED;
            errMsg = rb.getString(rb.E_TRANSACTION_NOT_PREPARED, tid);
        } else if (requestType == MessageType.ROLLBACK_TRANSACTION && (ts.getState() < TransactionState.STARTED || ts.getState() > TransactionState.PREPARED)) {
            status = Status.PRECONDITION_FAILED;
            errMsg = rb.getString(rb.E_INVALID_TXN_STATE_FOR_ROLLBACK, tid);
        } else {
            JMQXid xid = tl.UIDToXid(tid);
            if (xid == null && (!(Globals.getHAEnabled() && ts.getState() == TransactionState.PREPARED))) {
                /*
                     * Need to pick the right error message: If (action is ROLLBACK and state is one of {STARTED, FAILED, INCOMPLETE,
                     * COMPLETE}) "Rollback of non-XA transaction 123456789 in non-PREPARED state is not supported." else
                     * "Could not find Xid for 123456789"
                     */
                if (requestType == MessageType.ROLLBACK_TRANSACTION && (ts.getState() >= TransactionState.STARTED && ts.getState() < TransactionState.PREPARED)) {
                    errMsg = rb.getString(rb.E_INTERNAL_BROKER_ERROR, "Rollback of non-XA transaction " + tid + " in non-PREPARED state is not supported.");
                } else {
                    errMsg = rb.getString(rb.E_INTERNAL_BROKER_ERROR, "Could not find Xid for " + tid);
                }
                status = Status.ERROR;
            } else if (thandler == null) {
                errMsg = rb.getString(rb.E_INTERNAL_BROKER_ERROR, "Could not locate TransactionHandler");
                status = Status.ERROR;
            } else {
                if (requestType == MessageType.ROLLBACK_TRANSACTION) {
                    if (DEBUG) {
                        logger.log(Logger.DEBUG, "Rolling back " + tid + " in state " + ts);
                    }
                    try {
                        if (processActiveConsumers) {
                            logger.log(logger.INFO, rb.getKString(rb.I_ADMIN_REDELIVER_MSGS_ON_TXN_ROLLBACK, tid));
                            try {
                                thandler.redeliverUnacked(tl, tid, true, true, true, -1, false);
                            } catch (Exception e) {
                                logger.logStack(logger.WARNING, rb.getKString(rb.X_ADMIN_REDELIVER_MSG_ON_TXN_ROLLBACK, tid, e.getMessage()), e);
                            }
                        }
                        thandler.doRollback(tl, tid, xid, null, ts, null, con, RollbackReason.ADMIN);
                    } catch (BrokerException e) {
                        status = Status.ERROR;
                        errMsg = e.getMessage();
                    }
                } else if (requestType == MessageType.COMMIT_TRANSACTION) {
                    if (DEBUG) {
                        logger.log(Logger.DEBUG, "Committing " + tid + " in state " + ts);
                    }
                    try {
                        thandler.doCommit(tl, tid, xid, Integer.valueOf(XAResource.TMNOFLAGS), ts, null, false, con, null);
                    } catch (BrokerException e) {
                        status = Status.ERROR;
                        errMsg = e.getMessage();
                    }
                } else {
                    // Should never happen.
                    return super.handle(con, cmd_msg, cmd_props);
                }
            }
        }
    }
    sendReply(con, cmd_msg, requestType + 1, status, errMsg);
    return true;
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList) JMQXid(com.sun.messaging.jmq.util.JMQXid) HAMonitorService(com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAMonitorService) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) TransactionHandler(com.sun.messaging.jmq.jmsserver.data.handlers.TransactionHandler)

Example 10 with TransactionState

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

the class ProtocolImpl method verifyTransaction.

/**
 * Verify a transaction is PREPARED
 *
 * @param tuid transaction id to verify
 */
@Override
public Map verifyTransaction(TransactionUID tuid) throws BrokerException {
    // TransactionHandler handler = (TransactionHandler)
    // pr.getHandler(PacketType.START_TRANSACTION);
    Object[] oo = TransactionList.getTransListAndState(tuid, null, true, false);
    if (oo == null) {
        return null;
    }
    TransactionList translist = (TransactionList) oo[0];
    TransactionState ts = (TransactionState) oo[1];
    int realstate = ts.getState();
    if (realstate != TransactionState.PREPARED) {
        // GONE
        return null;
    }
    return translist.getTransactionMap(tuid, true);
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList)

Aggregations

TransactionState (com.sun.messaging.jmq.jmsserver.data.TransactionState)49 TransactionList (com.sun.messaging.jmq.jmsserver.data.TransactionList)25 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)22 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)14 JMQXid (com.sun.messaging.jmq.util.JMQXid)9 IOException (java.io.IOException)9 TransactionBroker (com.sun.messaging.jmq.jmsserver.data.TransactionBroker)8 TransactionInfo (com.sun.messaging.jmq.jmsserver.persist.api.TransactionInfo)8 TransactionHandler (com.sun.messaging.jmq.jmsserver.data.handlers.TransactionHandler)7 HashMap (java.util.HashMap)7 ArrayList (java.util.ArrayList)6 PHashMapLoadException (com.sun.messaging.jmq.io.disk.PHashMapLoadException)5 DestinationList (com.sun.messaging.jmq.jmsserver.core.DestinationList)5 LoadException (com.sun.messaging.jmq.jmsserver.persist.api.LoadException)5 BrokerAddress (com.sun.messaging.jmq.jmsserver.core.BrokerAddress)4 PartitionedStore (com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore)4 ConnectionUID (com.sun.messaging.jmq.jmsserver.service.ConnectionUID)4 SizeString (com.sun.messaging.jmq.util.SizeString)4 Iterator (java.util.Iterator)4 PHashMap (com.sun.messaging.jmq.io.disk.PHashMap)3