org.codehaus.activemq.bean
Class Requestor

java.lang.Object
  extended byorg.codehaus.activemq.bean.Requestor

public class Requestor
extends Object

A helper class for performing remote method invocations over JMS. This class is a polymorphic version of the QueueRequestor and TopicRequestor that ship with the JMS API which take advantage of the polymorphism of JMS 1.1 and which also supports timeouts.

Version:
$Revision: 1.1 $

Constructor Summary
Requestor(Session session, Destination destination)
          Constructor for the Requestor class.
 
Method Summary
 void close()
          Closes the Requestor and its session.
protected  TemporaryQueue createTemporaryDestination(Session session)
           
 long getMaximumTimeout()
           
 Message request(Message message)
          Sends a request and waits for a reply.
 Message request(Message message, long timeout)
          Sends a request and waits for a reply up to a maximum timeout.
 void setMaximumTimeout(long maximumTimeout)
          Sets the maximum default timeout used for remote requests.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Requestor

public Requestor(Session session,
                 Destination destination)
          throws JMSException
Constructor for the Requestor class.

This implementation assumes the session parameter to be non-transacted, with a delivery mode of either AUTO_ACKNOWLEDGE or DUPS_OK_ACKNOWLEDGE.

Parameters:
session - the Session the queue belongs to
destination - the destination to perform the request/reply call on
Throws:
JMSException - if the JMS provider fails to create the Requestor due to some internal error.
InvalidDestinationException - if an invalid queue is specified.
Method Detail

request

public Message request(Message message)
                throws JMSException
Sends a request and waits for a reply. The temporary queue is used for the JMSReplyTo destination, and only one reply per request is expected.

Parameters:
message - the message to send
Returns:
the reply message
Throws:
JMSException - if the JMS provider fails to complete the request due to some internal error.

request

public Message request(Message message,
                       long timeout)
                throws JMSException
Sends a request and waits for a reply up to a maximum timeout. The temporary queue is used for the JMSReplyTo destination, and only one reply per request is expected.

Parameters:
message - the message to send
Returns:
the reply message
Throws:
JMSException - if the JMS provider fails to complete the request due to some internal error.

close

public void close()
           throws JMSException
Closes the Requestor and its session.

Since a provider may allocate some resources on behalf of a Requestor outside the Java virtual machine, clients should close them when they are not needed. Relying on garbage collection to eventually reclaim these resources may not be timely enough.

Note that this method closes the Session object passed to the Requestor constructor.

Throws:
JMSException - if the JMS provider fails to close the Requestor due to some internal error.

getMaximumTimeout

public long getMaximumTimeout()

setMaximumTimeout

public void setMaximumTimeout(long maximumTimeout)
Sets the maximum default timeout used for remote requests. If set to <= 0 then the timeout is ignored.

Parameters:
maximumTimeout -

createTemporaryDestination

protected TemporaryQueue createTemporaryDestination(Session session)
                                             throws JMSException
Throws:
JMSException


Copyright © 2004-2005 Protique, Ltd.. All Rights Reserved.