Search in sources :

Example 26 with SysMessageID

use of com.sun.messaging.jmq.io.SysMessageID in project openmq by eclipse-ee4j.

the class MsgRemovalEvent method readFromBytes.

@Override
public void readFromBytes(byte[] data) throws IOException, BrokerException {
    ByteArrayInputStream bais = new ByteArrayInputStream(data);
    DataInputStream dis = new DataInputStream(bais);
    dis.skip(2);
    String dest = dis.readUTF();
    destUID = new DestinationUID(dest);
    sysMessageID = new SysMessageID();
    sysMessageID.readID(dis);
    dis.close();
    bais.close();
}
Also used : DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) ByteArrayInputStream(java.io.ByteArrayInputStream) SysMessageID(com.sun.messaging.jmq.io.SysMessageID) DataInputStream(java.io.DataInputStream)

Example 27 with SysMessageID

use of com.sun.messaging.jmq.io.SysMessageID in project openmq by eclipse-ee4j.

the class MsgStore method moveMessage.

void moveMessage(Packet message, DestinationUID from, DestinationUID to, ConsumerUID[] ints, int[] states, boolean sync) throws IOException, BrokerException {
    SysMessageID mid = message.getSysMessageID();
    // sanity check
    // get from cache; instantiate=true, load=true, create=false
    DstMsgStore fromdst = getDstMsgStore(from, true, true, false);
    if (fromdst == null || !fromdst.containsMsg(mid)) {
        logger.log(logger.ERROR, br.E_MSG_NOT_FOUND_IN_STORE, mid, from);
        throw new BrokerException(br.getString(br.E_MSG_NOT_FOUND_IN_STORE, mid, from));
    }
    // first save the message and then remove the message
    storeMessage(to, message, ints, states, sync);
    try {
        fromdst.removeMessage(message.getSysMessageID(), sync);
    } catch (BrokerException e) {
        // if we fails to remove the message; undo store
        getDstMsgStore(to).removeMessage(message.getSysMessageID(), sync);
        Object[] args = { mid, from, to };
        logger.log(logger.ERROR, br.X_MOVE_MESSAGE_FAILED, args, e);
        throw e;
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) SysMessageID(com.sun.messaging.jmq.io.SysMessageID)

Example 28 with SysMessageID

use of com.sun.messaging.jmq.io.SysMessageID 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 29 with SysMessageID

use of com.sun.messaging.jmq.io.SysMessageID in project openmq by eclipse-ee4j.

the class JMSServiceImpl method fetchMessage.

/**
 * Fetch a message from the broker.
 *
 * @param connectionId The Id of the connection
 * @param sessionId The Id of the session
 * @param consumerId The Id of the consumer for which to fetch the message
 * @param timeout The maximum time to wait (in milliseconds) for a message to be available before returning.<br>
 * Note that the method must return immediately if there is a message available for this consumerId at the time the call
 * is made.<br>
 * <UL>
 * <LI>When timeout is positive, the call must wait for a maximum of the specificied number of milliseconds before
 * returning. If a message is available before the timeout expires, the method returns with the message as soon as it is
 * available.</LI>
 * <LI>When timeout is 0, the call must block until a message is available to return or until the session is stopped.
 * </LI>
 * <LI>When the timeout is negative (less than 0), the call must return immediately, with a message if one is available
 * or with a null, if a message is not available immediately.</LI>
 * </UL>
 * @param acknowledge If this is set to {@code true} then it implies that the caller is asking for the message to be
 * <b>acknowledged</b> before the method returns. If this operation is part of a transaction, the {@code transactionId}
 * parameter will be non-zero.
 * @param transactionId If non-zero, this is the transactionId in which to acknowledge the message being returned if the
 * {@code acknowledge} parameter is set to {@code true}.
 *
 * @return The JMSPacket which contains the message being returned.
 *
 * @throws JMSServiceException if broker encounters an error. {@link JMSServiceReply.Status} contains the reason for the
 * error.
 */
@Override
public JMSPacket fetchMessage(long connectionId, long sessionId, long consumerId, long timeout, boolean acknowledge, long transactionId) throws JMSServiceException {
    JMSPacket msg = null;
    IMQConnection cxn;
    Session session;
    cxn = checkConnectionId(connectionId, "fetchMessage");
    session = checkSessionId(sessionId, "fetchMessage");
    SessionListener slistener = getListener(session.getSessionUID());
    ConsumerUID conUID;
    try {
        conUID = new ConsumerUID(consumerId);
        msg = slistener.getNextConsumerPacket(conUID, timeout);
        if ((msg != null) && acknowledge) {
            TransactionUID txnUID = null;
            if (transactionId != 0) {
                txnUID = new TransactionUID(transactionId);
            }
            SysMessageID[] ids = new SysMessageID[1];
            ids[0] = ((Packet) msg).getSysMessageID();
            ConsumerUID[] cids = new ConsumerUID[1];
            cids[0] = conUID;
            Globals.getProtocol().acknowledge(cxn, txnUID, false, AckHandler.ACKNOWLEDGE_REQUEST, null, null, 0, ids, cids);
        }
    } catch (Exception e) {
        HashMap props = new HashMap();
        String errStr = "fetchMessage: Fetch Message failed. Connection ID: " + connectionId + ", session ID: " + sessionId + ", consumer ID: " + consumerId;
        logger.logStack(Logger.ERROR, errStr, e);
        props.put("JMQStatus", JMSServiceReply.Status.ERROR);
        throw new JMSServiceException(errStr, e, props);
    }
    return (msg);
}
Also used : ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) JMSPacket(com.sun.messaging.jmq.io.JMSPacket) SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) AccessControlException(java.security.AccessControlException) TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) SysMessageID(com.sun.messaging.jmq.io.SysMessageID) Session(com.sun.messaging.jmq.jmsserver.core.Session)

