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
20
21
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 TopicRequestor {
30 private TopicSession session;
31 private Topic topic;
32 private TemporaryTopic temporaryTopic;
33 private TopicPublisher publisher;
34 private TopicSubscriber subscriber;
35
36 public TopicRequestor(TopicSession session, Topic topic)
37 throws JMSException {
38 super();
39 setSession(session);
40 setTopic(topic);
41 setTemporaryTopic(session.createTemporaryTopic());
42 setPublisher(session.createPublisher(topic));
43 setSubscriber(session.createSubscriber(getTemporaryTopic()));
44 }
45
46 public Message request(Message message) throws JMSException {
47 message.setJMSReplyTo(getTemporaryTopic());
48 getPublisher().publish(message);
49 return (getSubscriber().receive());
50 }
51
52 public void close() throws JMSException {
53 getSession().close();
54 getTemporaryTopic().delete();
55 }
56
57 private void setPublisher(TopicPublisher publisher) {
58 this.publisher = publisher;
59 }
60
61 private TopicPublisher getPublisher() {
62 return publisher;
63 }
64
65 private void setSession(TopicSession session) {
66 this.session = session;
67 }
68
69 private TopicSession getSession() {
70 return session;
71 }
72
73 private void setSubscriber(TopicSubscriber subscriber) {
74 this.subscriber = subscriber;
75 }
76
77 private TopicSubscriber getSubscriber() {
78 return subscriber;
79 }
80
81 private void setTemporaryTopic(TemporaryTopic temporaryTopic) {
82 this.temporaryTopic = temporaryTopic;
83 }
84
85 private TemporaryTopic getTemporaryTopic() {
86 return temporaryTopic;
87 }
88
89 private void setTopic(Topic topic) {
90 this.topic = topic;
91 }
92
93 private Topic getTopic() {
94 return topic;
95 }
96 }