Search in sources :

Example 31 with ConsumerUID

use of com.sun.messaging.jmq.jmsserver.core.ConsumerUID in project openmq by eclipse-ee4j.

the class ConsumerDAOImpl method checkConsumer.

/**
 * Check whether the specified consumer exists.
 *
 * @param conn database connection
 * @param consumer the Consumer
 * @return return true if the specified consumer exists
 */
private Consumer checkConsumer(Connection conn, Consumer consumer, boolean byId) throws BrokerException {
    ConsumerUID consumerUID = consumer.getConsumerUID();
    boolean myConn = false;
    String sql = selectExistByIDSQL;
    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;
        }
        if (!byId) {
            sql = selectExistSQL;
        }
        pstmt = dbMgr.createPreparedStatement(conn, sql);
        if (byId) {
            pstmt.setLong(1, consumerUID.longValue());
        } else {
            Util.setString(pstmt, 1, ((Subscription) consumer).getDurableName());
            Util.setString(pstmt, 2, ((Subscription) consumer).getClientID(), false);
        }
        rs = pstmt.executeQuery();
        if (rs.next()) {
            Consumer c = (Consumer) Util.readObject(rs, 1);
            return c;
        }
        return null;
    } 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 + "[" + sql + "]", rbe);
        }
        Exception ex;
        if (e instanceof BrokerException) {
            throw (BrokerException) e;
        } else if (e instanceof SQLException) {
            ex = DBManager.wrapSQLException("[" + sql + "]", (SQLException) e);
        } else if (e instanceof IOException) {
            ex = DBManager.wrapIOException("[" + sql + "]", (IOException) e);
        } else {
            ex = e;
        }
        throw new BrokerException(br.getKString(BrokerResources.X_RETRIEVE_INTEREST_FAILED, consumerUID), ex);
    } finally {
        if (myConn) {
            Util.close(rs, pstmt, conn, myex);
        } else {
            Util.close(rs, pstmt, null, myex);
        }
    }
}
Also used : Consumer(com.sun.messaging.jmq.jmsserver.core.Consumer) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) IOException(java.io.IOException) IOException(java.io.IOException)

Example 32 with ConsumerUID

use of com.sun.messaging.jmq.jmsserver.core.ConsumerUID in project openmq by eclipse-ee4j.

the class ConsumerStateDAOImpl method getStates.

/**
 * Get all consumers and states associated with the messapge ID.
 *
 * @param conn database connection
 * @return HashMap of containing all consumer's state
 */
@Override
public HashMap getStates(Connection conn, SysMessageID sysMsgID) throws BrokerException {
    HashMap map = new HashMap();
    String id = sysMsgID.getUniqueName();
    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, selectStatesByMsgSQL);
        pstmt.setString(1, id);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            ConsumerUID cUID = new ConsumerUID(rs.getLong(1));
            int state = rs.getInt(2);
            map.put(cUID, Integer.valueOf(state));
        }
    } 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("[" + selectStatesByMsgSQL + "]", (SQLException) e);
        } else {
            ex = e;
        }
        throw new BrokerException(br.getKString(BrokerResources.X_LOAD_INT_STATES_FOR_MSG_FAILED, id), ex);
    } finally {
        if (myConn) {
            Util.close(rs, pstmt, conn, myex);
        } else {
            Util.close(rs, pstmt, null, myex);
        }
    }
    return map;
}
Also used : ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID)

Example 33 with ConsumerUID

use of com.sun.messaging.jmq.jmsserver.core.ConsumerUID in project openmq by eclipse-ee4j.

the class ConsumerStateDAOImpl method getAllTransactionAcks.

/**
 * Retrieve all transaction acknowledgements for all transactions.
 *
 * @param conn database connection
 * @return HashMap of containing all acknowledgement
 */
@Override
public HashMap getAllTransactionAcks(Connection conn) throws BrokerException {
    HashMap data = new HashMap(100);
    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, selectAllTransactionAcksSQL);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            TransactionUID txnUID = new TransactionUID(rs.getLong(1));
            ConsumerUID conID = new ConsumerUID(rs.getLong(2));
            try {
                SysMessageID msgID = SysMessageID.get(rs.getString(3));
                List ackList = (List) data.get(txnUID);
                if (ackList == null) {
                    // Create a new list of acks for this txn
                    ackList = new ArrayList(25);
                    data.put(txnUID, ackList);
                }
                // Added ack to the list of acks
                ackList.add(new TransactionAcknowledgement(msgID, conID, conID));
            } catch (Exception e) {
                // fail to parse one object; just log it
                logger.logStack(Logger.ERROR, BrokerResources.X_PARSE_TXNACK_FAILED, txnUID, e);
            }
        }
    } 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("[" + selectAllTransactionAcksSQL + "]", (SQLException) e);
        } else {
            ex = e;
        }
        throw new BrokerException(br.getKString(BrokerResources.X_LOAD_TXNACK_FAILED), ex);
    } finally {
        if (myConn) {
            Util.close(rs, pstmt, conn, myex);
        } else {
            Util.close(rs, pstmt, null, myex);
        }
    }
    // Transforms HashMap value to TransactionAcknowledgement[] instead of List
    Set keySet = data.keySet();
    if (!keySet.isEmpty()) {
        Iterator itr = keySet.iterator();
        while (itr.hasNext()) {
            TransactionUID txnUID = (TransactionUID) itr.next();
            List ackList = (List) data.get(txnUID);
            data.put(txnUID, ackList.toArray(new TransactionAcknowledgement[ackList.size()]));
        }
    }
    return data;
}
Also used : TransactionAcknowledgement(com.sun.messaging.jmq.jmsserver.data.TransactionAcknowledgement) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) SysMessageID(com.sun.messaging.jmq.io.SysMessageID)

