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