View Javadoc

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 2000-2003 (C) Exoffice Technologies Inc. All Rights Reserved.
42   *
43   * $Id: IpcJmsSessionConnection.java,v 1.28 2003/08/30 07:58:51 tanderson Exp $
44   *
45   * Date         Author  Changes
46   * $Date	    jimm    Created
47   */
48  package org.exolab.jms.server.mipc;
49  
50  import java.io.Serializable;
51  import java.util.Vector;
52  
53  import javax.jms.JMSException;
54  import javax.jms.Message;
55  import javax.transaction.xa.XAException;
56  import javax.transaction.xa.XAResource;
57  import javax.transaction.xa.Xid;
58  
59  import org.apache.commons.logging.Log;
60  import org.apache.commons.logging.LogFactory;
61  
62  import org.exolab.core.ipc.NotifierIfc;
63  import org.exolab.core.mipc.MultiplexConnectionIfc;
64  import org.exolab.jms.client.JmsQueue;
65  import org.exolab.jms.client.JmsTopic;
66  import org.exolab.jms.message.MessageImpl;
67  import org.exolab.jms.server.JmsServerConnection;
68  import org.exolab.jms.server.JmsServerConnectionManager;
69  import org.exolab.jms.server.JmsServerSession;
70  
71  
72  /***
73   * This is the server side receiver for JmsSession requests. All requests are
74   * unpacked and passed on to the appropriate JmsServerSession object.
75   *
76   * @version     $Revision: 1.28 $ $Date: 2003/08/30 07:58:51 $
77   * @author      <a href="mailto:mourikis@exolab.org">Jim Mourikis</a>
78   * @see         org.exolab.jms.server.mipc.IpcJmsReceiver
79   * @see	       	org.exolab.jms.server.JmsServerConnection
80   * @see	       	org.exolab.jms.server.JmsServerConnectionManager
81   * @see         org.exolab.jms.server.JmsServerSession
82   */
83  public class IpcJmsSessionConnection implements NotifierIfc {
84  
85      /***
86       * The server
87       */
88      private IpcJmsServer _server;
89  
90      /***
91       * The logger
92       */
93      private static final Log _log =
94          LogFactory.getLog(IpcJmsSessionConnection.class);
95  
96  
97      /***
98       * Construct a new <code>IpcJmsSessionConnection</code>
99       *
100      * @param server the server instance
101      */
102     public IpcJmsSessionConnection(IpcJmsServer server) {
103         _server = server;
104     }
105 
106     /***
107      * A new request has been received.
108      * Carry out the request, and pass back any relevent data.
109      *
110      * @param ob The data received
111      * @param id The unique IPC id of the connection
112      * @param The unique identifier of this connection.
113      * @return Object Return any requested result. This must never be null.
114      *
115      */
116     public Serializable notify(Object ob, String id) {
117         Vector v = (Vector) ob;
118         String func = (String) v.get(1);
119         JmsServerSession session = getSession(id, v);
120         Serializable result = null;
121         if (session == null) {
122             JMSException error = new JMSException(
123                 "Failed to process request " + func
124                 + ": session not found");
125             result = pack(Boolean.FALSE, error);
126         } else {
127             if (func.equals("close")) {
128                 result = close(session, getConnection(id));
129             } else if (func.equals("acknowledgeMessage")) {
130                 result = acknowledgeMessage(session, (Long) v.get(5),
131                                             (String) v.get(6));
132             } else if (func.equals("sendMessage")) {
133                 result = sendMessage(session, (Message) v.get(5));
134             } else if (func.equals("sendMessages")) {
135                 result = sendMessages(session, (Vector) v.get(5));
136             } else if (func.equals("receiveMessage")) {
137                 result = receiveMessage(session, (Long) v.get(5),
138                                         (Long) v.get(6));
139             } else if (func.equals("receiveMessages")) {
140                 result = receiveMessages(session, (Long) v.get(5),
141                                          (Integer) v.get(6));
142             } else if (func.equals("createQueue")) {
143                 result = createQueue(session, (JmsQueue) v.get(5));
144             } else if (func.equals("createTopic")) {
145                 result = createTopic(session, (JmsTopic) v.get(5));
146             } else if (func.equals("createReceiver")) {
147                 result = createReceiver(
148                     session, (JmsQueue) v.get(5), (Long) v.get(6),
149                     (String) v.get(7), getConnection(id), (String) v.get(8),
150                     (String) v.get(9), (String) v.get(10));
151             } else if (func.equals("createSender")) {
152                 result = createSender(session, (JmsQueue) v.get(5));
153             } else if (func.equals("createBrowser")) {
154                 result = createBrowser(
155                     session, (JmsQueue) v.get(5), (Long) v.get(6),
156                     (String) v.get(7), getConnection(id), (String) v.get(8),
157                     (String) v.get(9), (String) v.get(10));
158             } else if (func.equals("deleteReceiver")) {
159                 result = deleteReceiver(session, (Long) v.get(5));
160             } else if (func.equals("deleteSender")) {
161                 result = deleteSender(session, (Long) v.get(5));
162             } else if (func.equals("deleteBrowser")) {
163                 result = deleteBrowser(session, (Long) v.get(5));
164             } else if (func.equals("createSubscriber")) {
165                 result = createSubscriber(
166                     session, (JmsTopic) v.get(5), (String) v.get(6),
167                     (Long) v.get(7), (String) v.get(8), (Boolean) v.get(9),
168                     getConnection(id), (String) v.get(10), (String) v.get(11),
169                     (String) v.get(12));
170             } else if (func.equals("createPublisher")) {
171                 result = createPublisher(session, (JmsTopic) v.get(5));
172             } else if (func.equals("deleteSubscriber")) {
173                 result = deleteSubscriber(session, (Long) v.get(5));
174             } else if (func.equals("deletePublisher")) {
175                 result = deletePublisher(session, (JmsTopic) v.get(5));
176             } else if (func.equals("unsubscribe")) {
177                 result = unsubscribe(session, (String) v.get(5));
178             } else if (func.equals("stopMessageDelivery")) {
179                 result = stopMessageDelivery(session);
180             } else if (func.equals("startMessageDelivery")) {
181                 result = startMessageDelivery(session);
182             } else if (func.equals("recover")) {
183                 result = recover(session);
184             } else if (func.equals("commit")) {
185                 result = commit(session);
186             } else if (func.equals("rollback")) {
187                 result = rollback(session);
188             } else if (func.equals("xa_commit")) {
189                 result = XACommit(session, (Xid) v.get(5), (Boolean) v.get(6));
190             } else if (func.equals("xa_end")) {
191                 result = XAEnd(session, (Xid) v.get(5), (Integer) v.get(6));
192             } else if (func.equals("xa_forget")) {
193                 result = XAForget(session, (Xid) v.get(5));
194             } else if (func.equals("xa_getTransactionTimeout")) {
195                 result = XAGetTransactionTimeout(session);
196             } else if (func.equals("xa_recover")) {
197                 result = XARecover(session, (Integer) v.get(5));
198             } else if (func.equals("xa_rollback")) {
199                 result = XARollback(session, (Xid) v.get(5));
200             } else if (func.equals("xa_setTransactionTimeout")) {
201                 result = XASetTransactionTimeout(session, (Integer) v.get(5));
202             } else if (func.equals("xa_start")) {
203                 result = XAStart(session, (Xid) v.get(5), (Integer) v.get(6));
204             } else if (func.equals("xa_prepare")) {
205                 result = XAPrepare(session, (Xid) v.get(5));
206             } else if (func.equals("xa_getResourceManagerId")) {
207                 result = XAGetResourceManagerId(session);
208             } else if (func.equals("enableAsynchronousDelivery")) {
209                 result = enableAsynchronousDelivery(
210                     session, (Long) v.get(5), (String) v.get(6),
211                     (Boolean) v.get(7));
212             } else {
213                 JMSException error = new JMSException(
214                     "Unknown request received: " + func);
215                 result = pack(Boolean.FALSE, error);
216             }
217         }
218 
219         return result;
220     }
221 
222     /***
223      * The connection has been broken.              
224      *
225      * @param id The unique identifier of this connection.
226      */
227     public void disconnection(String id) {
228     }
229 
230     /***
231      * A convenience routine to get the session.
232      *
233      * @param id The unique IPC id of the connection
234      * @param v The vector containing the packed data from the client.
235      * @return JmsServerSession The required session or null if not found.
236      *
237      */
238     protected JmsServerSession getSession(String id, Vector v) {
239         // Lookup the connection using the unique connection id
240         JmsServerConnection connection =
241             JmsServerConnectionManager.instance().getConnection
242             ((String) v.get(2));
243 
244         JmsServerSession session = null;
245 
246         if (connection != null) {
247             session = connection.getSession((String) v.get(4));
248         } else if (_log.isDebugEnabled()) {
249             _log.debug("Failed to locate connection=" + v.get(2));
250         }
251         if (session == null && _log.isDebugEnabled()) {
252             _log.debug("Failed to locate session=" + v.get(4));
253         }
254 
255         return session;
256     }
257 
258     /***
259      * A convenience routine to get the MutliplexConnection.
260      *
261      * @param id The unique IPC id of the connection
262      * @return MultiplexConnection The connection associated with the ipc channel.
263      *
264      */
265     protected MultiplexConnectionIfc getConnection(String id) {
266         IpcServerChannel channel = IpcServerChannel.getServerChannel(id);
267         MultiplexConnectionIfc mc = null;
268         if (channel != null) {
269             mc = channel.getConnection();
270         }
271         return mc;
272     }
273 
274     /***
275      * A close session request has been received.
276      *
277      * @param session The session to close
278      * @return Vector The result of the request.
279      *
280      */
281     protected Vector close(JmsServerSession session,
282                            MultiplexConnectionIfc connection) {
283         try {
284             _server.removeConnection(session, connection);
285             session.close();
286         } catch (JMSException exception) {
287             return pack(Boolean.FALSE, exception);
288         }
289 
290         return pack(Boolean.TRUE, null);
291     }
292 
293     /***
294      * Acknowledge a JmsMessage
295      *
296      * @param session - the session the request is for
297      * @param clientId - the identity of the client that sent it
298      * @param id The id of the message
299      * @return Vector The result of the request.
300      *
301      */
302     protected Vector acknowledgeMessage(JmsServerSession session,
303                                         Long clientId, String id) {
304         try {
305             session.acknowledgeMessage(clientId.longValue(), id);
306         } catch (JMSException exception) {
307             return pack(Boolean.FALSE, exception);
308         }
309 
310         return pack(Boolean.TRUE, null);
311     }
312 
313     /***
314      * A JmsMessage has been sent.
315      *
316      * @param session The session the request is for.
317      * @param message The message to process.
318      * @return Vector The result of the request.
319      *
320      */
321     protected Vector sendMessage(JmsServerSession session, Message message) {
322         boolean persistent = ((MessageImpl) message).isPersistent();
323 
324         try {
325             session.sendMessage(message);
326         } catch (JMSException exception) {
327             return pack(Boolean.FALSE, exception);
328         }
329 
330         if (persistent) {
331             return pack(Boolean.TRUE, null);
332         }
333         // non-persistent messages do not need to send back anything.
334         return null;
335     }
336 
337     /***
338      * A collection of messages have been sent
339      *
340      * @param session - the session the request is for.
341      * @param messages - the messages to process.
342      * @return Vector - the result of the request.
343      *
344      */
345     protected Vector sendMessages(JmsServerSession session, Vector messages) {
346         try {
347             session.sendMessages(messages);
348         } catch (JMSException exception) {
349             return pack(Boolean.FALSE, exception);
350         }
351 
352         return pack(Boolean.TRUE, null);
353     }
354 
355     /***
356      * Receive a message from the provider
357      *
358      * @param session The session the request is for.
359      * @param clientId The client identity
360      * @param wait How long to wait
361      * @return Vector The result of the request.
362      *
363      */
364     protected Vector receiveMessage(JmsServerSession session, Long clientId,
365                                     Long wait) {
366         Message message = null;
367         try {
368             message = session.receiveMessage(clientId.longValue(),
369                                              wait.longValue());
370         } catch (JMSException exception) {
371             return pack(Boolean.FALSE, exception);
372         }
373 
374         return pack(Boolean.TRUE, message);
375     }
376 
377 
378     /***
379      * Receive upto count messages from the endpoint
380      *
381      * @param session - the session the request is for.
382      * @param clientId - the client identity
383      * @param count - max number of messages to receive
384      * @return Vector - the result of the request.
385      *
386      */
387     protected Vector receiveMessages(JmsServerSession session, Long clientId,
388                                      Integer count) {
389         Vector messages = null;
390         try {
391             messages = session.receiveMessages(clientId.longValue(),
392                                                count.intValue());
393         } catch (JMSException exception) {
394             return pack(Boolean.FALSE, exception);
395         }
396         
397         return pack(Boolean.TRUE, messages);
398     }
399 
400 
401     /***
402      * Create a new Queue.
403      *
404      * @param session The session the request is for.
405      * @param queue The queue to create
406      * @return Vector The result of the request.
407      *
408      */
409     protected Vector createQueue(JmsServerSession session, JmsQueue queue) {
410         try {
411             session.createQueue(queue);
412         } catch (JMSException exception) {
413             return pack(Boolean.FALSE, exception);
414         }
415 
416         return pack(Boolean.TRUE, null);
417     }
418 
419     /***
420      * Create a new topic
421      *
422      * @param session The session the request is for.
423      * @param topic The topic to create
424      * @return Vector The result of the request.
425      *
426      */
427     protected Vector createTopic(JmsServerSession session, JmsTopic topic) {
428         try {
429             session.createTopic(topic);
430         } catch (JMSException exception) {
431             return pack(Boolean.FALSE, exception);
432         }
433 
434         return pack(Boolean.TRUE, null);
435     }
436 
437     /***
438      * Create a new receiver
439      *
440      * @param session The session the request is for.
441      * @param queue The queue to create the reciver for
442      * @param consumerName The unique name of this consumer,
443      * only valid for persitent messages
444      * @param selector The selector to filter messages. This may be null.
445      * @param connection The MultiplexConnection to the machine the consumer is on
446      * @param host The host the client is running on. Only used for http.
447      * @param port The port the client is listening on. Only used for http
448      * @param url The url for the clients web server. Only used for http
449      * @return Vector The result of the request.
450      *
451      */
452     protected Vector createReceiver(
453         JmsServerSession session, JmsQueue queue,
454          Long consumerId, String selector, MultiplexConnectionIfc connection,
455          String host, String port, String url) {
456 
457         try {
458             session.createReceiver(queue, consumerId.longValue(), selector);
459             _server.addConnection(session, connection);
460         } catch (Exception exception) {
461             return pack(Boolean.FALSE, exception);
462         }
463 
464         return pack(Boolean.TRUE, null);
465     }
466 
467 
468     /***
469      * Create a new sender for the given queue.
470      *
471      * @param session The session the request is for.
472      * @param queue The queue the sender is sending to
473      * @return Vector The result of the request.
474      *
475      */
476     protected Vector createSender(JmsServerSession session, JmsQueue queue) {
477         try {
478             session.createSender(queue);
479         } catch (JMSException exception) {
480             return pack(Boolean.FALSE, exception);
481         }
482         return pack(Boolean.TRUE, null);
483     }
484 
485 
486     /***
487      * Create a new queue browser for the specified session and queue.
488      *
489      * @param session             session that the request is for
490      * @param queue               queue to browse
491      * @param clientId            the client identity
492      * @param selector            message selector. May be null
493      * @param connection          the connection to the remote machine
494      * @param host The host the client is running on. Only used for http.
495      * @param port The port the client is listening on. Only used for http
496      * @param url The url for the clients web server. Only used for http
497      * @return      Vector              result of the request
498      *
499      */
500     protected Vector createBrowser(JmsServerSession session,
501                                    JmsQueue queue, Long clientId, 
502                                    String selector,
503                                    MultiplexConnectionIfc connection, 
504                                    String host, String port,
505                                    String url) {
506 
507         try {
508             session.createBrowser(queue, clientId.longValue(), selector);
509             _server.addConnection(session, connection);
510         } catch (Exception exception) {
511             return pack(Boolean.FALSE, exception);
512         }
513         return pack(Boolean.TRUE, null);
514     }
515 
516     /***
517      * Delete the receiver for this queue.
518      *
519      * @param session  - the session the request is for.
520      * @param clientId -  the client id
521      * @return Vector The result of the request.
522      *
523      */
524     protected Vector deleteReceiver(JmsServerSession session, Long clientId) {
525         try {
526             session.deleteReceiver(clientId.longValue());
527         } catch (JMSException exception) {
528             return pack(Boolean.FALSE, exception);
529         }
530 
531         return pack(Boolean.TRUE, null);
532     }
533 
534     /***
535      * Delete the sender for this queue.
536      *
537      * @param session The session the request is for.
538      * @param clientId The identity of the client
539      * @return Vector The result of the request.
540      */
541     protected Vector deleteSender(JmsServerSession session, Long clientId) {
542         try {
543             session.deleteSender(clientId.longValue());
544         } catch (JMSException exception) {
545             return pack(Boolean.FALSE, exception);
546         }
547 
548         return pack(Boolean.TRUE, null);
549     }
550 
551     /***
552      * Delete the queue browser for the specified queue.
553      *
554      * @param       session             session that the request is for
555      * @param       clientId            the identity of the browser
556      * @return      Vector              The result of the request.
557      */
558     protected Vector deleteBrowser(JmsServerSession session, Long clientId) {
559         try {
560             session.deleteBrowser(clientId.longValue());
561         } catch (JMSException exception) {
562             return pack(Boolean.FALSE, exception);
563         }
564 
565         return pack(Boolean.TRUE, null);
566     }
567 
568     /***
569      * Create a new subscriber, and connect back to the client through the
570      * MultiplexConnection.
571      *
572      * @param session The session the request is for.
573      * @param topic The topic the subscriber is subscribing on
574      * @param name The unique name of this subscriber,
575      * only valid for persitent messages
576      * @param selector The selector to filter messages. This may be null.
577      * @param connection The MultiplexConnection to the machine the consumer is on
578      * @param host The host the client is running on. Only used for http.
579      * @param port The port the client is listening on. Only used for http
580      * @param url The url for the clients web server. Only used for http
581      * @return Vector The result of the request.
582      */
583     protected Vector createSubscriber(
584         JmsServerSession session, JmsTopic topic, String name, Long clientId,
585         String selector, Boolean noLocal, MultiplexConnectionIfc connection,
586         String host, String port, String url) {
587         try {
588             session.createSubscriber(topic, name, clientId.longValue(),
589                                      selector, noLocal.booleanValue());
590             _server.addConnection(session, connection);
591         } catch (Exception exception) {
592             return pack(Boolean.FALSE, exception);
593         }
594 
595         return pack(Boolean.TRUE, null);
596     }
597 
598 
599     /***
600      * Create a new publisher for the given topic.
601      *
602      * @param session The session the request is for.
603      * @param topic The topic the publisher is publishing to
604      * @return Vector The result of the request.
605      */
606     protected Vector createPublisher(JmsServerSession session,
607                                      JmsTopic topic) {
608         try {
609             session.createPublisher(topic);
610         } catch (JMSException exception) {
611             return pack(Boolean.FALSE, exception);
612         }
613 
614         return pack(Boolean.TRUE, null);
615     }
616 
617     /***
618      * Delete a subscriber for the given topic
619      *
620      * @param session The session the request is for.
621      * @param clientId - The client identity of the subscriber to delete
622      * @return Vector The result of the request.
623      */
624     protected Vector deleteSubscriber(JmsServerSession session,
625                                       Long clientId) {
626         try {
627             session.deleteSubscriber(clientId.longValue());
628         } catch (JMSException exception) {
629             return pack(Boolean.FALSE, exception);
630         }
631 
632         return pack(Boolean.TRUE, null);
633     }
634 
635     /***
636      * Delete a publisher for the given topic.
637      *
638      * @param session The session the request is for.
639      * @param topic The topic the publisher is publishing to
640      * @return Vector The result of the request.
641      *
642      */
643     protected Vector deletePublisher(JmsServerSession session,
644                                      JmsTopic topic) {
645         try {
646             session.deletePublisher(topic);
647         } catch (JMSException exception) {
648             return pack(Boolean.FALSE, exception);
649         }
650 
651         return pack(Boolean.TRUE, null);
652     }
653 
654     /***
655      * Unsubscribe a durable subscription
656      *
657      * @param       session             the session the request is for
658      * @param       name                the name used to identify the
659      *                                  subscription
660      * @return      Vector              the result of the request.
661      */
662     public Vector unsubscribe(JmsServerSession session, String name) {
663         try {
664             session.unsubscribe(name);
665         } catch (JMSException exception) {
666             return pack(Boolean.FALSE, exception);
667         }
668         return pack(Boolean.TRUE, null);
669     }
670 
671     /***
672      * Stop message delivery for this session.
673      *
674      * @param session The session the request is for.
675      * @return Vector The result of the request.
676      *
677      */
678     protected Vector stopMessageDelivery(JmsServerSession session) {
679         try {
680             session.stopMessageDelivery();
681         } catch (JMSException exception) {
682             return pack(Boolean.FALSE, exception);
683         }
684 
685         return pack(Boolean.TRUE, null);
686     }
687 
688 
689     /***
690      * Enable or disable asynchronous message delivery.
691      *
692      * @param session - the session the request is for.
693      * @param clientId - consumer identity
694      * @param enable - true to enable
695      * @return Vector - the result of the request.
696      *
697      */
698     protected Vector enableAsynchronousDelivery(JmsServerSession session,
699                                                 Long clientId, String id,
700                                                 Boolean enable) {
701         try {
702             session.enableAsynchronousDelivery(
703                 clientId.longValue(), id, enable.booleanValue());
704         } catch (JMSException exception) {
705             return pack(Boolean.FALSE, exception);
706         }
707 
708         return pack(Boolean.TRUE, null);
709     }
710 
711     /***
712      * Start message delivery for this session.
713      *
714      * @param session The session the request is for.
715      * @return Vector The result of the request.
716      *
717      */
718     protected Vector startMessageDelivery(JmsServerSession session) {
719         try {
720             session.startMessageDelivery();
721         } catch (JMSException exception) {
722             return pack(Boolean.FALSE, exception);
723         }
724 
725         return pack(Boolean.TRUE, null);
726     }
727 
728     /***
729      * recover the session
730      *
731      * @param session The session the request is for.
732      * @return Vector The result of the request.
733      */
734     protected Vector recover(JmsServerSession session) {
735         try {
736             session.recover();
737         } catch (JMSException exception) {
738             return pack(Boolean.FALSE, exception);
739         }
740 
741         return pack(Boolean.TRUE, null);
742     }
743 
744     /***
745      * commit the session
746      *
747      * @param session The session the request is for.
748      * @return Vector The result of the request.
749      */
750     protected Vector commit(JmsServerSession session) {
751         try {
752             session.commit();
753         } catch (JMSException exception) {
754             return pack(Boolean.FALSE, exception);
755         }
756 
757         return pack(Boolean.TRUE, null);
758     }
759 
760     /***
761      * rollback the session
762      *
763      * @param session The session the request is for.
764      * @return Vector The result of the request.
765      */
766     protected Vector rollback(JmsServerSession session) {
767         try {
768             session.rollback();
769         } catch (JMSException exception) {
770             return pack(Boolean.FALSE, exception);
771         }
772 
773         return pack(Boolean.TRUE, null);
774     }
775 
776     /***
777      * Commits an XA transaction that is in progress.
778      *
779      * @param xid - the xa transaction identity
780      * @param onePhase - treu if it is a one phase commit
781      * @return Vector
782      */
783     protected Vector XACommit(JmsServerSession session, Xid xid,
784                               Boolean onePhase) {
785         try {
786             session.commit(xid, onePhase.booleanValue());
787         } catch (Exception exception) {
788             return pack(Boolean.FALSE, exception);
789         }
790 
791         return pack(Boolean.TRUE, null);
792     }
793 
794     /***
795      * Ends the work performed on behalf of a transaction branch. The resource
796      * manager disassociates the XA resource from the transaction branch
797      * specified and let the transaction be completedCommits an XA transaction
798      * that is in progress.
799      *
800      * @param xid - the xa transaction identity
801      * @param flags - one of TMSUCCESS, TMFAIL, or TMSUSPEND
802      * @return Vector
803      */
804     protected Vector XAEnd(JmsServerSession session, Xid xid, Integer flags) {
805         try {
806             session.end(xid, flags.intValue());
807         } catch (Exception exception) {
808             return pack(Boolean.FALSE, exception);
809         }
810 
811         return pack(Boolean.TRUE, null);
812     }
813 
814     /***
815      * Tell the resource manager to forget about a heuristically completed
816      * transaction branch.
817      *
818      * @param xid - the xa transaction identity
819      * @return Vector
820      */
821     protected Vector XAForget(JmsServerSession session, Xid xid) {
822         try {
823             session.forget(xid);
824         } catch (Exception exception) {
825             return pack(Boolean.FALSE, exception);
826         }
827 
828         return pack(Boolean.TRUE, null);
829     }
830 
831     /***
832      * Return the transaction timeout for this instance of the resource
833      * manager.
834      *
835      * @return int - the timeout in seconds
836      * @return Vector
837      */
838     protected Vector XAGetTransactionTimeout(JmsServerSession session) {
839         int seconds = 0;
840         try {
841             seconds = session.getTransactionTimeout();
842         } catch (Exception exception) {
843             return pack(Boolean.FALSE, exception);
844         }
845 
846         return pack(Boolean.TRUE, new Integer(seconds));
847     }
848 
849     /***
850      * Ask the resource manager to prepare for a transaction commit of the
851      * transaction specified in xid
852      *
853      * @param xid - the xa transaction identity
854      * @return Vector
855      */
856     protected Vector XAPrepare(JmsServerSession session, Xid xid) {
857         try {
858             session.prepare(xid);
859         } catch (Exception exception) {
860             return pack(Boolean.FALSE, exception);
861         }
862 
863         return pack(Boolean.TRUE, null);
864     }
865 
866     /***
867      * Obtain a list of prepared transaction branches from a resource manager.
868      * The transaction manager calls this method during recovery to obtain the
869      * list of transaction branches that are currently in prepared or
870      * heuristically completed states.
871      *
872      * @param flag - One of TMSTARTRSCAN, TMENDRSCAN, TMNOFLAGS. TMNOFLAGS
873      * @param Xid[] - the set of Xids to recover
874      * @return Vector
875      */
876     public Vector XARecover(JmsServerSession session, Integer flag) {
877         Xid[] xids = null;
878         try {
879             xids = session.recover(flag.intValue());
880         } catch (Exception exception) {
881             return pack(Boolean.FALSE, exception);
882         }
883 
884         return pack(Boolean.TRUE, xids);
885     }
886 
887     /***
888      * Inform the resource manager to roll back work done on behalf of a
889      * transaction branch
890      *
891      * @param xid - the xa transaction identity
892      * @author Vector
893      */
894     protected Vector XARollback(JmsServerSession session, Xid xid) {
895         try {
896             session.rollback(xid);
897         } catch (Exception exception) {
898             return pack(Boolean.FALSE, exception);
899         }
900 
901         return pack(Boolean.TRUE, null);
902     }
903 
904     /***
905      * Set the current transaction timeout value for this XAResource instance.
906      *
907      * @param seconds - timeout in seconds
908      * @return boolean - true if the new transaction timeout was accepted
909      * @return Vector
910      */
911     protected Vector XASetTransactionTimeout(JmsServerSession session,
912                                              Integer seconds) {
913         boolean result = false;
914         try {
915             result = session.setTransactionTimeout(seconds.intValue());
916         } catch (Exception exception) {
917             return pack(Boolean.FALSE, exception);
918         }
919 
920         return pack(Boolean.TRUE, new Boolean(result));
921     }
922 
923     /***
924      * Start work on behalf of a transaction branch specified in xid If TMJOIN
925      * is specified, the start is for joining a transaction previously seen by
926      * the resource manager
927      *
928      * @param xid - the xa transaction identity
929      * @param flags - One of TMNOFLAGS, TMJOIN, or TMRESUME
930      * @return Vector
931      */
932     protected Vector XAStart(JmsServerSession session, Xid xid,
933                              Integer flags) {
934         try {
935             session.start(xid, flags.intValue());
936         } catch (Exception exception) {
937             return pack(Boolean.FALSE, exception);
938         }
939 
940         return pack(Boolean.TRUE, null);
941     }
942 
943     /***
944      * Return the identity of the resource manager.
945      *
946      * @param session - the session identity
947      * @return Vector
948      */
949     protected Vector XAGetResourceManagerId(JmsServerSession session) {
950         String id = null;
951         try {
952             id = session.getResourceManagerId();
953         } catch (Exception exception) {
954             return pack(Boolean.FALSE, exception);
955         }
956 
957         return pack(Boolean.TRUE, id);
958     }
959 
960     /***
961      * Pack all the data that is required by the server in a vector.
962      * Set the size of the vector to be exactly the right size for efficiency.
963      *
964      * @param success Boolean indicating success or failure of request.
965      * @param ob The Object being returned.
966      * @return Vector The vector containing all the data.
967      *
968      */
969     protected Vector pack(Boolean success, Object ob) {
970         Vector v = new Vector(2);
971         v.add(success);
972         v.add(ob);
973         return v;
974     }
975 
976 }
977