KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > walend > somnifugi > SomniTopicPublisher


1 package net.walend.somnifugi;
2
3 import javax.jms.TopicPublisher JavaDoc;
4 import javax.jms.Topic JavaDoc;
5 import javax.jms.JMSException JavaDoc;
6 import javax.jms.Message JavaDoc;
7 import javax.jms.Destination JavaDoc;
8
9 /**
10 A Publisher for a Topic.
11
12 @author <a HREF="http://walend.net">David Walend</a> <a HREF="mailto:david@walend.net">david@walend.net</a>
13 @author <a HREF="http://www.jumpi.org">Peter Klauser</a> <a HREF="mailto:klp@users.sourceforge.net">klp@users.sourceforge.net</a>
14  */

15
16 public class SomniTopicPublisher
17     extends SomniMessageProducer
18     implements TopicPublisher JavaDoc
19 {
20     private SomniTopic topic;
21
22     protected SomniTopicPublisher(SomniTopic topic,String JavaDoc name,String JavaDoc connectionClientID)
23     {
24         super(topic,name,connectionClientID);
25         this.topic = topic;
26     }
27
28     /** Gets the topic associated with this <CODE>TopicPublisher</CODE>.
29       *
30 @return this publisher's topic
31  
32 @exception JMSException if the JMS provider fails to get the topic for
33                         this <CODE>TopicPublisher</CODE>
34                         due to some internal error.
35       */

36     public Topic JavaDoc getTopic()
37         throws JMSException JavaDoc
38     {
39         synchronized(guard)
40             {
41                 return topic;
42             }
43     }
44
45     /** Publishes a message to the topic.
46 Uses the <CODE>TopicPublisher</CODE>'s default delivery mode, priority,
47 and time to live.
48       *
49 @param message the message to publish
50       *
51 @exception JMSException if the JMS provider fails to publish the message
52                         due to some internal error.
53 @exception MessageFormatException if an invalid message is specified.
54 @exception InvalidDestinationException if a client uses this method
55                         with a <CODE>TopicPublisher</CODE> with
56                         an invalid topic.
57 @exception java.lang.UnsupportedOperationException if a client uses this
58                         method with a <CODE>TopicPublisher</CODE> that
59                         did not specify a topic at creation time.
60
61 @see javax.jms.MessageProducer#getDeliveryMode()
62 @see javax.jms.MessageProducer#getTimeToLive()
63 @see javax.jms.MessageProducer#getPriority()
64       */

65     public void publish(Message JavaDoc message)
66         throws JMSException JavaDoc
67     {
68         synchronized(guard)
69             {
70                 publish(message,getDeliveryMode(),getPriority(),getTimeToLive());
71             }
72     }
73
74     /**
75 Publishes a message to the topic, specifying delivery mode,
76 priority, and time to live.
77
78 @param jmsMessage the message to publish
79 @param deliveryMode the delivery mode to use
80 @param priority the priority for this message
81 @param timeToLive the message's lifetime (in milliseconds)
82
83 @exception JMSException if the JMS provider fails to publish the message
84                         due to some internal error.
85 @exception MessageFormatException if an invalid message is specified.
86 @exception InvalidDestinationException if a client uses this method
87                         with a <CODE>TopicPublisher</CODE> with
88                         an invalid topic.
89 @exception java.lang.UnsupportedOperationException if a client uses this
90                         method with a <CODE>TopicPublisher</CODE> that
91                         did not specify a topic at creation time.
92       */

93     public void publish(Message JavaDoc jmsMessage,int deliveryMode,int priority,long timeToLive)
94         throws JMSException JavaDoc
95     {
96         publish(topic,jmsMessage,deliveryMode,priority,timeToLive);
97     }
98
99     /**
100 Publishes a message to a topic for an unidentified message producer.
101 Uses the <CODE>TopicPublisher</CODE>'s default delivery mode,
102 priority, and time to live.
103  
104 <P>Typically, a message producer is assigned a topic at creation
105 time; however, the JMS API also supports unidentified message producers,
106 which require that the topic be supplied every time a message is
107 published.
108       *
109 @param topic the topic to publish this message to
110 @param message the message to publish
111  
112 @exception JMSException if the JMS provider fails to publish the message
113                         due to some internal error.
114 @exception MessageFormatException if an invalid message is specified.
115 @exception InvalidDestinationException if a client uses
116                         this method with an invalid topic.
117
118 @see javax.jms.MessageProducer#getDeliveryMode()
119 @see javax.jms.MessageProducer#getTimeToLive()
120 @see javax.jms.MessageProducer#getPriority()
121       */

122     public void publish(Topic JavaDoc topic, Message JavaDoc message)
123         throws JMSException JavaDoc
124     {
125         synchronized(guard)
126             {
127                 publish(topic,message,getDeliveryMode(),getPriority(),getTimeToLive());
128             }
129     }
130
131     /**
132 Publishes a message to a topic for an unidentified message
133 producer, specifying delivery mode, priority and time to live.
134  
135 <P>Typically, a message producer is assigned a topic at creation
136 time; however, the JMS API also supports unidentified message producers,
137 which require that the topic be supplied every time a message is
138 published.
139       *
140 @param jmsTopic the topic to publish this message to
141 @param jmsMessage the message to publish
142 @param deliveryMode the delivery mode to use
143 @param priority the priority for this message
144 @param timeToLive the message's lifetime (in milliseconds)
145  
146 @exception JMSException if the JMS provider fails to publish the message
147                         due to some internal error.
148 @exception MessageFormatException if an invalid message is specified.
149 @exception InvalidDestinationException if a client uses
150                         this method with an invalid topic.
151       */

152     public void publish(Topic JavaDoc jmsTopic,Message JavaDoc jmsMessage,int deliveryMode,int priority,long timeToLive)
153         throws JMSException JavaDoc
154     {
155         if(!(jmsMessage instanceof SomniMessage))
156             {
157                 throw new ClassCastException JavaDoc("message must be an instance of SomniMessage, not "+jmsMessage.getClass().getName());
158             }
159         if(!(jmsTopic instanceof SomniTopic))
160             {
161                 throw new ClassCastException JavaDoc("topic must be an instance of SomniTopic, not "+jmsTopic.getClass().getName());
162             }
163
164         SomniMessage message = (SomniMessage)jmsMessage;
165         SomniTopic topic = (SomniTopic)jmsTopic;
166
167         synchronized(guard)
168             {
169                 try
170                     {
171                         setMessageDetails(message,deliveryMode,priority,timeToLive);
172                         topic.getPuttable().put(message);
173                         logSent(message,"published");
174                     }
175                 catch(InterruptedException JavaDoc ie)
176                     {
177                         throw new SomniInterruptedException(ie,message,topic);
178                     }
179             }
180     }
181
182     //MessageProducer methods
183
/** Gets the destination associated with this <CODE>MessageProducer</CODE>.
184       *
185       * @return this producer's <CODE>Destination/<CODE>
186       *
187       * @exception JMSException if the JMS provider fails to get the destination for
188       * this <CODE>MessageProducer</CODE>
189       * due to some internal error.
190       *@since 1.1
191       */

192     
193     public Destination JavaDoc getDestination() throws JMSException JavaDoc
194     {
195         return getTopic();
196     }
197
198       /** Sends a message using the <CODE>MessageProducer</CODE>'s
199       * default delivery mode, priority, and time to live.
200       *
201       * @param message the message to send
202       *
203       * @exception JMSException if the JMS provider fails to send the message
204       * due to some internal error.
205       * @exception MessageFormatException if an invalid message is specified.
206       * @exception InvalidDestinationException if a client uses
207       * this method with a <CODE>MessageProducer</CODE> with
208       * an invalid destination.
209       * @exception java.lang.UnsupportedOperationException if a client uses this
210       * method with a <CODE>MessageProducer</CODE> that did
211       * not specify a destination at creation time.
212       *
213       * @see javax.jms.Session#createProducer
214       * @see javax.jms.MessageProducer
215       *
216       * @since 1.1
217       */

218
219     public void send(Message JavaDoc message) throws JMSException JavaDoc
220     {
221         throw new IllegalStateException JavaDoc("I don't know that I'll ever fill this method in.");
222     }
223
224       /** Sends a message to the destination, specifying delivery mode, priority, and
225       * time to live.
226       *
227       * @param message the message to send
228       * @param deliveryMode the delivery mode to use
229       * @param priority the priority for this message
230       * @param timeToLive the message's lifetime (in milliseconds)
231       *
232       * @exception JMSException if the JMS provider fails to send the message
233       * due to some internal error.
234       * @exception MessageFormatException if an invalid message is specified.
235       * @exception InvalidDestinationException if a client uses
236       * this method with a <CODE>MessageProducer</CODE> with
237       * an invalid destination.
238       * @exception java.lang.UnsupportedOperationException if a client uses this
239       * method with a <CODE>MessageProducer</CODE> that did
240       * not specify a destination at creation time.
241       *
242       * @see javax.jms.Session#createProducer
243       * @since 1.1
244       */

245
246     public void send(Message JavaDoc message,int deliveryMode,int priority,long timeToLive) throws JMSException JavaDoc
247     {
248         throw new IllegalStateException JavaDoc("I don't know that I'll ever fill this method in.");
249     }
250
251     /** Sends a message to a destination for an unidentified message producer,
252       * specifying delivery mode, priority and time to live.
253       *
254       * <P>Typically, a message producer is assigned a destination at creation
255       * time; however, the JMS API also supports unidentified message producers,
256       * which require that the destination be supplied every time a message is
257       * sent.
258       *
259       * @param destination the destination to send this message to
260       * @param message the message to send
261       * @param deliveryMode the delivery mode to use
262       * @param priority the priority for this message
263       * @param timeToLive the message's lifetime (in milliseconds)
264       *
265       * @exception JMSException if the JMS provider fails to send the message
266       * due to some internal error.
267       * @exception MessageFormatException if an invalid message is specified.
268       * @exception InvalidDestinationException if a client uses
269       * this method with an invalid destination.
270       *
271       * @see javax.jms.Session#createProducer
272       * @since 1.1
273       */

274
275     public void send(Destination JavaDoc destination,Message JavaDoc message,int deliveryMode,int priority,long timeToLive) throws JMSException JavaDoc
276     {
277         throw new IllegalStateException JavaDoc("I don't know that I'll ever fill this method in.");
278     }
279
280      /**Sends a message to a destination for an unidentified message producer.
281       * Uses the <CODE>MessageProducer</CODE>'s default delivery mode, priority,
282       * and time to live.
283       *
284       * <P>Typically, a message producer is assigned a destination at creation
285       * time; however, the JMS API also supports unidentified message producers,
286       * which require that the destination be supplied every time a message is
287       * sent.
288       *
289       * @param destination the destination to send this message to
290       * @param message the message to send
291       *
292       * @exception JMSException if the JMS provider fails to send the message
293       * due to some internal error.
294       * @exception MessageFormatException if an invalid message is specified.
295       * @exception InvalidDestinationException if a client uses
296       * this method with an invalid destination.
297       * @exception java.lang.UnsupportedOperationException if a client uses this
298       * method with a <CODE>MessageProducer</CODE> that
299       * specified a destination at creation time.
300       *
301       * @see javax.jms.Session#createProducer
302       * @see javax.jms.MessageProducer
303       * @since 1.1
304       */

305  
306     public void send(Destination JavaDoc destination, Message JavaDoc message) throws JMSException JavaDoc
307     {
308         throw new IllegalStateException JavaDoc("I don't know that I'll ever fill this method in.");
309     }
310
311     public void close()
312         throws JMSException JavaDoc
313     {
314         super.close();
315     }
316 }
317
318 /* Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006 David Walend
319 All rights reserved.
320
321 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
322
323 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
324
325 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
326
327 Neither the name of the SomnifugiJMS Project, walend.net, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission from David Walend.
328
329 Credits in redistributions in source or binary forms must include a link to http://somnifugi.sourceforge.net .
330
331 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
332 The net.walend.somnifugi.sql92 package is modified code from the openmq project, https://mq.dev.java.net/ , Copyright (c) of Sun, and carries the CDDL license, repeated here: You can obtain a copy of the license at https://glassfish.dev.java.net/public/CDDLv1.0.html. See the License for the specific language governing permissions and limitations under the License.
333
334 =================================================================================
335
336 For more information and the latest version of this software, please see http://somnifugi.sourceforge.net and http://walend.net or email <a HREF="mailto:david@walend.net">david@walend.net</a>.
337  */

338
Popular Tags