All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.jms.listener.serversession.ServerSessionMessageListenerContainer102 Maven / Gradle / Ivy

There is a newer version: 5.3.34
Show newest version
/*
 * Copyright 2002-2006 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.jms.listener.serversession;

import javax.jms.Connection;
import javax.jms.ConnectionConsumer;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.ServerSessionPool;
import javax.jms.Session;
import javax.jms.Topic;
import javax.jms.TopicConnection;
import javax.jms.TopicConnectionFactory;

/**
 * A subclass of ServerSessionMessageListenerContainer that uses the JMS 1.0.2 specification,
 * rather than the JMS 1.1 methods used by ServerSessionMessageListenerContainer itself.
 * This class can be used for JMS 1.0.2 providers, offering the same facility as
 * ServerSessionMessageListenerContainer does for JMS 1.1 providers.
 *
 * @author Juergen Hoeller
 * @since 2.0
 */
public class ServerSessionMessageListenerContainer102 extends ServerSessionMessageListenerContainer {

	/**
	 * This implementation overrides the superclass method to use JMS 1.0.2 API.
	 */
	protected Connection createConnection() throws JMSException {
		if (isPubSubDomain()) {
			return ((TopicConnectionFactory) getConnectionFactory()).createTopicConnection();
		}
		else {
			return ((QueueConnectionFactory) getConnectionFactory()).createQueueConnection();
		}
	}

	/**
	 * This implementation overrides the superclass method to use JMS 1.0.2 API.
	 */
	protected ConnectionConsumer createConsumer(Connection con, Destination destination, ServerSessionPool pool)
			throws JMSException {

		if (isPubSubDomain()) {
			if (isSubscriptionDurable()) {
				return ((TopicConnection) con).createDurableConnectionConsumer(
						(Topic) destination, getDurableSubscriptionName(), getMessageSelector(), pool, getMaxMessagesPerTask());
			}
			else {
				return ((TopicConnection) con).createConnectionConsumer(
						(Topic) destination, getMessageSelector(), pool, getMaxMessagesPerTask());
			}
		}
		else {
			return ((QueueConnection) con).createConnectionConsumer(
					(Queue) destination, getMessageSelector(), pool, getMaxMessagesPerTask());
		}
	}

	/**
	 * This implementation overrides the superclass method to use JMS 1.0.2 API.
	 */
	protected Session createSession(Connection con) throws JMSException {
		if (isPubSubDomain()) {
			return ((TopicConnection) con).createTopicSession(isSessionTransacted(), getSessionAcknowledgeMode());
		}
		else {
			return ((QueueConnection) con).createQueueSession(isSessionTransacted(), getSessionAcknowledgeMode());
		}
	}

	/**
	 * This implementation overrides the superclass method to avoid using
	 * JMS 1.1's Session getAcknowledgeMode() method.
	 * The best we can do here is to check the setting on the listener container.
	 */
	protected boolean isClientAcknowledge(Session session) throws JMSException {
		return (getSessionAcknowledgeMode() == Session.CLIENT_ACKNOWLEDGE);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy