KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exolab > jms > server > net > RemoteServerSession


1 /**
2  * Redistribution and use of this software and associated documentation
3  * ("Software"), with or without modification, are permitted provided
4  * that the following conditions are met:
5  *
6  * 1. Redistributions of source code must retain copyright
7  * statements and notices. Redistributions must also contain a
8  * copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the
11  * above copyright notice, this list of conditions and the
12  * following disclaimer in the documentation and/or other
13  * materials provided with the distribution.
14  *
15  * 3. The name "Exolab" must not be used to endorse or promote
16  * products derived from this Software without prior written
17  * permission of Exoffice Technologies. For written permission,
18  * please contact info@exolab.org.
19  *
20  * 4. Products derived from this Software may not be called "Exolab"
21  * nor may "Exolab" appear in their names without prior written
22  * permission of Exoffice Technologies. Exolab is a registered
23  * trademark of Exoffice Technologies.
24  *
25  * 5. Due credit should be given to the Exolab Project
26  * (http://www.exolab.org/).
27  *
28  * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32  * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39  * OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Copyright 2004-2005 (C) Exoffice Technologies Inc. All Rights Reserved.
42  *
43  * $Id: RemoteServerSession.java,v 1.2 2005/06/13 23:05:45 tanderson Exp $
44  */

45 package org.exolab.jms.server.net;
46
47 import java.rmi.RemoteException JavaDoc;
48 import java.util.List JavaDoc;
49 import javax.jms.JMSException JavaDoc;
50 import javax.transaction.xa.XAException JavaDoc;
51 import javax.transaction.xa.Xid JavaDoc;
52
53 import org.exolab.jms.client.JmsDestination;
54 import org.exolab.jms.client.JmsMessageListener;
55 import org.exolab.jms.client.JmsQueue;
56 import org.exolab.jms.client.JmsTopic;
57 import org.exolab.jms.message.MessageImpl;
58 import org.exolab.jms.net.orb.ORB;
59 import org.exolab.jms.net.orb.UnicastObject;
60 import org.exolab.jms.server.ServerSession;
61
62
63 /**
64  * Implementation of the {@link ServerSession} interface which wraps an {@link
65  * ServerSession} to make it remotable.
66  *
67  * @author <a HREF="mailto:tma@netspace.net.au">Tim Anderson</a>
68  * @version $Revision: 1.2 $ $Date: 2005/06/13 23:05:45 $
69  */

