Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/activemq/ra/jms/MessageProducerProxy.java


1   /** 
2    * 
3    * Copyright 2004 Protique Ltd
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License"); 
6    * you may not use this file except in compliance with the License. 
7    * You may obtain a copy of the License at 
8    * 
9    * http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, 
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
14   * See the License for the specific language governing permissions and 
15   * limitations under the License. 
16   * 
17   **/
18  package org.activemq.ra.jms;
19  
20  import javax.jms.Destination;
21  import javax.jms.JMSException;
22  import javax.jms.Message;
23  import javax.jms.MessageProducer;
24  import javax.jms.Queue;
25  import javax.jms.QueueSender;
26  import javax.jms.Topic;
27  import javax.jms.TopicPublisher;
28  
29  /**
30   * An implementation of {@link MessageProducer} which uses the ActiveMQ JCA ResourceAdapter's
31   * current thread's JMS {@link javax.jms.Session} to send messages.
32   *
33   * @version $Revision: 1.1.1.1 $
34   */
35  public class MessageProducerProxy implements MessageProducer, QueueSender, TopicPublisher {
36      
37      private MessageProducer messageProducer;
38      private Destination destination;
39      private int deliveryMode;
40      private boolean disableMessageID;
41      private boolean disableMessageTimestamp;
42      private int priority;
43      private long timeToLive;
44  
45      public MessageProducerProxy(MessageProducer messageProducer, Destination destination) throws JMSException {
46          this.messageProducer = messageProducer;
47          this.destination = destination;
48  
49          this.deliveryMode = messageProducer.getDeliveryMode();
50          this.disableMessageID = messageProducer.getDisableMessageID();
51          this.disableMessageTimestamp = messageProducer.getDisableMessageTimestamp();
52          this.priority = messageProducer.getPriority();
53          this.timeToLive = messageProducer.getTimeToLive();
54      }
55  
56      public void close() throws JMSException {
57          // do nothing as we just go back into the pool
58          // though lets reset the various settings which may have been changed
59          messageProducer.setDeliveryMode(deliveryMode);
60          messageProducer.setDisableMessageID(disableMessageID);
61          messageProducer.setDisableMessageTimestamp(disableMessageTimestamp);
62          messageProducer.setPriority(priority);
63          messageProducer.setTimeToLive(timeToLive);
64      }
65  
66      public Destination getDestination() throws JMSException {
67          return destination;
68      }
69  
70      public int getDeliveryMode() throws JMSException {
71          return messageProducer.getDeliveryMode();
72      }
73  
74      public boolean getDisableMessageID() throws JMSException {
75          return messageProducer.getDisableMessageID();
76      }
77  
78      public boolean getDisableMessageTimestamp() throws JMSException {
79          return messageProducer.getDisableMessageTimestamp();
80      }
81  
82      public int getPriority() throws JMSException {
83          return messageProducer.getPriority();
84      }
85  
86      public long getTimeToLive() throws JMSException {
87          return messageProducer.getTimeToLive();
88      }
89  
90      public void send(Destination destination, Message message) throws JMSException {
91          if (destination == null) {
92              destination = this.destination;
93          }
94          messageProducer.send(destination, message);
95      }
96  
97      public void send(Destination destination, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException {
98          if (destination == null) {
99              destination = this.destination;
100         }
101         messageProducer.send(destination, message, deliveryMode, priority, timeToLive);
102     }
103 
104     public void send(Message message) throws JMSException {
105         messageProducer.send(destination, message);
106     }
107 
108     public void send(Message message, int deliveryMode, int priority, long timeToLive) throws JMSException {
109         messageProducer.send(destination, message, deliveryMode, priority, timeToLive);
110     }
111 
112     public void setDeliveryMode(int i) throws JMSException {
113         messageProducer.setDeliveryMode(i);
114     }
115 
116     public void setDisableMessageID(boolean b) throws JMSException {
117         messageProducer.setDisableMessageID(b);
118     }
119 
120     public void setDisableMessageTimestamp(boolean b) throws JMSException {
121         messageProducer.setDisableMessageTimestamp(b);
122     }
123 
124     public void setPriority(int i) throws JMSException {
125         messageProducer.setPriority(i);
126     }
127 
128     public void setTimeToLive(long l) throws JMSException {
129         messageProducer.setTimeToLive(l);
130     }
131 
132     public Queue getQueue() throws JMSException {
133         return (Queue) messageProducer.getDestination();
134     }
135 
136     public void send(Queue arg0, Message arg1) throws JMSException {
137         messageProducer.send(arg0, arg1);
138     }
139 
140     public void send(Queue arg0, Message arg1, int arg2, int arg3, long arg4) throws JMSException {
141         messageProducer.send(arg0, arg1, arg2, arg3, arg4);
142     }
143 
144     public Topic getTopic() throws JMSException {
145         return (Topic) messageProducer.getDestination();
146     }
147 
148     public void publish(Message arg0) throws JMSException {
149         messageProducer.send(arg0);
150     }
151 
152     public void publish(Message arg0, int arg1, int arg2, long arg3) throws JMSException {
153         messageProducer.send(arg0, arg1, arg2, arg3);
154     }
155 
156     public void publish(Topic arg0, Message arg1) throws JMSException {
157         messageProducer.send(arg0, arg1);
158     }
159 
160     public void publish(Topic arg0, Message arg1, int arg2, int arg3, long arg4) throws JMSException {
161         messageProducer.send(arg0, arg1, arg2, arg3, arg4);
162     }
163 }