View Javadoc

    1   /***
    2    *
    3    * Copyright 2004 Hiram Chirino
    4    *
    5    * Licensed under the Apache License, Version 2.0 (the "License");
    6    * you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    *
    9    * http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   *
    17   **/
    18  package org.codehaus.activemq.ra;
    19
    20  import javax.jms.*;
    21  import java.io.Serializable;
    22
    23
    24  /***
    25   * Acts as a pass through proxy for a JMS Session object.
    26   * It intercepts events that are of interest of the ActiveMQManagedConnection.
    27   *
    28   * @version $Revision: 1.8 $
    29   */
    30  public class JMSSessionProxy implements Session, QueueSession, TopicSession {
    31
    32
    33      private final ActiveMQManagedConnection managedConnection;
    34      boolean closed=false;
    35
    36  	public JMSSessionProxy(ActiveMQManagedConnection managedConnection) {
    37  		this.managedConnection = managedConnection;
    38      }
    39
    40      /***
    41       * @throws JMSException
    42       */
    43      public void close() throws JMSException {
    44          cleanup();
    45      }
    46
    47      /***
    48       * Called by the ActiveMQManagedConnection to invalidate this proxy.
    49       */
    50      public void cleanup() {
    51      	closed=true;
    52      }
    53
    54      /***
    55       *
    56       */
    57      private Session getSession() throws JMSException {
    58          if (closed) {
    59              throw new JMSException("Session closed.");
    60          }
    61          return managedConnection.getPhysicalSession();
    62      }
    63
    64      /***
    65       * @throws JMSException
    66       */
    67      public void commit() throws JMSException {
    68          getSession().commit();
    69      }
    70
    71      /***
    72       * @param queue
    73       * @return
    74       * @throws JMSException
    75       */
    76      public QueueBrowser createBrowser(Queue queue) throws JMSException {
    77          return getSession().createBrowser(queue);
    78      }
    79
    80      /***
    81       * @param queue
    82       * @param messageSelector
    83       * @return
    84       * @throws JMSException
    85       */
    86      public QueueBrowser createBrowser(Queue queue, String messageSelector)
    87              throws JMSException {
    88          return getSession().createBrowser(queue, messageSelector);
    89      }
    90
    91      /***
    92       * @return
    93       * @throws JMSException
    94       */
    95      public BytesMessage createBytesMessage() throws JMSException {
    96          return getSession().createBytesMessage();
    97      }
    98
    99      /***
    100      * @param destination
    101      * @return
    102      * @throws JMSException
    103      */
    104     public MessageConsumer createConsumer(Destination destination)
    105             throws JMSException {
    106         return getSession().createConsumer(destination);
    107     }
    108
    109     /***
    110      * @param destination
    111      * @param messageSelector
    112      * @return
    113      * @throws JMSException
    114      */
    115     public MessageConsumer createConsumer(Destination destination,
    116                                           String messageSelector) throws JMSException {
    117         return getSession().createConsumer(destination, messageSelector);
    118     }
    119
    120     /***
    121      * @param destination
    122      * @param messageSelector
    123      * @param NoLocal
    124      * @return
    125      * @throws JMSException
    126      */
    127     public MessageConsumer createConsumer(Destination destination,
    128                                           String messageSelector, boolean NoLocal) throws JMSException {
    129         return getSession().createConsumer(destination, messageSelector, NoLocal);
    130     }
    131
    132     /***
    133      * @param topic
    134      * @param name
    135      * @return
    136      * @throws JMSException
    137      */
    138     public TopicSubscriber createDurableSubscriber(Topic topic, String name)
    139             throws JMSException {
    140         return getSession().createDurableSubscriber(topic, name);
    141     }
    142
    143     /***
    144      * @param topic
    145      * @param name
    146      * @param messageSelector
    147      * @param noLocal
    148      * @return
    149      * @throws JMSException
    150      */
    151     public TopicSubscriber createDurableSubscriber(Topic topic, String name,
    152                                                    String messageSelector, boolean noLocal) throws JMSException {
    153         return getSession().createDurableSubscriber(topic, name, messageSelector,
    154                 noLocal);
    155     }
    156
    157     /***
    158      * @return
    159      * @throws JMSException
    160      */
    161     public MapMessage createMapMessage() throws JMSException {
    162         return getSession().createMapMessage();
    163     }
    164
    165     /***
    166      * @return
    167      * @throws JMSException
    168      */
    169     public Message createMessage() throws JMSException {
    170         return getSession().createMessage();
    171     }
    172
    173     /***
    174      * @return
    175      * @throws JMSException
    176      */
    177     public ObjectMessage createObjectMessage() throws JMSException {
    178         return getSession().createObjectMessage();
    179     }
    180
    181     /***
    182      * @param object
    183      * @return
    184      * @throws JMSException
    185      */
    186     public ObjectMessage createObjectMessage(Serializable object)
    187             throws JMSException {
    188         return getSession().createObjectMessage(object);
    189     }
    190
    191     /***
    192      * @param destination
    193      * @return
    194      * @throws JMSException
    195      */
    196     public MessageProducer createProducer(Destination destination)
    197             throws JMSException {
    198         return getSession().createProducer(destination);
    199     }
    200
    201     /***
    202      * @param queueName
    203      * @return
    204      * @throws JMSException
    205      */
    206     public Queue createQueue(String queueName) throws JMSException {
    207         return getSession().createQueue(queueName);
    208     }
    209
    210     /***
    211      * @return
    212      * @throws JMSException
    213      */
    214     public StreamMessage createStreamMessage() throws JMSException {
    215         return getSession().createStreamMessage();
    216     }
    217
    218     /***
    219      * @return
    220      * @throws JMSException
    221      */
    222     public TemporaryQueue createTemporaryQueue() throws JMSException {
    223         return getSession().createTemporaryQueue();
    224     }
    225
    226     /***
    227      * @return
    228      * @throws JMSException
    229      */
    230     public TemporaryTopic createTemporaryTopic() throws JMSException {
    231         return getSession().createTemporaryTopic();
    232     }
    233
    234     /***
    235      * @return
    236      * @throws JMSException
    237      */
    238     public TextMessage createTextMessage() throws JMSException {
    239         return getSession().createTextMessage();
    240     }
    241
    242     /***
    243      * @param text
    244      * @return
    245      * @throws JMSException
    246      */
    247     public TextMessage createTextMessage(String text) throws JMSException {
    248         return getSession().createTextMessage(text);
    249     }
    250
    251     /***
    252      * @param topicName
    253      * @return
    254      * @throws JMSException
    255      */
    256     public Topic createTopic(String topicName) throws JMSException {
    257         return getSession().createTopic(topicName);
    258     }
    259
    260     /***
    261      * @return
    262      * @throws JMSException
    263      */
    264     public int getAcknowledgeMode() throws JMSException {
    265         return getSession().getAcknowledgeMode();
    266     }
    267
    268     /***
    269      * @return
    270      * @throws JMSException
    271      */
    272     public MessageListener getMessageListener() throws JMSException {
    273         return getSession().getMessageListener();
    274     }
    275
    276     /***
    277      * @return
    278      * @throws JMSException
    279      */
    280     public boolean getTransacted() throws JMSException {
    281         return getSession().getTransacted();
    282     }
    283
    284     /***
    285      * @throws JMSException
    286      */
    287     public void recover() throws JMSException {
    288         getSession().recover();
    289     }
    290
    291     /***
    292      * @throws JMSException
    293      */
    294     public void rollback() throws JMSException {
    295         getSession().rollback();
    296     }
    297
    298     /***
    299      * @param listener
    300      * @throws JMSException
    301      */
    302     public void setMessageListener(MessageListener listener)
    303             throws JMSException {
    304         getSession().setMessageListener(listener);
    305     }
    306
    307
    308     /***
    309      * @param name
    310      * @throws JMSException
    311      */
    312     public void unsubscribe(String name) throws JMSException {
    313         getSession().unsubscribe(name);
    314     }
    315
    316     /***
    317      * @param queue
    318      * @return
    319      * @throws JMSException
    320      */
    321     public QueueReceiver createReceiver(Queue queue) throws JMSException {
    322         return ((QueueSession) getSession()).createReceiver(queue);
    323     }
    324
    325     /***
    326      * @param queue
    327      * @param messageSelector
    328      * @return
    329      * @throws JMSException
    330      */
    331     public QueueReceiver createReceiver(Queue queue, String messageSelector)
    332             throws JMSException {
    333         return ((QueueSession) getSession()).createReceiver(queue, messageSelector);
    334     }
    335
    336     /***
    337      * @param queue
    338      * @return
    339      * @throws JMSException
    340      */
    341     public QueueSender createSender(Queue queue) throws JMSException {
    342         return ((QueueSession) getSession()).createSender(queue);
    343     }
    344
    345     /***
    346      * @param topic
    347      * @return
    348      * @throws JMSException
    349      */
    350     public TopicPublisher createPublisher(Topic topic) throws JMSException {
    351         return ((TopicSession) getSession()).createPublisher(topic);
    352     }
    353
    354     /***
    355      * @param topic
    356      * @return
    357      * @throws JMSException
    358      */
    359     public TopicSubscriber createSubscriber(Topic topic) throws JMSException {
    360         return ((TopicSession) getSession()).createSubscriber(topic);
    361     }
    362
    363     /***
    364      * @param topic
    365      * @param messageSelector
    366      * @param noLocal
    367      * @return
    368      * @throws JMSException
    369      */
    370     public TopicSubscriber createSubscriber(Topic topic,
    371                                             String messageSelector, boolean noLocal) throws JMSException {
    372         return ((TopicSession) getSession()).createSubscriber(topic, messageSelector, noLocal);
    373     }
    374
    375     /***
    376      * @see javax.jms.Session#run()
    377      */
    378     public void run() {
    379         throw new RuntimeException("Operation not supported.");
    380     }
    381
    382 }