com.rabbitmq.client
Class RpcServer

java.lang.Object
  extended by com.rabbitmq.client.RpcServer
Direct Known Subclasses:
MapRpcServer, StringRpcServer

public class RpcServer
extends java.lang.Object

Class which manages a request queue for a simple RPC-style service. The class is agnostic about the format of RPC arguments / return values.


Constructor Summary
RpcServer(Channel channel)
          Creates an RpcServer listening on a temporary exclusive autodelete queue.
RpcServer(Channel channel, java.lang.String queueName)
          If the passed-in queue name is null, creates a server-named temporary exclusive autodelete queue to use; otherwise expects the queue to have already been declared.
 
Method Summary
 void close()
          Public API - cancels the consumer, thus deleting the queue, if it was a temporary queue, and marks the RpcServer as closed.
 Channel getChannel()
          Retrieve the channel.
 java.lang.String getQueueName()
          Retrieve the queue name.
 byte[] handleCall(AMQP.BasicProperties requestProperties, byte[] requestBody, AMQP.BasicProperties replyProperties)
          Mid-level response method.
 byte[] handleCall(byte[] requestBody, AMQP.BasicProperties replyProperties)
          High-level response method.
 byte[] handleCall(QueueingConsumer.Delivery request, AMQP.BasicProperties replyProperties)
          Lowest-level response method.
 void handleCast(AMQP.BasicProperties requestProperties, byte[] requestBody)
          Mid-level handler method.
 void handleCast(byte[] requestBody)
          High-level handler method.
 void handleCast(QueueingConsumer.Delivery request)
          Lowest-level handler method.
 ShutdownSignalException mainloop()
          Public API - main server loop.
 void processRequest(QueueingConsumer.Delivery request)
          Private API - Process a single request.
protected  QueueingConsumer setupConsumer()
          Registers a consumer on the reply queue.
 void terminateMainloop()
          Call this method to terminate the mainloop.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RpcServer

public RpcServer(Channel channel)
          throws java.io.IOException
Creates an RpcServer listening on a temporary exclusive autodelete queue.

Throws:
java.io.IOException

RpcServer

public RpcServer(Channel channel,
                 java.lang.String queueName)
          throws java.io.IOException
If the passed-in queue name is null, creates a server-named temporary exclusive autodelete queue to use; otherwise expects the queue to have already been declared.

Throws:
java.io.IOException
Method Detail

close

public void close()
           throws java.io.IOException
Public API - cancels the consumer, thus deleting the queue, if it was a temporary queue, and marks the RpcServer as closed.

Throws:
java.io.IOException - if an error is encountered

setupConsumer

protected QueueingConsumer setupConsumer()
                                  throws java.io.IOException
Registers a consumer on the reply queue.

Returns:
the newly created and registered consumer
Throws:
java.io.IOException - if an error is encountered

mainloop

public ShutdownSignalException mainloop()
                                 throws java.io.IOException
Public API - main server loop. Call this to begin processing requests. Request processing will continue until the Channel (or its underlying Connection) is shut down, or until terminateMainloop() is called. Note that if the mainloop is blocked waiting for a request, the termination flag is not checked until a request is received, so a good time to call terminateMainloop() is during a request handler.

Returns:
the exception that signalled the Channel shutdown, or null for orderly shutdown
Throws:
java.io.IOException

terminateMainloop

public void terminateMainloop()
Call this method to terminate the mainloop. Note that if the mainloop is blocked waiting for a request, the termination flag is not checked until a request is received, so a good time to call terminateMainloop() is during a request handler.


processRequest

public void processRequest(QueueingConsumer.Delivery request)
                    throws java.io.IOException
Private API - Process a single request. Called from mainloop().

Throws:
java.io.IOException

handleCall

public byte[] handleCall(QueueingConsumer.Delivery request,
                         AMQP.BasicProperties replyProperties)
Lowest-level response method. Calls handleCall(AMQP.BasicProperties,byte[],AMQP.BasicProperties).


handleCall

public byte[] handleCall(AMQP.BasicProperties requestProperties,
                         byte[] requestBody,
                         AMQP.BasicProperties replyProperties)
Mid-level response method. Calls handleCall(byte[],AMQP.BasicProperties).


handleCall

public byte[] handleCall(byte[] requestBody,
                         AMQP.BasicProperties replyProperties)
High-level response method. Returns an empty response by default - override this (or other handleCall and handleCast methods) in subclasses.


handleCast

public void handleCast(QueueingConsumer.Delivery request)
Lowest-level handler method. Calls handleCast(AMQP.BasicProperties,byte[]).


handleCast

public void handleCast(AMQP.BasicProperties requestProperties,
                       byte[] requestBody)
Mid-level handler method. Calls handleCast(byte[]).


handleCast

public void handleCast(byte[] requestBody)
High-level handler method. Does nothing by default - override this (or other handleCast and handleCast methods) in subclasses.


getChannel

public Channel getChannel()
Retrieve the channel.

Returns:
the channel to which this server is connected

getQueueName

public java.lang.String getQueueName()
Retrieve the queue name.

Returns:
the queue which this server is consuming from