Example 34 with ConsumerUID

use of com.sun.messaging.jmq.jmsserver.core.ConsumerUID in project openmq by eclipse-ee4j.

the class ConsumerStateDAOImpl method getConsumerUIDs.

/**
 * Get all consumers associated with the messapge ID and state is not INTEREST_STATE_ACKNOWLEDGED.
 *
 * @param conn database connection
 * @param sysMsgID the system message ID
 * @return list of consumer IDs
 */
@Override
public List getConsumerUIDs(Connection conn, SysMessageID sysMsgID) throws BrokerException {
    List list = new ArrayList();
    String id = sysMsgID.getUniqueName();
    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, selectConsumerIDsByMsgSQL);
        pstmt.setString(1, id);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            ConsumerUID cUID = new ConsumerUID(rs.getLong(1));
            list.add(cUID);
        }
    } 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("[" + selectConsumerIDsByMsgSQL + "]", (SQLException) e);
        } else {
            ex = e;
        }
        throw new BrokerException(br.getKString(BrokerResources.X_LOAD_INT_STATES_FOR_MSG_FAILED, id), ex);
    } finally {
        if (myConn) {
            Util.close(rs, pstmt, conn, myex);
        } else {
            Util.close(rs, pstmt, null, myex);
        }
    }
    return list;
}
Also used : ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID)

Example 35 with ConsumerUID

use of com.sun.messaging.jmq.jmsserver.core.ConsumerUID in project openmq by eclipse-ee4j.

the class JMSServiceImpl method redeliverMessages.

/**
 * Redeliver messages for a Session.
 * <p>
 * All the messages that are specified by the parameters will be redelivered by the broker.
 *
 * @param connectionId The Id of the connection in which the messages were received
 * @param sessionId The Id of the session in which the messages were received
 * @param messageIDs The array of SysMessageID objects for the messages that were received and are to be redelivered
 * @param consumerIds The array of consumerId longs for the messages that were received and are to be redelivered
 * @param transactionId The Id of the transaction in which the messages were received
 * @param setRedelivered Indicates whether to set the Redelivered flag when redelivering the messages.<br>
 * If <code>true</code> then the Redelivered flag must be set for the messages when they are redelivered.<br>
 * If <code>false</code>, then the Redelivered flag must not be set for the messages when they are redelivered.
 *
 * @throws JMSServiceException If broker encounters an error.<br>
 * {@link JMSServiceException#getJMSServiceReply} should be used to obtain the broker reply in case of an exception.<br>
 * The reason for the exception can be obtained from {@link JMSServiceReply.Status}
 */
@Override
public JMSServiceReply redeliverMessages(long connectionId, long sessionId, SysMessageID[] messageIDs, Long[] consumerIds, long transactionId, boolean setRedelivered) throws JMSServiceException {
    JMSServiceReply reply;
    IMQConnection cxn;
    HashMap props = new HashMap();
    ConsumerUID[] conUIDs = null;
    TransactionUID txnUID = null;
    // Session session;
    cxn = checkConnectionId(connectionId, "redeliverMessages");
    // session = checkSessionId(sessionId, "redeliverMessages");
    checkSessionId(sessionId, "redeliverMessages");
    if (consumerIds != null) {
        conUIDs = new ConsumerUID[consumerIds.length];
        for (int i = 0; i < consumerIds.length; ++i) {
            conUIDs[i] = new ConsumerUID(consumerIds[i]);
        }
    }
    if (transactionId != -1) {
        txnUID = new TransactionUID(transactionId);
    }
    try {
        protocol.redeliver(conUIDs, messageIDs, cxn, txnUID, setRedelivered);
    } catch (Exception e) {
        String errStr = "redeliverMessages: Redeliver failed. Connection ID: " + connectionId + ", session ID: " + sessionId + ", transaction ID: " + transactionId;
        logger.logStack(Logger.ERROR, errStr, e);
        props.put("JMQStatus", getErrorReplyStatus(e));
        throw new JMSServiceException(errStr, e, props);
    }
    props.put("JMQStatus", JMSServiceReply.Status.OK);
    reply = new JMSServiceReply(props);
    return (reply);
}
Also used : TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) AccessControlException(java.security.AccessControlException)

Aggregations

ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)83 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)29 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)28 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)27 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)22 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)21 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)21 Iterator (java.util.Iterator)21 HashMap (java.util.HashMap)19 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)17 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)16 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)15 Map (java.util.Map)15 List (java.util.List)13 BrokerAddress (com.sun.messaging.jmq.jmsserver.core.BrokerAddress)10 DestinationList (com.sun.messaging.jmq.jmsserver.core.DestinationList)10 Session (com.sun.messaging.jmq.jmsserver.core.Session)10 TransactionList (com.sun.messaging.jmq.jmsserver.data.TransactionList)10 AckEntryNotFoundException (com.sun.messaging.jmq.jmsserver.util.AckEntryNotFoundException)9