use of com.sun.messaging.jmq.jmsserver.core.Session in project openmq by eclipse-ee4j.
the class JMSServiceImpl method checkSessionId.
/*
* Convenience method to check session ID. If the session ID is valid, the corresponding Session object will be
* returned. If not, a JMSServiceException will be thrown.
*/
private Session checkSessionId(long sessionId, String methodName) throws JMSServiceException {
Session ses = Session.getSession(new SessionUID(sessionId));
if (ses == null) {
String errStr = methodName + ": session ID not found: " + sessionId;
logger.log(Logger.ERROR, errStr);
HashMap props = new HashMap();
props.put("JMQStatus", JMSServiceReply.Status.ERROR);
throw new JMSServiceException(errStr, props);
}
return (ses);
}
use of com.sun.messaging.jmq.jmsserver.core.Session 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);
}
use of com.sun.messaging.jmq.jmsserver.core.Session in project openmq by eclipse-ee4j.
the class IMQConnection method getConsumers.
public List getConsumers() {
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);
}
}
return cons;
}
use of com.sun.messaging.jmq.jmsserver.core.Session in project openmq by eclipse-ee4j.
the class IMQConnection method getDebugState.
/**
* The debug state of this object
*/
@Override
public synchronized Hashtable getDebugState() {
Hashtable ht = super.getDebugState();
ht.put("pauseFlowCnt", String.valueOf(pauseFlowCnt));
ht.put("resumeFlowCnt", String.valueOf(resumeFlowCnt));
ht.put("producerCnt", String.valueOf(producers.size()));
if (producers.size() > 0) {
Vector v = new Vector();
Iterator itr = producers.keySet().iterator();
while (itr.hasNext()) {
ProducerUID p = (ProducerUID) itr.next();
v.add(p.toString());
}
ht.put("producers", v);
}
ht.put("msgsToConsumer", String.valueOf(msgsToConsumer));
ht.put("sessionCnt", String.valueOf(sessions.size()));
if (sessions.size() > 0) {
Vector v = new Vector();
Iterator itr = sessions.values().iterator();
while (itr.hasNext()) {
Session p = (Session) itr.next();
v.add(p.getSessionUID().toString());
}
ht.put("sessions", v);
}
ht.put("busySessionCnt", String.valueOf(busySessions.size()));
if (busySessions.size() > 0) {
Vector v = new Vector();
Iterator itr = busySessions.iterator();
while (itr.hasNext()) {
Session p = (Session) itr.next();
v.add(p.getSessionUID().toString());
}
ht.put("busySessions", v);
}
ht.put("tempDestCnt", String.valueOf(tmpDestinations.size()));
if (tmpDestinations.size() > 0) {
Vector v = new Vector();
Iterator itr = tmpDestinations.iterator();
while (itr.hasNext()) {
DestinationUID p = (DestinationUID) itr.next();
v.add(p.toString());
}
ht.put("tempDestinations", v);
}
ht.put("runningMsgs", String.valueOf(runningMsgs));
ht.put("paused", String.valueOf(paused));
ht.put("waitingForResumeFlow", String.valueOf(waitingForResumeFlow));
ht.put("flowCount", String.valueOf(flowCount));
ht.put("sentCount", String.valueOf(sent_count));
ht.put("userName", getUserName());
ht.put("remoteString", getRemoteConnectionString());
// ht.put("write_assigned", write_assigned.toString());
return ht;
}
use of com.sun.messaging.jmq.jmsserver.core.Session in project openmq by eclipse-ee4j.
the class IMQDualThreadConnection method startConnection.
/**
* start sending JMS messages to the connection
*/
@Override
public void startConnection() {
super.startConnection();
// added to fix CR 6879664
synchronized (sessions) {
Iterator itr = sessions.values().iterator();
while (itr.hasNext()) {
Session session = ((Session) itr.next());
// Pull messages until not busy
while (session.isBusy()) {
// NOTE: this should work for queues because they require a
// resume flow from the client
Packet emptyPacket = new Packet();
session.fillNextPacket(emptyPacket);
// write packet
writePacket(emptyPacket, false);
}
}
}
}
Aggregations