KickJava   Java API By Example, From Geeks To Geeks.

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


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.TopicConnection JavaDoc;
9 import javax.jms.TopicSession JavaDoc;
10 import javax.jms.JMSException JavaDoc;
11 import javax.jms.ConnectionConsumer JavaDoc;
12 import javax.jms.Topic 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
18 /**
19 A connection for SomniTopics. Use this to get SomniTopicSessions.
20
21 @author <a HREF="http://walend.net">David Walend</a> <a HREF="mailto:david@walend.net">david@walend.net</a>
22 @author @pwang@ added support for client acknowledgement.
23  */

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

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

99     public ConnectionConsumer JavaDoc createConnectionConsumer(Topic JavaDoc topic,String JavaDoc messageSelector,ServerSessionPool JavaDoc sessionPool,int maxMessages)
100         throws JMSException JavaDoc
101     {
102         throw new UnsupportedOperationException JavaDoc("Don't use somnifugi in an EJB app server. It plays with Threads.");
103     }
104
105     //Connection methods
106

107
108  /** Creates a <CODE>Session</CODE> object.
109       *
110       * @param transacted indicates whether the session is transacted
111       * @param acknowledgeMode indicates whether the consumer or the
112       * client will acknowledge any messages it receives; ignored if the session
113       * is transacted. Legal values are <code>Session.AUTO_ACKNOWLEDGE</code>,
114       * <code>Session.CLIENT_ACKNOWLEDGE</code>, and
115       * <code>Session.DUPS_OK_ACKNOWLEDGE</code>.
116       *
117       * @return a newly created session
118       *
119       * @exception JMSException if the <CODE>Connection</CODE> object fails
120       * to create a session due to some internal error or
121       * lack of support for the specific transaction
122       * and acknowledgement mode.
123       * @since 1.1
124       *
125       * @see Session#AUTO_ACKNOWLEDGE
126       * @see Session#CLIENT_ACKNOWLEDGE
127       * @see Session#DUPS_OK_ACKNOWLEDGE
128   
129       */

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

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

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

240
Popular Tags