Search in sources :

Example 51 with ConsumerUID

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

the class JMSServiceImpl method acknowledgeMessage.

/**
 * Acknowledge a message to 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 acknowledge the message
 *
 * @param sysMessageID The SysMessageID of the message to be acknowledged
 *
 * @param transactionId If non-zero, this is the transactionId in which to acknowledge the message.
 *
 * @param ackType The MessageAckType for this message acknowledgement
 *
 * @param retryCnt retry count of client runtime in delivery the message applicable to ackType DEAD_REQUEST
 * UNDELIVERABLE_REQUEST or non-null transactionId should be 0 otherwise
 * @param deadComment if ackType is DEAD_REQUEST
 * @param deadThr if ackType is DEAD_REQUEST
 *
 * @return The JMSServiceReply which contains status and information about the acknowledge request.
 *
 * @throws JMSServiceException If the Status returned for the acknowledgeMessage method is not
 * {@link JMSServiceReply.Status#OK}.<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 acknowledgeMessage(long connectionId, long sessionId, long consumerId, SysMessageID sysMessageID, long transactionId, MessageAckType ackType, int retryCnt, String deadComment, Throwable deadThr) throws JMSServiceException {
    boolean validate = false;
    TransactionUID txnUID = null;
    int brokerAckType;
    SysMessageID[] ids = null;
    ConsumerUID[] cids = null;
    JMSServiceReply reply;
    HashMap props = new HashMap();
    IMQConnection cxn;
    cxn = checkConnectionId(connectionId, "acknowledgeMessage");
    if (transactionId != 0) {
        txnUID = new TransactionUID(transactionId);
    }
    brokerAckType = convertToBrokerAckType(ackType);
    ids = new SysMessageID[1];
    ids[0] = sysMessageID;
    cids = new ConsumerUID[1];
    cids[0] = new ConsumerUID(consumerId);
    try {
        /*
             * TBD: validate - should the acks just be validated (normally false) deadThr - exception associated with a dead message
             * (should be null if ackType != DEAD) deadComment - the explaination why a message was marked dead (should be null if
             * ackType != DEAD) retryCnt - number of times a message was retried
             *
             */
        protocol.acknowledge(cxn, txnUID, validate, brokerAckType, deadThr, deadComment, retryCnt, ids, cids);
    } catch (Exception e) {
        String errStr = "acknowledgeMessage: Sending Acknowledgement failed. Connection ID: " + connectionId;
        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 : ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) 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)

Example 52 with ConsumerUID

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

the class JMSServiceImpl method sendAcknowledgement.

/**
 * Send a message acknowledgement to the broker. All messages acknowledged by the method must be of the same
 * MessageAckType
 *
 * @param connectionId The Id of the connection
 * @param ackType The type of the acknowledgement
 * @param acks The acknowledgements
 *
 * @throws JMSServiceException if the Status returned for the sendAcknowledgement method is not
 * {@link JMSServiceReply.Status#OK}
 */
@Override
public JMSServiceReply sendAcknowledgement(long connectionId, MessageAckType ackType, JMSPacket acks) throws JMSServiceException {
    boolean validate = false;
    TransactionUID txnUID = null;
    int brokerAckType;
    int deliverCnt = -1;
    SysMessageID[] ids = null;
    ConsumerUID[] cids = null;
    Throwable deadThr = null;
    String deadComment = null;
    JMSServiceReply reply;
    HashMap props = new HashMap();
    IMQConnection cxn;
    cxn = checkConnectionId(connectionId, "sendAcknowledgement");
    brokerAckType = convertToBrokerAckType(ackType);
    try {
        /*
             * TBD: txnUID - transaction id associated with the acknowledgement (or null if no transaction) validate - should the
             * acks just be validated (normally false) deadThr - exception associated with a dead message (should be null if ackType
             * != DEAD) deadComment - the explaination why a message was marked dead (should be null if ackType != DEAD) deliverCnt
             * - number of times a dead message was delivered (should be 0 if ackType != DEAD) ids - array of message ids to process
             * cids - array of consumerIDs associated with a message, should directly correspond to the same index in ids
             */
        protocol.acknowledge(cxn, txnUID, validate, brokerAckType, deadThr, deadComment, deliverCnt, ids, cids);
    } catch (Exception e) {
        String errStr = "sendAcknowledgement: Sending Acknowledgement failed. Connection ID: " + connectionId;
        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 : ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) 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)

Example 53 with ConsumerUID

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

the class JMSServiceImpl method setConsumerAsync.

/**
 * Configure a consumer for async or sync message consumption.
 * <p>
 * This method is used to enable and disable async delivery of messages from the broker to the client.
 *
 * @param connectionId The Id of the connection
 * @param sessionId The Id of the session
 * @param consumerId The Id of the consumer for which the async state is being set.
 * @param consumer The Consumer object that is to be used to deliver the message.<br>
 * If <b>non-null</b>, the consumer is being set into the <u>async</u> state and the server must start delivering
 * messagesto the {@code Consumer.deliver()} method when the connectionId and sessionId have been started via the
 * {@code startConnection} and {@code startSession} methods.<br>
 * If <b>null</b>, the consumer is being set into the <u>sync</u> state and the delivery of messages must stop.<br>
 * The session must first be stopped, before changing a consumer from the async state to the sync state. However, the
 * connection and session are not required to be stopped when a consumer is changed from the sync state, which is the
 * default for {@code addConsumer()}, to the async state.
 *
 * @throws JMSServiceException if the Status returned for the setConsumerAsync method is not
 * {@link JMSServiceReply.Status#OK}
 *
 * @see JMSService#startConnection
 * @see JMSService#startSession
 * @see JMSService#stopSession
 * @see Consumer#deliver
 *
 * @see JMSServiceReply.Status#NOT_FOUND
 * @see JMSServiceReply.Status#CONFLICT
 * @see JMSServiceReply.Status#ERROR
 */
@Override
public JMSServiceReply setConsumerAsync(long connectionId, long sessionId, long consumerId, Consumer consumer) throws JMSServiceException {
    JMSServiceReply reply;
    // IMQConnection cxn;
    HashMap props = new HashMap();
    Session session;
    com.sun.messaging.jmq.jmsserver.core.Consumer con;
    // cxn = checkConnectionId(connectionId, "setConsumerAsync");
    checkConnectionId(connectionId, "setConsumerAsync");
    session = checkSessionId(sessionId, "setConsumerAsync");
    try {
        ConsumerUID conUID = new ConsumerUID(consumerId);
        con = com.sun.messaging.jmq.jmsserver.core.Consumer.getConsumer(conUID);
        // register it as an asychronous listener
        SessionListener slistener = getListener(session.getSessionUID());
        slistener.setAsyncListener(con, consumer);
    } catch (Exception e) {
        String errStr = "setConsumerAsync: Set Async consumer 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);
    }
    props.put("JMQStatus", JMSServiceReply.Status.OK);
    props.put("JMQConsumerID", consumerId);
    reply = new JMSServiceReply(props);
    return (reply);
}
Also used : ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) AccessControlException(java.security.AccessControlException) Session(com.sun.messaging.jmq.jmsserver.core.Session)

Example 54 with ConsumerUID

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

the class SessionListener method setAsyncListener.

/**
 * Set this up as an AsyncListener
 */
public void setAsyncListener(com.sun.messaging.jmq.jmsserver.core.Consumer brokerC, Consumer target) {
    ConsumerUID cuid;
    /*
         * Target passed in may be null This is to indicate that the consumer has unregistered itself as an async consumer - may
         * go into sync mode.
         *
         */
    if (target == null) {
        // XXX Need to stop delivery of msgs - TBD
        // 
        // we are no longer asynchronous
        sync = true;
        // Remove Consumer from table
        // 
        cuid = brokerC.getConsumerUID();
        consumers.remove(cuid);
        return;
    }
    // we arent synchronous
    sync = false;
    // put the Consumer into a table so we can retrieve it when
    // a message is received
    cuid = brokerC.getConsumerUID();
    consumers.put(cuid, target);
    // set up a listener to wake up when the Session is Busy
    if (!sessionEvListenerRegistered) {
        sessionEL = session.addEventListener(this, EventType.BUSY_STATE_CHANGED, null);
        sessionEvListenerRegistered = true;
    }
    // ok - start the parsing thread
    if (!started) {
        Thread thr = new Thread(this, "Session" + session.getSessionUID());
        thr.start();
        started = true;
    }
}
Also used : ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID)

Example 55 with ConsumerUID

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

the class SessionListener method eventOccured.

/**
 * This method is called when a thread puts a message on a consumer or session. Its used to wake up the waiting thread
 * which might be in the process() [asynchronous] method or in the getNextConsumerPacket()[synchronous].
 */
@Override
public void eventOccured(EventType type, Reason r, Object target, Object oldval, Object newval, Object userdata) {
    if (type != EventType.BUSY_STATE_CHANGED) {
        // should never occur
        return;
    }
    // deal with consumers (the synchronous case)
    if (target instanceof com.sun.messaging.jmq.jmsserver.core.Consumer) {
        // notify on the ConsumerUID
        com.sun.messaging.jmq.jmsserver.core.Consumer cc = (com.sun.messaging.jmq.jmsserver.core.Consumer) target;
        ConsumerUID cuid = cc.getConsumerUID();
        if (cc.isBusy()) {
            synchronized (cuid) {
                // we cant check isBusy in here - we can deadlock
                // so instead look in the cuidNotify hashtable
                cuidNotify.add(cuid);
                // ok, we want to wake up the thread currently in
                // getNextConsumerPacket.
                // it is waiting on the ConsumerUID
                // so do a notify on ConsumerUID
                cuid.notifyAll();
            }
        }
        return;
    }
    // this wakes up the process thread which is blocked on SessionLock
    synchronized (sessionLock) {
        sessionLockNotify = true;
        sessionLock.notifyAll();
    }
}
Also used : ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID)

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