* @param message
* @throws JMSException
*/
private void dispatchToSession(ActiveMQMessage message) throws JMSException {
ServerSession serverSession = sessionPool.getServerSession();
Session nestedSession = serverSession.getSession();
ActiveMQSession session = null;
if (nestedSession instanceof ActiveMQSession) {
session = (ActiveMQSession) nestedSession;
} else if (nestedSession instanceof ActiveMQTopicSession) {
ActiveMQTopicSession topicSession = (ActiveMQTopicSession) nestedSession;
session = (ActiveMQSession) topicSession.getNext();
} else if (nestedSession instanceof ActiveMQQueueSession) {
ActiveMQQueueSession queueSession = (ActiveMQQueueSession) nestedSession;
session = (ActiveMQSession) queueSession.getNext();
} else {
throw new JMSException("Invalid instance of session obtained from server session." +
"The instance should be one of the following: ActiveMQSession, ActiveMQTopicSession, ActiveMQQueueSession. " +
"Found instance of " + nestedSession.getClass().getName());
}
session.dispatch(message);
serverSession.start();
}