001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.camel.component.jms;
018
019 import javax.jms.Destination;
020 import javax.jms.JMSException;
021 import javax.jms.Session;
022 import javax.jms.TemporaryTopic;
023
024 /**
025 * A <a href="http://activemq.apache.org/jms.html">JMS Endpoint</a>
026 * for working with a {@link TemporaryTopic}
027 * <p/>
028 * <b>Important:</b> Need to be really careful to always use the same Connection otherwise the destination goes stale
029 *
030 * @version $Revision: 19503 $
031 */
032 public class JmsTemporaryTopicEndpoint extends JmsEndpoint implements DestinationEndpoint {
033 private Destination jmsDestination;
034
035 public JmsTemporaryTopicEndpoint(String uri, JmsComponent component, String destination, JmsConfiguration configuration) {
036 super(uri, component, destination, true, configuration);
037 }
038
039 public JmsTemporaryTopicEndpoint(String endpointUri, String destination) {
040 super(endpointUri, destination);
041 }
042
043 public JmsTemporaryTopicEndpoint(TemporaryTopic jmsDestination) throws JMSException {
044 super("jms:temp:topic:" + jmsDestination.getTopicName(), null);
045 this.jmsDestination = jmsDestination;
046 setDestination(jmsDestination);
047 }
048
049 /**
050 * This endpoint is a singleton so that the temporary destination instances are shared across all
051 * producers and consumers of the same endpoint URI
052 *
053 * @return true
054 */
055 public boolean isSingleton() {
056 return true;
057 }
058
059 @Override
060 public Object getManagedObject(JmsEndpoint object) {
061 // We don't want to manage this temporary object
062 return null;
063 }
064
065 public synchronized Destination getJmsDestination(Session session) throws JMSException {
066 if (jmsDestination == null) {
067 jmsDestination = createJmsDestination(session);
068 }
069 return jmsDestination;
070 }
071
072 protected Destination createJmsDestination(Session session) throws JMSException {
073 return session.createTemporaryTopic();
074 }
075
076 }