Search in sources :

Example 6 with Session

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

the class JMSServiceImpl method addConsumer.

/**
 * Add a consumer.
 * <p>
 * The initial state of the consumer must be the <u>sync</u> state.
 *
 * @param connectionId The Id of the connection in which to add the consumer
 * @param sessionId The Id of the session in which to add the consumer. The acknowledgement mode of the consumer will be
 * that of the session
 * @param dest The Destination from which the consumer will receive messages
 * @param selector The selector which will be used to filter messages
 * @param subscriptionName if dest is Topic and if either durable true or share true, the subscription name
 * @param durable if dest is Topic, if true, this is a durable subscription
 * @param share if dest is Topic, if true, this is a shared subscription
 * @param jmsshare if dest is Topic, if true and share true, this is a JMS 2.0 Shared Subscription if false and share
 * true, this is a MQ Shared Subscription
 *
 * @param clientId The clientId to use when this is a durable subscription with a non-null durableName. This clientId
 * must match the one that has been set on the connection previously.
 * @param noLocal If {@code true}, consumer does not wnat to receive messages produced on the same connection<br>
 * If {@code false}, consumer wants to receive messages produced on the same connection as well.
 *
 * @return The JMSServiceReply of the request to add a consumer
 *
 * @throws JMSServiceException if the Status returned for the addConsumer method is not
 * {@link JMSServiceReply.Status#OK}
 *
 * @see JMSService#setConsumerAsync
 *
 * @see JMSServiceReply.Status#getJMQConsumerID
 *
 * @see JMSServiceReply.Status#FORBIDDEN
 * @see JMSServiceReply.Status#BAD_REQUEST
 * @see JMSServiceReply.Status#NOT_FOUND
 * @see JMSServiceReply.Status#NOT_ALLOWED
 * @see JMSServiceReply.Status#PRECONDITION_FAILED
 * @see JMSServiceReply.Status#CONFLICT
 * @see JMSServiceReply.Status#ERROR
 */
@Override
public JMSServiceReply addConsumer(long connectionId, long sessionId, Destination dest, String selector, String subscriptionName, boolean durable, boolean share, boolean jmsshare, String clientId, boolean noLocal) throws JMSServiceException {
    JMSServiceReply reply;
    IMQConnection cxn;
    HashMap props = new HashMap();
    com.sun.messaging.jmq.jmsserver.core.Destination d;
    Session session;
    com.sun.messaging.jmq.jmsserver.core.Consumer con;
    int size = 1000;
    long consumerID = 0;
    cxn = checkConnectionId(connectionId, "addConsumer");
    session = checkSessionId(sessionId, "addConsumer");
    try {
        com.sun.messaging.jmq.jmsserver.core.Destination[] ds = Globals.getDestinationList().getDestination(cxn.getPartitionedStore(), dest.getName(), (dest.getType() == Destination.Type.QUEUE));
        d = ds[0];
        /*
             * size (prefetch size) is not needed here since the broker is going to call the client method with the messages, not
             * simply dump packets till a particular size is reached.
             */
        boolean useFlowControl = false;
        con = protocol.createConsumer(d, cxn, session, selector, clientId, subscriptionName, durable, share, jmsshare, noLocal, size, new Object().toString(), cxn.getAccessController().isAccessControlEnabled(), useFlowControl);
        consumerID = con.getConsumerUID().longValue();
    } catch (Exception e) {
        String errStr = "addConsumer: Add consumer failed. Connection ID: " + connectionId + ", session ID: " + sessionId;
        logger.logStack(Logger.ERROR, errStr, e);
        if (e instanceof SelectorFormatException) {
            props.put("JMQStatus", JMSServiceReply.Status.BAD_REQUEST);
        } else {
            props.put("JMQStatus", getErrorReplyStatus(e));
        }
        if (e instanceof BrokerException) {
            String ecode = ((BrokerException) e).getErrorCode();
            if (ecode != null) {
                props.put(JMSPacketProperties.JMQErrorCode, ecode);
            }
        }
        throw new JMSServiceException(errStr, e, props);
    }
    props.put("JMQStatus", JMSServiceReply.Status.OK);
    props.put("JMQConsumerID", consumerID);
    reply = new JMSServiceReply(props);
    return (reply);
}
Also used : SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) AccessControlException(java.security.AccessControlException) SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) Session(com.sun.messaging.jmq.jmsserver.core.Session)

Example 7 with Session

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

the class JMSServiceImpl method deleteConsumer.

/**
 * Delete a consumer.
 * <p>
 * If this operation is deleting a consumer that is a durable subscription, then the durableName <b>and</b> the clientId
 * must be non-null. In addition, the clientId must match the clientId that is currently set on the connection
 * identified by connectionId.
 *
 * @param connectionId The Id of the connection
 * @param sessionId The Id of the session
 * @param consumerId The Id of the consumer to delete
 * @param lastMessageSeen The last message received by this consumer which has been seen by the application. Set to null
 * if deleting a durable subscription.
 * @param durableName The name of the durable subscription to remove if the consumer is unsubscribing.
 * @param clientId The clientId of the connection
 *
 * @return The JMSServiceReply of the request to delete a consumer
 *
 * @throws JMSServiceException if the Status returned for the deleteConsumer method is not
 * {@link JMSServiceReply.Status#OK}
 *
 * @see JMSServiceReply.Status#FORBIDDEN
 * @see JMSServiceReply.Status#NOT_FOUND
 * @see JMSServiceReply.Status#PRECONDITION_FAILED
 * @see JMSServiceReply.Status#CONFLICT
 * @see JMSServiceReply.Status#ERROR
 */
@Override
public JMSServiceReply deleteConsumer(long connectionId, long sessionId, long consumerId, SysMessageID lastMessageSeen, boolean lastMessageSeenInTransaction, String durableName, String clientId) throws JMSServiceException {
    JMSServiceReply reply;
    IMQConnection cxn;
    Session session;
    HashMap props = new HashMap();
    cxn = checkConnectionId(connectionId, "deleteConsumer");
    session = checkSessionId(sessionId, "deleteConsumer");
    try {
        if (durableName == null) {
            ConsumerUID conUID = new ConsumerUID(consumerId);
            protocol.destroyConsumer(conUID, session, lastMessageSeen, lastMessageSeenInTransaction, cxn);
        } else {
            protocol.unsubscribe(durableName, clientId, cxn);
        }
    } catch (Exception e) {
        String errStr = "deleteConsumer: Delete consumer failed. Connection ID: " + connectionId + ", session ID: " + sessionId + ", consumer ID: " + consumerId + ", durable name: " + durableName + ", client ID: " + clientId;
        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) Session(com.sun.messaging.jmq.jmsserver.core.Session)

Example 8 with Session

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

the class IMQConnection method getConsumersIDs.

public List getConsumersIDs() {
    ArrayList cons = new ArrayList();
    Iterator itr = sessions.values().iterator();
    while (itr.hasNext()) {
        Session s = (Session) itr.next();
        Iterator citr = s.getConsumers();
        while (citr.hasNext()) {
            ConsumerSpi c = (ConsumerSpi) citr.next();
            cons.add(c.getConsumerUID());
        }
    }
    return cons;
}
Also used : ConsumerSpi(com.sun.messaging.jmq.jmsserver.plugin.spi.ConsumerSpi) Session(com.sun.messaging.jmq.jmsserver.core.Session)

Example 9 with Session

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

the class IMQDualThreadConnection method eventOccured.

@Override
public void eventOccured(EventType type, Reason r, Object target, Object oldval, Object newval, Object userdata) {
    // a session has something to do
    Session s = (Session) target;
    if (!runningMsgs) {
        // Connection is stopped so not sending messages to consumers
        return;
    }
    // Pull messages until not busy
    while (s.isBusy()) {
        // NOTE: this should work for queues because they require a resume flow from the client
        Packet emptyPacket = new Packet();
        s.fillNextPacket(emptyPacket);
        // write packet
        writePacket(emptyPacket, false);
    }
}
Also used : ReadWritePacket(com.sun.messaging.jmq.io.ReadWritePacket) Packet(com.sun.messaging.jmq.io.Packet) Session(com.sun.messaging.jmq.jmsserver.core.Session)

Example 10 with Session

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

the class ProtocolImpl method pauseSession.

/**
 * Pause a session
 * <P>
 * Packet:<B>STOP</b>
 * </p>
 *
 * @param uid session to pause
 */
@Override
public void pauseSession(SessionUID uid) throws BrokerException {
    Session ses = Session.getSession(uid);
    if (ses == null) {
        throw new BrokerException("No session for " + uid);
    }
    ses.pause("PROTOCOL");
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) Session(com.sun.messaging.jmq.jmsserver.core.Session)

Aggregations

Session (com.sun.messaging.jmq.jmsserver.core.Session)28 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)11 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)10 SessionUID (com.sun.messaging.jmq.jmsserver.core.SessionUID)8 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)7 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)7 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)7 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)6 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)5 Iterator (java.util.Iterator)4 ProducerUID (com.sun.messaging.jmq.jmsserver.core.ProducerUID)3 ConsumerSpi (com.sun.messaging.jmq.jmsserver.plugin.spi.ConsumerSpi)3 AccessControlException (java.security.AccessControlException)3 Packet (com.sun.messaging.jmq.io.Packet)2 ReadWritePacket (com.sun.messaging.jmq.io.ReadWritePacket)2 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)2 Producer (com.sun.messaging.jmq.jmsserver.core.Producer)2 TransactionList (com.sun.messaging.jmq.jmsserver.data.TransactionList)2 ConnectionUID (com.sun.messaging.jmq.jmsserver.service.ConnectionUID)2 IMQConnection (com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection)2