001 /** 002 * 003 * Copyright 2003-2004 The Apache Software Foundation 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 // 019 // This source code implements specifications defined by the Java 020 // Community Process. In order to remain compliant with the specification 021 // DO NOT add / change / or delete method signatures! 022 // 023 024 package javax.jms; 025 026 /** 027 * @version $Rev: 46019 $ $Date: 2004-09-14 02:56:06 -0700 (Tue, 14 Sep 2004) $ 028 */ 029 public class TopicRequestor { 030 private TopicSession session; 031 private Topic topic; 032 private TemporaryTopic temporaryTopic; 033 private TopicPublisher publisher; 034 private TopicSubscriber subscriber; 035 036 public TopicRequestor(TopicSession session, Topic topic) 037 throws JMSException { 038 super(); 039 setSession(session); 040 setTopic(topic); 041 setTemporaryTopic(session.createTemporaryTopic()); 042 setPublisher(session.createPublisher(topic)); 043 setSubscriber(session.createSubscriber(getTemporaryTopic())); 044 } 045 046 public Message request(Message message) throws JMSException { 047 message.setJMSReplyTo(getTemporaryTopic()); 048 getPublisher().publish(message); 049 return (getSubscriber().receive()); 050 } 051 052 public void close() throws JMSException { 053 getSession().close(); 054 getTemporaryTopic().delete(); 055 } 056 057 private void setPublisher(TopicPublisher publisher) { 058 this.publisher = publisher; 059 } 060 061 private TopicPublisher getPublisher() { 062 return publisher; 063 } 064 065 private void setSession(TopicSession session) { 066 this.session = session; 067 } 068 069 private TopicSession getSession() { 070 return session; 071 } 072 073 private void setSubscriber(TopicSubscriber subscriber) { 074 this.subscriber = subscriber; 075 } 076 077 private TopicSubscriber getSubscriber() { 078 return subscriber; 079 } 080 081 private void setTemporaryTopic(TemporaryTopic temporaryTopic) { 082 this.temporaryTopic = temporaryTopic; 083 } 084 085 private TemporaryTopic getTemporaryTopic() { 086 return temporaryTopic; 087 } 088 089 private void setTopic(Topic topic) { 090 this.topic = topic; 091 } 092 093 private Topic getTopic() { 094 return topic; 095 } 096 }