KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > ra > InboundMessageProducerProxy


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.ra;
19
20 import javax.jms.Destination JavaDoc;
21 import javax.jms.JMSException JavaDoc;
22 import javax.jms.Message JavaDoc;
23 import javax.jms.MessageProducer JavaDoc;
24 import javax.jms.Queue JavaDoc;
25 import javax.jms.QueueSender JavaDoc;
26 import javax.jms.Topic JavaDoc;
27 import javax.jms.TopicPublisher JavaDoc;
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$
34  */

35 public class InboundMessageProducerProxy implements MessageProducer JavaDoc, QueueSender JavaDoc, TopicPublisher JavaDoc {
36     
37     private MessageProducer JavaDoc messageProducer;
38     private Destination JavaDoc destination;
39     private int deliveryMode;
40     private boolean disableMessageID;
41     private boolean disableMessageTimestamp;
42     private int priority;
43     private long timeToLive;
44
45     public InboundMessageProducerProxy(MessageProducer JavaDoc messageProducer, Destination JavaDoc destination) throws JMSException JavaDoc {
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 JavaDoc {
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 JavaDoc getDestination() throws JMSException JavaDoc {
67         return destination;
68     }
69
70     public int getDeliveryMode() throws JMSException JavaDoc {
71         return messageProducer.getDeliveryMode();
72     }
73
74     public boolean getDisableMessageID() throws JMSException JavaDoc {
75         return messageProducer.getDisableMessageID();
76     }
77
78     public boolean getDisableMessageTimestamp() throws JMSException JavaDoc {
79         return messageProducer.getDisableMessageTimestamp();
80     }
81
82     public int getPriority() throws JMSException JavaDoc {
83         return messageProducer.getPriority();
84     }
85
86     public long getTimeToLive() throws JMSException JavaDoc {
87         return messageProducer.getTimeToLive();
88     }
89
90     public void send(Destination JavaDoc destination, Message JavaDoc message) throws JMSException JavaDoc {
91         if (destination == null) {
92             destination = this.destination;
93         }
94         messageProducer.send(destination, message);
95     }
96
97     public void send(Destination JavaDoc destination, Message JavaDoc message, int deliveryMode, int priority, long timeToLive) throws JMSException JavaDoc {
98         if (destination == null) {
99             destination = this.destination;
100         }
101         messageProducer.send(destination, message, deliveryMode, priority, timeToLive);
102     }
103
104     public void send(Message JavaDoc message) throws JMSException JavaDoc {
105         messageProducer.send(destination, message);
106     }
107
108     public void send(Message JavaDoc message, int deliveryMode, int priority, long timeToLive) throws JMSException JavaDoc {
109         messageProducer.send(destination, message, deliveryMode, priority, timeToLive);
110     }
111
112     public void setDeliveryMode(int i) throws JMSException JavaDoc {
113         messageProducer.setDeliveryMode(i);
114     }
115
116     public void setDisableMessageID(boolean b) throws JMSException JavaDoc {
117         messageProducer.setDisableMessageID(b);
118     }
119
120     public void setDisableMessageTimestamp(boolean b) throws JMSException JavaDoc {
121         messageProducer.setDisableMessageTimestamp(b);
122     }
123
124     public void setPriority(int i) throws JMSException JavaDoc {
125         messageProducer.setPriority(i);
126     }
127
128     public void setTimeToLive(long l) throws JMSException JavaDoc {
129         messageProducer.setTimeToLive(l);
130     }
131
132     public Queue JavaDoc getQueue() throws JMSException JavaDoc {
133         return (Queue JavaDoc) messageProducer.getDestination();
134     }
135
136     public void send(Queue JavaDoc arg0, Message JavaDoc arg1) throws JMSException JavaDoc {
137         messageProducer.send(arg0, arg1);
138     }
139
140     public void send(Queue JavaDoc arg0, Message JavaDoc arg1, int arg2, int arg3, long arg4) throws JMSException JavaDoc {
141         messageProducer.send(arg0, arg1, arg2, arg3, arg4);
142     }
143
144     public Topic JavaDoc getTopic() throws JMSException JavaDoc {
145         return (Topic JavaDoc) messageProducer.getDestination();
146     }
147
148     public void publish(Message JavaDoc arg0) throws JMSException JavaDoc {
149         messageProducer.send(arg0);
150     }
151
152     public void publish(Message JavaDoc arg0, int arg1, int arg2, long arg3) throws JMSException JavaDoc {
153         messageProducer.send(arg0, arg1, arg2, arg3);
154     }
155
156     public void publish(Topic JavaDoc arg0, Message JavaDoc arg1) throws JMSException JavaDoc {
157         messageProducer.send(arg0, arg1);
158     }
159
160     public void publish(Topic JavaDoc arg0, Message JavaDoc arg1, int arg2, int arg3, long arg4) throws JMSException JavaDoc {
161         messageProducer.send(arg0, arg1, arg2, arg3, arg4);
162     }
163 }
164
Popular Tags