70 public class RemoteServerSession
71         extends UnicastObject
72         implements ServerSession {
73
74     /**
75      * The connection that created this.
76      */

77     private RemoteServerConnection _connection;
78
79     /**
80      * The session to delegate calls to.
81      */

82     private ServerSession _session;
83
84
85     /**
86      * Construct a new <code>RemoteServerSession</code>.
87      *
88      * @param orb the ORB to export this with
89      * @param connection the connection that created this
90      * @param session the session to delegate calls to
91      * @throws RemoteException if this can't be exported
92      */

93     public RemoteServerSession(ORB orb, RemoteServerConnection connection,
94                                ServerSession session)
95             throws RemoteException JavaDoc {
96         super(orb, null, true);
97         if (connection == null) {
98             throw new IllegalArgumentException JavaDoc("Argument 'connection' is null");
99         }
100         if (session == null) {
101             throw new IllegalArgumentException JavaDoc("Argument 'session' is null");
102         }
103         _connection = connection;
104         _session = session;
105     }
106
107     /**
108      * Close and release any resource allocated to this session.
109      *
110      * @throws JMSException if the session can't be closed
111      */

112     public synchronized void close() throws JMSException JavaDoc {
113         if (_session != null) {
114             try {
115                 _session.close();
116             } finally {
117                 try {
118                     unexportObject();
119                 } catch (RemoteException JavaDoc exception) {
120                     JMSException JavaDoc error = new JMSException JavaDoc(
121                             exception.getMessage());
122                     error.setLinkedException(exception);
123                     throw error;
124                 } finally {
125                     _connection.closed(this);
126                     _connection = null;
127                     _session = null;
128                 }
129             }
130         }
131     }
132
133     /**
134      * Acknowledge that a message has been processed.
135      *
136      * @param consumerId the identity of the consumer performing the ack
137      * @param messageId the message identifier
138      * @throws JMSException for any error
139      */

140     public void acknowledgeMessage(long consumerId, String JavaDoc messageId)
141             throws JMSException JavaDoc {
142         _session.acknowledgeMessage(consumerId, messageId);
143     }
144
145     /**
146      * Send a message.
147      *
148      * @param message the message to send
149      * @throws JMSException for any error
150      */

151     public void send(MessageImpl message) throws JMSException JavaDoc {
152         _session.send(message);
153     }
154
155     /**
156      * Send a set of messages.
157      *
158      * @param messages a list of <code>MessageImpl</code> instances
159      * @throws JMSException for any JMS error
160      */

161     public void send(List JavaDoc messages) throws JMSException JavaDoc {
162         _session.send(messages);
163     }
164
165     /**
166      * Return the next available message to the specified consumer.
167      * <p/>
168      * The <code>wait</code> parameter indicates how many milliseconds to wait
169      * for a message before returning. If <code>wait</code> is <code>0</code>
170      * then do not wait. If <code>wait</code> is <code>-1</code> then wait
171      * indefinitely for the next message.
172      *
173      * @param consumerId the consumer identifier
174      * @param wait number of milliseconds to wait
175      * @return the next message or <code>null</code>
176      * @throws JMSException for any JMS error
177      */

178     public MessageImpl receive(long consumerId, long wait)
179             throws JMSException JavaDoc {
180         return _session.receive(consumerId, wait);
181     }
182
183     /**
184      * Browse up to count messages.
185      *
186      * @param consumerId the consumer identifier
187      * @param count the maximum number of messages to receive
188      * @return a list of {@link MessageImpl} instances
189      * @throws JMSException for any JMS error
190      */

191     public List JavaDoc browse(long consumerId, int count) throws JMSException JavaDoc {
192         return _session.browse(consumerId, count);
193     }
194
195     /**
196      * Create a new message consumer.
197      *
198      * @param destination the destination to consume messages from
199      * @param selector the message selector. May be <code>null</code>
200      * @param noLocal if true, and the destination is a topic, inhibits the
201      * delivery of messages published by its own connection.
202      * The behavior for <code>noLocal</code> is not specified
203      * if the destination is a queue.
204      * @return the identifty of the message consumer
205      * @throws JMSException for any JMS error
206      */

207     public long createConsumer(JmsDestination destination, String JavaDoc selector,
208                                boolean noLocal) throws JMSException JavaDoc {
209         return _session.createConsumer(destination, selector, noLocal);
210     }
211
212     /**
213      * Create a new durable consumer. Durable consumers may only consume from
214      * non-temporary <code>Topic</code> destinations.
215      *
216      * @param topic the non-temporary <code>Topic</code> to subscribe to
217      * @param name the name used to identify this subscription
218      * @param selector only messages with properties matching the message
219      * selector expression are delivered. A value of null or an
220      * empty string indicates that there is no message selector
221      * for the message consumer.
222      * @param noLocal if set, inhibits the delivery of messages published by
223      * its own connection
224      * @return the identity of the durable consumer
225      * @throws JMSException for any JMS error
226      */

227     public long createDurableConsumer(JmsTopic topic, String JavaDoc name,
228                                       String JavaDoc selector, boolean noLocal)
229             throws JMSException JavaDoc {
230         return _session.createDurableConsumer(topic, name, selector, noLocal);
231     }
232
233     /**
234      * Create a queue browser for this session. This allows clients to browse a
235      * queue without removing any messages.
236      *
237      * @param queue the queue to browse
238      * @param selector the message selector. May be <code>null</code>
239      * @return the identity of the queue browser
240      * @throws JMSException for any JMS error
241      */

242     public long createBrowser(JmsQueue queue, String JavaDoc selector)
243             throws JMSException JavaDoc {
244         return _session.createBrowser(queue, selector);
245     }
246
247     /**
248      * Remove a message consumer.
249      *
250      * @param consumerId the identity of the consumer to remove
251      * @throws JMSException for any JMS error
252      */

253     public void removeConsumer(long consumerId) throws JMSException JavaDoc {
254         _session.removeConsumer(consumerId);
255     }
256
257     /**
258      * Unsubscribe a durable subscription.
259      *
260      * @param name the name used to identify the subscription
261      * @throws JMSException for any JMS error
262      */

263     public void unsubscribe(String JavaDoc name) throws JMSException JavaDoc {
264         _session.unsubscribe(name);
265     }
266
267     /**
268      * Start message delivery to this session.
269      *
270      * @throws JMSException for any JMS error
271      */

272     public void start() throws JMSException JavaDoc {
273         _session.start();
274     }
275
276     /**
277      * Stop message delivery to this session.
278      *
279      * @throws JMSException for any JMS error
280      */

281     public void stop() throws JMSException JavaDoc {
282         _session.stop();
283     }
284
285     /**
286      * Set the listener for this session. The listener is an object that
287      * implements MessageListener and is called back whenever a message for the
288      * session is present
289      *
290      * @param listener the message listener
291      */

292     public void setMessageListener(JmsMessageListener listener) {
293         _session.setMessageListener(listener);
294     }
295
296     /**
297      * Enable or disable asynchronous message delivery for a particular
298      * consumer.
299      *
300      * @param consumerId the consumer identifier
301      * @param enable true to enable; false to disable
302      * @throws JMSException for any JMS error
303      */

304     public void enableAsynchronousDelivery(long consumerId, boolean enable)
305             throws JMSException JavaDoc {
306         _session.enableAsynchronousDelivery(consumerId, enable);
307     }
308
309     /**
310      * Recover the session. This means all unacknowledged messages are resent
311      * with the redelivery flag set
312      *
313      * @throws JMSException if the session cannot be recovered
314      */

315     public void recover() throws JMSException JavaDoc {
316         _session.recover();
317     }
318
319     /**
320      * Commit the session which will send all the published messages and
321      * acknowledge all received messages.
322      *
323      * @throws JMSException if the session cannot be committed
324      */

325     public void commit() throws JMSException JavaDoc {
326         _session.commit();
327     }
328
329     /**
330      * Rollback the session, which will not acknowledge any of the sent
331      * messages.
332      *
333      * @throws JMSException if the session cannot be rolled back
334      */

335     public void rollback() throws JMSException JavaDoc {
336         _session.rollback();
337     }
338
339     /**
340      * Start work on behalf of a transaction branch specified in xid If TMJOIN
341      * is specified, the start is for joining a transaction previously seen by
342      * the resource manager.
343      *
344      * @param xid the xa transaction identity
345      * @param flags One of TMNOFLAGS, TMJOIN, or TMRESUME
346      * @throws XAException if there is a problem completing the call
347      */

348     public void start(Xid JavaDoc xid, int flags) throws XAException JavaDoc {
349         _session.start(xid, flags);
350     }
351
352     /**
353      * Ask the resource manager to prepare for a transaction commit of the
354      * transaction specified in xid.
355      *
356      * @param xid the xa transaction identity
357      * @return XA_RDONLY or XA_OK
358      * @throws XAException if there is a problem completing the call
359      */

360     public int prepare(Xid JavaDoc xid) throws XAException JavaDoc {
361         return _session.prepare(xid);
362     }
363
364     /**
365      * Commits an XA transaction that is in progress.
366      *
367      * @param xid the xa transaction identity
368      * @param onePhase true if it is a one phase commit
369      * @throws XAException if there is a problem completing the call
370      */

371     public void commit(Xid JavaDoc xid, boolean onePhase) throws XAException JavaDoc {
372         _session.commit(xid, onePhase);
373     }
374
375     /**
376      * Ends the work performed on behalf of a transaction branch. The resource
377      * manager disassociates the XA resource from the transaction branch
378      * specified and let the transaction be completedCommits an XA transaction
379      * that is in progress.
380      *
381      * @param xid the xa transaction identity
382      * @param flags one of TMSUCCESS, TMFAIL, or TMSUSPEND
383      * @throws XAException if there is a problem completing the call
384      */

385     public void end(Xid JavaDoc xid, int flags) throws XAException JavaDoc {
386         _session.end(xid, flags);
387     }
388
389     /**
390      * Tell the resource manager to forget about a heuristically completed
391      * transaction branch.
392      *
393      * @param xid the xa transaction identity
394      * @throws XAException if there is a problem completing the call
395      */

396     public void forget(Xid JavaDoc xid) throws XAException JavaDoc {
397         _session.forget(xid);
398     }
399
400     /**
401      * Obtain a list of prepared transaction branches from a resource manager.
402      * The transaction manager calls this method during recovery to obtain the
403      * list of transaction branches that are currently in prepared or
404      * heuristically completed states.
405      *
406      * @param flag One of TMSTARTRSCAN, TMENDRSCAN, TMNOFLAGS. TMNOFLAGS
407      * @return the set of Xids to recover
408      * @throws XAException - if there is a problem completing the call
409      */

410     public Xid JavaDoc[] recover(int flag) throws XAException JavaDoc {
411         return _session.recover(flag);
412     }
413
414     /**
415      * Inform the resource manager to roll back work done on behalf of a
416      * transaction branch.
417      *
418      * @param xid the xa transaction identity
419      * @throws XAException if there is a problem completing the call
420      */

421     public void rollback(Xid JavaDoc xid) throws XAException JavaDoc {
422         _session.rollback(xid);
423     }
424
425     /**
426      * Return the transaction timeout for this instance of the resource
427      * manager.
428      *
429      * @return the timeout in seconds
430      * @throws XAException if there is a problem completing the call
431      */

432     public int getTransactionTimeout() throws XAException JavaDoc {
433         return _session.getTransactionTimeout();
434     }
435
436     /**
437      * Set the current transaction timeout value for this XAResource instance.
438      *
439      * @param seconds timeout in seconds
440      * @return if the new transaction timeout was accepted
441      * @throws XAException if there is a problem completing the call
442      */

443     public boolean setTransactionTimeout(int seconds) throws XAException JavaDoc {
444         return _session.setTransactionTimeout(seconds);
445     }
446
447     /**
448      * Return the identity of the associated resource manager.
449      *
450      * @return the identity of the resource manager
451      * @throws XAException if there is a problem completing the call
452      */

453     public String JavaDoc getResourceManagerId() throws XAException JavaDoc {
454         return _session.getResourceManagerId();
455     }
456
457 }
458
Popular Tags