
javax.jms.QueueRequestor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ow2-jms-2.0-spec Show documentation
Show all versions of ow2-jms-2.0-spec Show documentation
The Java Message Service (JMS) API, version 2.0
The newest version!
/**
* Copyright 2013 ScalAgent Distributed Technologies
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ---------------------------------------------------------------------
* $Id: QueueRequestor.java 6347 2013-03-13 08:52:02Z tachker $
* ---------------------------------------------------------------------
*/
package javax.jms;
/**
* The {@code QueueRequestor} helper class simplifies making service requests.
*
* @see javax.jms.TopicRequestor
*
* @version JMS 2.0
* @since JMS 1.0
*
*/
public class QueueRequestor {
private QueueSession session;
private TemporaryQueue temporaryQueue;
private QueueSender sender;
private QueueReceiver receiver;
/**
* Constructor for the {@code QueueRequestor} class.
*
* @exception JMSException if the JMS provider fails to create the {@code QueueRequestor} due to some internal error.
* @exception InvalidDestinationException if an invalid queue is specified.
*/
public QueueRequestor(QueueSession session, Queue queue) throws JMSException {
if (queue == null)
throw new InvalidDestinationException("Invalid queue");
this.session = session;
temporaryQueue = session.createTemporaryQueue();
sender = session.createSender(queue);
receiver = session.createReceiver(temporaryQueue);
}
/**
* Sends a request and waits for a reply. The temporary queue is used for the {@code JMSReplyTo} destination, and only one
* reply per request is expected.
*
* @param message the message to send
*
* @return the reply message
*
* @exception JMSException if the JMS provider fails to complete the request due to some internal error.
*/
public Message request(Message message) throws JMSException {
message.setJMSReplyTo(temporaryQueue);
sender.send(message);
return receiver.receive();
}
/**
* Closes the {@code QueueRequestor} and its session.
*
* @exception JMSException if the JMS provider fails to close the {@code QueueRequestor} due to some internal error.
*/
public void close() throws JMSException {
session.close();
temporaryQueue.delete();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy