View Javadoc

1   /**
2    *
3    * Copyright 2003-2004 The Apache Software Foundation
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  //
19  // This source code implements specifications defined by the Java
20  // Community Process. In order to remain compliant with the specification
21  // DO NOT add / change / or delete method signatures!
22  //
23  
24  package javax.jms;
25  
26  /**
27   * @version $Rev: 46019 $ $Date: 2004-09-14 02:56:06 -0700 (Tue, 14 Sep 2004) $
28   */
29  public class QueueRequestor {
30      private QueueSession session;
31      private TemporaryQueue temporaryQueue;
32      private QueueSender sender;
33      private QueueReceiver receiver;
34  
35      public QueueRequestor(QueueSession session, Queue queue)
36          throws JMSException
37      {
38          super();
39  
40          if(queue == null) {
41              throw new InvalidDestinationException("Invalid queue");
42          }
43          
44          setSession(session);
45          setTemporaryQueue(session.createTemporaryQueue());
46          setSender(session.createSender(queue));
47          setReceiver(session.createReceiver(getTemporaryQueue()));
48      }
49  
50      public Message request(Message message) throws JMSException {
51          message.setJMSReplyTo(getTemporaryQueue());
52          getSender().send(message);
53          return getReceiver().receive();
54      }
55  
56      public void close() throws JMSException {
57          getSession().close();
58          getTemporaryQueue().delete();
59      }
60  
61      private void setReceiver(QueueReceiver receiver) {
62          this.receiver = receiver;
63      }
64  
65      private QueueReceiver getReceiver() {
66          return receiver;
67      }
68  
69      private void setSender(QueueSender sender) {
70          this.sender = sender;
71      }
72  
73      private QueueSender getSender() {
74          return sender;
75      }
76  
77      private void setSession(QueueSession session) {
78          this.session = session;
79      }
80  
81      private QueueSession getSession() {
82          return session;
83      }
84  
85      private void setTemporaryQueue(TemporaryQueue temporaryQueue) {
86          this.temporaryQueue = temporaryQueue;
87      }
88  
89      private TemporaryQueue getTemporaryQueue() {
90          return temporaryQueue;
91      }
92  }