KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.walend.somnifugi;
2
3 import javax.naming.Referenceable JavaDoc;
4 import javax.naming.Reference JavaDoc;
5 import javax.naming.NamingException JavaDoc;
6 import javax.naming.Context JavaDoc;
7
8 import javax.jms.QueueConnection JavaDoc;
9 import javax.jms.QueueSession JavaDoc;
10 import javax.jms.JMSException JavaDoc;
11 import javax.jms.ConnectionConsumer JavaDoc;
12 import javax.jms.Queue JavaDoc;
13 import javax.jms.ServerSessionPool JavaDoc;
14 import javax.jms.ResourceAllocationException JavaDoc;
15 import javax.jms.Session JavaDoc;
16 import javax.jms.Destination JavaDoc;
17 import javax.jms.Topic JavaDoc;
18
19 /**
20 A connection for SomniQueues. Use this as a source of QueueSessions, and as a convinient thing to close.
21
22 @author <a HREF="http://walend.net">David Walend</a> <a HREF="mailto:david@walend.net">david@walend.net</a>
23 @author @pwang@ added support for client acknowledgement.
24  */

25
26 public class SomniQueueConnection
27     extends SomniConnection
28     implements QueueConnection JavaDoc, Referenceable JavaDoc
29 {
30
31     protected SomniQueueConnection(SomniQueueConnectionFactory factory,String JavaDoc clientID,Context JavaDoc context)
32     {
33         super(factory,clientID,context);
34     }
35
36     //SomniQueueConnection methods
37
/** Creates a <CODE>QueueSession</CODE> object.
38  
39 @param transacted indicates whether the session is transacted
40 @param acknowledgeMode indicates whether the consumer or the
41 client will acknowledge any messages it receives; ignored if the session
42 is transacted. Legal values are <code>Session.AUTO_ACKNOWLEDGE</code>,
43 <code>Session.CLIENT_ACKNOWLEDGE</code>, and
44 <code>Session.DUPS_OK_ACKNOWLEDGE</code>.
45  
46 @return a newly created queue session
47  
48 @exception JMSException if the <CODE>QueueConnection</CODE> object fails
49                         to create a session due to some internal error or
50                         lack of support for the specific transaction
51                         and acknowledgement mode.
52
53 @see Session#AUTO_ACKNOWLEDGE
54 @see Session#CLIENT_ACKNOWLEDGE
55 @see Session#DUPS_OK_ACKNOWLEDGE
56       */

57     public QueueSession JavaDoc createQueueSession(boolean transacted,int acknowledgeMode)
58         throws JMSException JavaDoc
59     {
60         if(transacted)
61             {
62                 throw new ResourceAllocationException JavaDoc("somnifugi sessions are nontransactional.");
63             }
64         if((acknowledgeMode!=Session.AUTO_ACKNOWLEDGE)&&(acknowledgeMode!=Session.CLIENT_ACKNOWLEDGE))
65             {
66                 throw new ResourceAllocationException JavaDoc("somnifugi sessions must be AUTO_ACKNOWLEDGE or CLIENT_ACKNOWLEDGE, not "+acknowledgeMode);
67             }
68         synchronized(guard)
69             {
70                 SomniQueueSession session = new SomniQueueSession(createSessionName(),(SomniExceptionListener)getExceptionListener(),isStarted(),getContext(),acknowledgeMode,getClientID());
71                 addSession(session);
72
73                 return session;
74             }
75     }
76
77     /** Creates a connection consumer for this connection (optional operation).
78 This is an expert facility not used by regular JMS clients.
79
80 @param queue the queue to access
81 @param messageSelector only messages with properties matching the
82 message selector expression are delivered. A value of null or
83 an empty string indicates that there is no message selector
84 for the message consumer.
85 @param sessionPool the server session pool to associate with this
86 connection consumer
87 @param maxMessages the maximum number of messages that can be
88 assigned to a server session at one time
89
90 @return the connection consumer
91  
92 @exception JMSException if the <CODE>QueueConnection</CODE> object fails
93                         to create a connection consumer due to some
94                         internal error or invalid arguments for
95                         <CODE>sessionPool</CODE> and
96                         <CODE>messageSelector</CODE>.
97 @exception InvalidDestinationException if an invalid queue is specified.
98 @exception InvalidSelectorException if the message selector is invalid.
99 @see <{ConnectionConsumer}>
100 @exception UnsupportedOperationException because you shouldn't use Somnifugi inside an EJB app server.
101       */

102     public ConnectionConsumer JavaDoc createConnectionConsumer(Queue JavaDoc queue,String JavaDoc messageSelector,ServerSessionPool JavaDoc sessionPool,int maxMessages)
103         throws JMSException JavaDoc
104     {
105         throw new UnsupportedOperationException JavaDoc("Don't use somnifugi in an EJB app server. It plays with Threads.");
106     }
107
108
109     //Connection methods
110
/** Creates a <CODE>Session</CODE> object.
111       *
112       * @param transacted indicates whether the session is transacted
113       * @param acknowledgeMode indicates whether the consumer or the
114       * client will acknowledge any messages it receives; ignored if the session
115       * is transacted. Legal values are <code>Session.AUTO_ACKNOWLEDGE</code>,
116       * <code>Session.CLIENT_ACKNOWLEDGE</code>, and
117       * <code>Session.DUPS_OK_ACKNOWLEDGE</code>.
118       *
119       * @return a newly created session
120       *
121       * @exception JMSException if the <CODE>Connection</CODE> object fails
122       * to create a session due to some internal error or
123       * lack of support for the specific transaction
124       * and acknowledgement mode.
125       * @since 1.1
126       *
127       * @see Session#AUTO_ACKNOWLEDGE
128       * @see Session#CLIENT_ACKNOWLEDGE
129       * @see Session#DUPS_OK_ACKNOWLEDGE
130   
131       */

132
133     public Session JavaDoc createSession(boolean transacted,int acknowledgeMode)
134         throws JMSException JavaDoc
135     {
136         return createQueueSession(transacted,acknowledgeMode);
137     }
138
139       /** Creates a connection consumer for this connection (optional operation).
140       * This is an expert facility not used by regular JMS clients.
141       *
142       * @param destination the destination to access
143       * @param messageSelector only messages with properties matching the
144       * message selector expression are delivered. A value of null or
145       * an empty string indicates that there is no message selector
146       * for the message consumer.
147       * @param sessionPool the server session pool to associate with this
148       * connection consumer
149       * @param maxMessages the maximum number of messages that can be
150       * assigned to a server session at one time
151       *
152       * @return the connection consumer
153       *
154       * @exception JMSException if the <CODE>Connection</CODE> object fails
155       * to create a connection consumer due to some
156       * internal error or invalid arguments for
157       * <CODE>sessionPool</CODE> and
158       * <CODE>messageSelector</CODE>.
159       * @exception InvalidDestinationException if an invalid destination is specified.
160       * @exception InvalidSelectorException if the message selector is invalid.
161       *
162       * @since 1.1
163       * @see javax.jms.ConnectionConsumer
164       */

165
166     public ConnectionConsumer JavaDoc createConnectionConsumer(Destination JavaDoc destination,
167                              String JavaDoc messageSelector,
168                              ServerSessionPool JavaDoc sessionPool,
169                  int maxMessages)
170                  throws JMSException JavaDoc
171     {
172         throw new UnsupportedOperationException JavaDoc("Don't use somnifugi in an EJB app server. It plays with Threads.");
173     }
174
175     /** Create a durable connection consumer for this connection (optional operation).
176       * This is an expert facility not used by regular JMS clients.
177       *
178       * @param topic topic to access
179       * @param subscriptionName durable subscription name
180       * @param messageSelector only messages with properties matching the
181       * message selector expression are delivered. A value of null or
182       * an empty string indicates that there is no message selector
183       * for the message consumer.
184       * @param sessionPool the server session pool to associate with this
185       * durable connection consumer
186       * @param maxMessages the maximum number of messages that can be
187       * assigned to a server session at one time
188       *
189       * @return the durable connection consumer
190       *
191       * @exception JMSException if the <CODE>Connection</CODE> object fails
192       * to create a connection consumer due to some
193       * internal error or invalid arguments for
194       * <CODE>sessionPool</CODE> and
195       * <CODE>messageSelector</CODE>.
196       * @exception InvalidDestinationException if an invalid destination
197       * is specified.
198       * @exception InvalidSelectorException if the message selector is invalid.
199       * @since 1.1
200       * @see javax.jms.ConnectionConsumer
201       */

202
203     public ConnectionConsumer JavaDoc createDurableConnectionConsumer(Topic JavaDoc topic,
204                     String JavaDoc subscriptionName,
205                                     String JavaDoc messageSelector,
206                                     ServerSessionPool JavaDoc sessionPool,
207                     int maxMessages)
208                              throws JMSException JavaDoc
209     {
210         throw new IllegalStateException JavaDoc("Don't use somnifugi in an EJB app server. It plays with Threads. Plus, why does a method in Connection take a Topic?");
211     }
212
213
214     //Referenceable methods
215
public Reference JavaDoc getReference()
216         throws NamingException JavaDoc
217     {
218         return new Reference JavaDoc(this.getClass().getName(),SomniQueueConnectionFactory.class.getName(),null);
219     }
220
221 }
222
223 /* Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006 David Walend
224 All rights reserved.
225
226 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
227
228 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
229
230 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.
231
232 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.
233
234 Credits in redistributions in source or binary forms must include a link to http://somnifugi.sourceforge.net .
235
236 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.
237 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.
238
239 =================================================================================
240
241 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>.
242  */

243
Popular Tags