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.activemq.ra;
018    
019    import javax.jms.Destination;
020    import javax.jms.JMSException;
021    import javax.jms.Message;
022    import javax.jms.MessageProducer;
023    import javax.jms.Queue;
024    import javax.jms.QueueSender;
025    import javax.jms.Topic;
026    import javax.jms.TopicPublisher;
027    
028    /**
029     * An implementation of {@link MessageProducer} which uses the ActiveMQ JCA ResourceAdapter's
030     * current thread's JMS {@link javax.jms.Session} to send messages.
031     *
032     * 
033     */
034    public class InboundMessageProducerProxy implements MessageProducer, QueueSender, TopicPublisher {
035        
036        private MessageProducer messageProducer;
037        private Destination destination;
038        private int deliveryMode;
039        private boolean disableMessageID;
040        private boolean disableMessageTimestamp;
041        private int priority;
042        private long timeToLive;
043    
044        public InboundMessageProducerProxy(MessageProducer messageProducer, Destination destination) throws JMSException {
045            this.messageProducer = messageProducer;
046            this.destination = destination;
047    
048            this.deliveryMode = messageProducer.getDeliveryMode();
049            this.disableMessageID = messageProducer.getDisableMessageID();
050            this.disableMessageTimestamp = messageProducer.getDisableMessageTimestamp();
051            this.priority = messageProducer.getPriority();
052            this.timeToLive = messageProducer.getTimeToLive();
053        }
054    
055        public void close() throws JMSException {
056            // do nothing as we just go back into the pool
057            // though lets reset the various settings which may have been changed
058            messageProducer.setDeliveryMode(deliveryMode);
059            messageProducer.setDisableMessageID(disableMessageID);
060            messageProducer.setDisableMessageTimestamp(disableMessageTimestamp);
061            messageProducer.setPriority(priority);
062            messageProducer.setTimeToLive(timeToLive);
063        }
064    
065        public Destination getDestination() throws JMSException {
066            return destination;
067        }
068    
069        public int getDeliveryMode() throws JMSException {
070            return messageProducer.getDeliveryMode();
071        }
072    
073        public boolean getDisableMessageID() throws JMSException {
074            return messageProducer.getDisableMessageID();
075        }
076    
077        public boolean getDisableMessageTimestamp() throws JMSException {
078            return messageProducer.getDisableMessageTimestamp();
079        }
080    
081        public int getPriority() throws JMSException {
082            return messageProducer.getPriority();
083        }
084    
085        public long getTimeToLive() throws JMSException {
086            return messageProducer.getTimeToLive();
087        }
088    
089        public void send(Destination destination, Message message) throws JMSException {
090            if (destination == null) {
091                destination = this.destination;
092            }
093            messageProducer.send(destination, message);
094        }
095    
096        public void send(Destination destination, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException {
097            if (destination == null) {
098                destination = this.destination;
099            }
100            messageProducer.send(destination, message, deliveryMode, priority, timeToLive);
101        }
102    
103        public void send(Message message) throws JMSException {
104            messageProducer.send(destination, message);
105        }
106    
107        public void send(Message message, int deliveryMode, int priority, long timeToLive) throws JMSException {
108            messageProducer.send(destination, message, deliveryMode, priority, timeToLive);
109        }
110    
111        public void setDeliveryMode(int i) throws JMSException {
112            messageProducer.setDeliveryMode(i);
113        }
114    
115        public void setDisableMessageID(boolean b) throws JMSException {
116            messageProducer.setDisableMessageID(b);
117        }
118    
119        public void setDisableMessageTimestamp(boolean b) throws JMSException {
120            messageProducer.setDisableMessageTimestamp(b);
121        }
122    
123        public void setPriority(int i) throws JMSException {
124            messageProducer.setPriority(i);
125        }
126    
127        public void setTimeToLive(long l) throws JMSException {
128            messageProducer.setTimeToLive(l);
129        }
130    
131        public Queue getQueue() throws JMSException {
132            return (Queue) messageProducer.getDestination();
133        }
134    
135        public void send(Queue arg0, Message arg1) throws JMSException {
136            messageProducer.send(arg0, arg1);
137        }
138    
139        public void send(Queue arg0, Message arg1, int arg2, int arg3, long arg4) throws JMSException {
140            messageProducer.send(arg0, arg1, arg2, arg3, arg4);
141        }
142    
143        public Topic getTopic() throws JMSException {
144            return (Topic) messageProducer.getDestination();
145        }
146    
147        public void publish(Message arg0) throws JMSException {
148            messageProducer.send(arg0);
149        }
150    
151        public void publish(Message arg0, int arg1, int arg2, long arg3) throws JMSException {
152            messageProducer.send(arg0, arg1, arg2, arg3);
153        }
154    
155        public void publish(Topic arg0, Message arg1) throws JMSException {
156            messageProducer.send(arg0, arg1);
157        }
158    
159        public void publish(Topic arg0, Message arg1, int arg2, int arg3, long arg4) throws JMSException {
160            messageProducer.send(arg0, arg1, arg2, arg3, arg4);
161        }
162    }