KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.walend.somnifugi;
2
3 import javax.jms.QueueSender JavaDoc;
4 import javax.jms.Queue JavaDoc;
5 import javax.jms.JMSException JavaDoc;
6 import javax.jms.Message JavaDoc;
7 import javax.jms.Destination JavaDoc;
8
9 /**
10 A sender end for a Queue. Get this from the QueueSession
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 SomniQueueSender
17     extends SomniMessageProducer
18     implements QueueSender JavaDoc
19 {
20     private SomniQueue queue;
21
22     protected SomniQueueSender(SomniQueue queue,String JavaDoc name,String JavaDoc connectionClientID)
23     {
24         super(queue,name,connectionClientID);
25         this.queue = queue;
26     }
27
28     /** Gets the queue associated with this <CODE>QueueSender</CODE>.
29  
30 @return this sender's queue
31  
32 @exception JMSException if the JMS provider fails to get the queue for
33                         this <CODE>QueueSender</CODE>
34                         due to some internal error.
35       */

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

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

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

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

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

189     
190     public Destination JavaDoc getDestination() throws JMSException JavaDoc
191     {
192         return getQueue();
193     }
194
195     /** Sends a message to a destination for an unidentified message producer,
196       * specifying delivery mode, priority and time to live.
197       *
198       * <P>Typically, a message producer is assigned a destination at creation
199       * time; however, the JMS API also supports unidentified message producers,
200       * which require that the destination be supplied every time a message is
201       * sent.
202       *
203       * @param destination the destination to send this message to
204       * @param message the message to send
205       * @param deliveryMode the delivery mode to use
206       * @param priority the priority for this message
207       * @param timeToLive the message's lifetime (in milliseconds)
208       *
209       * @exception JMSException if the JMS provider fails to send the message
210       * due to some internal error.
211       * @exception MessageFormatException if an invalid message is specified.
212       * @exception InvalidDestinationException if a client uses
213       * this method with an invalid destination.
214       *
215       * @see javax.jms.Session#createProducer
216       * @since 1.1
217       */

218
219     public void send(Destination JavaDoc destination,Message JavaDoc message,int deliveryMode,int priority,long timeToLive) throws JMSException JavaDoc
220     {
221         throw new UnsupportedOperationException JavaDoc("I don't know that I'll ever fill this method in.");
222     }
223
224      /**Sends a message to a destination for an unidentified message producer.
225       * Uses the <CODE>MessageProducer</CODE>'s default delivery mode, priority,
226       * and time to live.
227       *
228       * <P>Typically, a message producer is assigned a destination at creation
229       * time; however, the JMS API also supports unidentified message producers,
230       * which require that the destination be supplied every time a message is
231       * sent.
232       *
233       * @param destination the destination to send this message to
234       * @param message the message to send
235       *
236       * @exception JMSException if the JMS provider fails to send the message
237       * due to some internal error.
238       * @exception MessageFormatException if an invalid message is specified.
239       * @exception InvalidDestinationException if a client uses
240       * this method with an invalid destination.
241       * @exception java.lang.UnsupportedOperationException if a client uses this
242       * method with a <CODE>MessageProducer</CODE> that
243       * specified a destination at creation time.
244       *
245       * @see javax.jms.Session#createProducer
246       * @see javax.jms.MessageProducer
247       * @since 1.1
248       */

249  
250     public void send(Destination JavaDoc destination, Message JavaDoc message) throws JMSException JavaDoc
251     {
252         throw new UnsupportedOperationException JavaDoc("I don't know that I'll ever fill this method in.");
253     }
254
255
256     public void close()
257         throws JMSException JavaDoc
258     {
259         super.close();
260     }
261
262
263 }
264
265 /* Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006 David Walend
266 All rights reserved.
267
268 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
269
270 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
271
272 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.
273
274 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.
275
276 Credits in redistributions in source or binary forms must include a link to http://somnifugi.sourceforge.net .
277
278 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.
279 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.
280
281 =================================================================================
282
283 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>.
284  */

285
Popular Tags