KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > pool > PooledProducer


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.pool;
19
20 import org.apache.activemq.ActiveMQMessageProducer;
21
22 import javax.jms.Destination JavaDoc;
23 import javax.jms.JMSException JavaDoc;
24 import javax.jms.Message JavaDoc;
25 import javax.jms.MessageProducer JavaDoc;
26
27 /**
28  * A pooled {@link MessageProducer}
29  *
30  * @version $Revision: 1.1 $
31  */

32 public class PooledProducer implements MessageProducer {
33     private ActiveMQMessageProducer messageProducer;
34     private Destination JavaDoc destination;
35     private int deliveryMode;
36     private boolean disableMessageID;
37     private boolean disableMessageTimestamp;
38     private int priority;
39     private long timeToLive;
40
41     public PooledProducer(ActiveMQMessageProducer messageProducer, Destination JavaDoc destination) throws JMSException JavaDoc {
42         this.messageProducer = messageProducer;
43         this.destination = destination;
44
45         this.deliveryMode = messageProducer.getDeliveryMode();
46         this.disableMessageID = messageProducer.getDisableMessageID();
47         this.disableMessageTimestamp = messageProducer.getDisableMessageTimestamp();
48         this.priority = messageProducer.getPriority();
49         this.timeToLive = messageProducer.getTimeToLive();
50     }
51
52     public void close() throws JMSException JavaDoc {
53     }
54
55     public void send(Destination JavaDoc destination, Message JavaDoc message) throws JMSException JavaDoc {
56         send(destination, message, getDeliveryMode(), getPriority(), getTimeToLive());
57     }
58
59     public void send(Message JavaDoc message) throws JMSException JavaDoc {
60         send(destination, message, getDeliveryMode(), getPriority(), getTimeToLive());
61     }
62
63     public void send(Message JavaDoc message, int deliveryMode, int priority, long timeToLive) throws JMSException JavaDoc {
64         send(destination, message, deliveryMode, priority, timeToLive);
65     }
66
67     public void send(Destination JavaDoc destination, Message JavaDoc message, int deliveryMode, int priority, long timeToLive) throws JMSException JavaDoc {
68         if (destination == null) {
69             destination = this.destination;
70         }
71         ActiveMQMessageProducer messageProducer = getMessageProducer();
72
73         // just in case let only one thread send at once
74
synchronized (messageProducer) {
75             messageProducer.send(destination, message, deliveryMode, priority, timeToLive);
76         }
77     }
78
79     public Destination JavaDoc getDestination() {
80         return destination;
81     }
82
83     public int getDeliveryMode() {
84         return deliveryMode;
85     }
86
87     public void setDeliveryMode(int deliveryMode) {
88         this.deliveryMode = deliveryMode;
89     }
90
91     public boolean getDisableMessageID() {
92         return disableMessageID;
93     }
94
95     public void setDisableMessageID(boolean disableMessageID) {
96         this.disableMessageID = disableMessageID;
97     }
98
99     public boolean getDisableMessageTimestamp() {
100         return disableMessageTimestamp;
101     }
102
103     public void setDisableMessageTimestamp(boolean disableMessageTimestamp) {
104         this.disableMessageTimestamp = disableMessageTimestamp;
105     }
106
107     public int getPriority() {
108         return priority;
109     }
110
111     public void setPriority(int priority) {
112         this.priority = priority;
113     }
114
115     public long getTimeToLive() {
116         return timeToLive;
117     }
118
119     public void setTimeToLive(long timeToLive) {
120         this.timeToLive = timeToLive;
121     }
122
123     // Implementation methods
124
//-------------------------------------------------------------------------
125
protected ActiveMQMessageProducer getMessageProducer() {
126         return messageProducer;
127     }
128     
129     public String JavaDoc toString() {
130         return "PooledProducer { "+messageProducer+" }";
131     }
132
133 }
134
Popular Tags