1 /***
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 *
14 **/
15 package org.jencks.pool;
16
17 import javax.jms.MessageProducer;
18 import javax.jms.Destination;
19 import javax.jms.JMSException;
20 import javax.jms.Message;
21
22 /***
23 * A pooled {@link javax.jms.MessageProducer}
24 *
25 * @version $Revision$
26 */
27 public class PooledProducer implements MessageProducer
28 {
29 private MessageProducer messageProducer;
30 private Destination destination;
31 private int deliveryMode;
32 private boolean disableMessageID;
33 private boolean disableMessageTimestamp;
34 private int priority;
35 private long timeToLive;
36
37 public PooledProducer(final MessageProducer messageProducer,
38 final Destination destination) throws JMSException
39 {
40 this.messageProducer = messageProducer;
41 this.destination = destination;
42
43 this.deliveryMode = messageProducer.getDeliveryMode();
44 this.disableMessageID = messageProducer.getDisableMessageID();
45 this.disableMessageTimestamp = messageProducer.getDisableMessageTimestamp();
46 this.priority = messageProducer.getPriority();
47 this.timeToLive = messageProducer.getTimeToLive();
48 }
49
50 public void close() throws JMSException
51 {
52 }
53
54 public void send(final Destination destination, final Message message)
55 throws JMSException
56 {
57 send(destination, message, getDeliveryMode(), getPriority(), getTimeToLive());
58 }
59
60 public void send(final Message message) throws JMSException
61 {
62 send(this.destination, message, getDeliveryMode(), getPriority(), getTimeToLive());
63 }
64
65 public void send(final Message message, final int deliveryMode, final int priority,
66 final long timeToLive) throws JMSException
67 {
68 send(this.destination, message, deliveryMode, priority, timeToLive);
69 }
70
71 public void send(Destination destination, final Message message, final int deliveryMode,
72 final int priority, final long timeToLive) throws JMSException
73 {
74 if (destination == null) {
75 destination = this.destination;
76 }
77 MessageProducer messageProducer = getMessageProducer();
78
79
80 synchronized (messageProducer) {
81 messageProducer.send(destination, message, deliveryMode, priority, timeToLive);
82 }
83 }
84
85 public Destination getDestination()
86 {
87 return this.destination;
88 }
89
90 public int getDeliveryMode()
91 {
92 return this.deliveryMode;
93 }
94
95 public void setDeliveryMode(final int deliveryMode)
96 {
97 this.deliveryMode = deliveryMode;
98 }
99
100 public boolean getDisableMessageID()
101 {
102 return this.disableMessageID;
103 }
104
105 public void setDisableMessageID(final boolean disableMessageID)
106 {
107 this.disableMessageID = disableMessageID;
108 }
109
110 public boolean getDisableMessageTimestamp()
111 {
112 return this.disableMessageTimestamp;
113 }
114
115 public void setDisableMessageTimestamp(final boolean disableMessageTimestamp)
116 {
117 this.disableMessageTimestamp = disableMessageTimestamp;
118 }
119
120 public int getPriority()
121 {
122 return this.priority;
123 }
124
125 public void setPriority(final int priority)
126 {
127 this.priority = priority;
128 }
129
130 public long getTimeToLive()
131 {
132 return this.timeToLive;
133 }
134
135 public void setTimeToLive(final long timeToLive)
136 {
137 this.timeToLive = timeToLive;
138 }
139
140
141
142 protected MessageProducer getMessageProducer()
143 {
144 return this.messageProducer;
145 }
146 }