KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > client > connector > OutboundProducer


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2004 - Bull SA
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  *
20  * Initial developer(s): Frederic Maistre (Bull SA)
21  * Contributor(s): Nicolas Tachker (Bull SA)
22  */

23 package org.objectweb.joram.client.connector;
24
25 import javax.jms.Destination JavaDoc;
26 import javax.jms.IllegalStateException JavaDoc;
27 import javax.jms.JMSException JavaDoc;
28 import javax.jms.Message JavaDoc;
29 import javax.jms.MessageProducer JavaDoc;
30
31 import org.objectweb.util.monolog.api.BasicLevel;
32
33 /**
34  * An <code>OutboundProducer</code> instance wraps a JMS producer
35  * for a component involved in outbound messaging.
36  */

37 public class OutboundProducer implements javax.jms.MessageProducer JavaDoc
38 {
39   /** The <code>OutboundSession</code> this producer belongs to. */
40   protected OutboundSession session;
41   /** The wrapped JMS producer. */
42   protected MessageProducer JavaDoc producer;
43
44   /** <code>false</code> if producer is no more valid. */
45   boolean valid = true;
46   
47
48   /**
49    * Constructs an <code>OutboundProducer</code> instance.
50    *
51    * @param producer The JMS producer to wrap.
52    * @param session The OutboundSession this producer belongs to.
53    */

54   OutboundProducer(MessageProducer JavaDoc producer, OutboundSession session) {
55     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
56       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
57                                     "OutboundProducer(" + producer +
58                                     ", " + session + ")");
59
60     this.producer = producer;
61     this.session = session;
62   }
63
64
65   /** Delegates the call to the wrapped producer. */
66   public void setDisableMessageID(boolean value) throws JMSException JavaDoc
67   {
68     checkValidity();
69     producer.setDisableMessageID(value);
70   }
71
72   /** Delegates the call to the wrapped producer. */
73   public void setDeliveryMode(int deliveryMode) throws JMSException JavaDoc
74   {
75     checkValidity();
76     producer.setDeliveryMode(deliveryMode);
77   }
78
79   /** Delegates the call to the wrapped producer. */
80   public void setPriority(int priority) throws JMSException JavaDoc
81   {
82     checkValidity();
83     producer.setPriority(priority);
84   }
85
86   /** Delegates the call to the wrapped producer. */
87   public void setTimeToLive(long timeToLive) throws JMSException JavaDoc
88   {
89     checkValidity();
90     producer.setTimeToLive(timeToLive);
91   }
92
93   /** Delegates the call to the wrapped producer. */
94   public void setDisableMessageTimestamp(boolean value) throws JMSException JavaDoc
95   {
96     checkValidity();
97     producer.setDisableMessageTimestamp(value);
98   }
99
100   /** Delegates the call to the wrapped producer. */
101   public Destination JavaDoc getDestination() throws JMSException JavaDoc
102   {
103     checkValidity();
104     return producer.getDestination();
105   }
106
107   /** Delegates the call to the wrapped producer. */
108   public boolean getDisableMessageID() throws JMSException JavaDoc
109   {
110     checkValidity();
111     return producer.getDisableMessageID();
112   }
113
114   /** Delegates the call to the wrapped producer. */
115   public int getDeliveryMode() throws JMSException JavaDoc
116   {
117     checkValidity();
118     return producer.getDeliveryMode();
119   }
120
121   /** Delegates the call to the wrapped producer. */
122   public int getPriority() throws JMSException JavaDoc
123   {
124     checkValidity();
125     return producer.getPriority();
126   }
127
128   /** Delegates the call to the wrapped producer. */
129   public long getTimeToLive() throws JMSException JavaDoc
130   {
131     checkValidity();
132     return producer.getTimeToLive();
133   }
134
135   /** Delegates the call to the wrapped producer. */
136   public boolean getDisableMessageTimestamp() throws JMSException JavaDoc
137   {
138     checkValidity();
139     return producer.getDisableMessageTimestamp();
140   }
141
142
143   /** Delegates the call to the wrapped producer. */
144   public void send(Message JavaDoc message) throws JMSException JavaDoc {
145     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
146       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " send(" + message + ")");
147
148     checkValidity();
149     producer.send(message);
150   }
151
152   /** Delegates the call to the wrapped producer. */
153   public void send(Message JavaDoc message,
154                    int deliveryMode,
155                    int priority,
156                    long timeToLive)
157     throws JMSException JavaDoc {
158     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
159       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " send(" + message +
160                                     ", " + deliveryMode +
161                                     ", " + priority +
162                                     ", " + timeToLive + ")");
163
164     checkValidity();
165     producer.send(message, deliveryMode, priority, timeToLive);
166   }
167
168   /** Delegates the call to the wrapped producer. */
169   public void send(Destination JavaDoc dest, Message JavaDoc message)
170     throws JMSException JavaDoc {
171     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
172       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
173                                     this + " send(" + dest + ", " + message + ")");
174
175     checkValidity();
176     producer.send(dest, message);
177   }
178
179   /** Delegates the call to the wrapped producer. */
180   public void send(Destination JavaDoc dest,
181                    Message JavaDoc message,
182                    int deliveryMode,
183                    int priority,
184                    long timeToLive)
185     throws JMSException JavaDoc {
186     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
187       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " send(" + dest +
188                                     ", " + message +
189                                     ", " + deliveryMode +
190                                     ", " + priority +
191                                     ", " + timeToLive + ")");
192
193     checkValidity();
194     producer.send(dest, message, deliveryMode, priority, timeToLive);
195   }
196
197   /** Delegates the call to the wrapped producer. */
198   public void close() throws JMSException JavaDoc {
199     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
200       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " close()");
201
202     valid = false;
203     producer.close();
204   }
205
206   /** Checks the validity of the subscriber instance. */
207   protected void checkValidity() throws IllegalStateException JavaDoc
208   {
209     session.checkValidity();
210
211     if (! valid)
212       throw new IllegalStateException JavaDoc("Invalid call on a closed producer.");
213   }
214 }
215
Popular Tags