Example 30 with SysMessageID

use of com.sun.messaging.jmq.io.SysMessageID in project openmq by eclipse-ee4j.

the class StompSubscriberSession method closeSubscribers.

@Override
protected void closeSubscribers() {
    if (consumerId == 0L) {
        return;
    }
    try {
        SysMessageID lastseen = null;
        synchronized (unackedMessages) {
            int sz = unackedMessages.size();
            if (sz > 0) {
                lastseen = unackedMessages.get(sz - 1);
            }
        }
        jmsservice.deleteConsumer(connectionId, sessionId, consumerId, lastseen, false, null, stompconn.getClientID());
        consumerId = 0L;
        unackedMessages.clear();
    } catch (Exception e) {
        if (!isClosing() || getDEBUG()) {
            logger.logStack(logger.WARNING, e.getMessage(), e);
        }
    }
}
Also used : SysMessageID(com.sun.messaging.jmq.io.SysMessageID) ConsumerClosedNoDeliveryException(com.sun.messaging.jmq.jmsservice.ConsumerClosedNoDeliveryException) StompProtocolException(com.sun.messaging.bridge.api.StompProtocolException) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException)

Aggregations

SysMessageID (com.sun.messaging.jmq.io.SysMessageID)70 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)31 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)27 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)19 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)18 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)15 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)15 HashMap (java.util.HashMap)15 IOException (java.io.IOException)14 ArrayList (java.util.ArrayList)14 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)12 Iterator (java.util.Iterator)12 Map (java.util.Map)12 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)10 TransactionAcknowledgement (com.sun.messaging.jmq.jmsserver.data.TransactionAcknowledgement)10 AckEntryNotFoundException (com.sun.messaging.jmq.jmsserver.util.AckEntryNotFoundException)10 BrokerAddress (com.sun.messaging.jmq.jmsserver.core.BrokerAddress)9 DestinationList (com.sun.messaging.jmq.jmsserver.core.DestinationList)9 List (java.util.List)9 Packet (com.sun.messaging.jmq.io.Packet)8