net.grinder.communication
Class ServerReceiver

java.lang.Object
  extended by net.grinder.communication.ServerReceiver
All Implemented Interfaces:
Receiver

public final class ServerReceiver
extends Object
implements Receiver

Manages the receipt of messages from many clients.

Author:
Philip Aston

Constructor Summary
ServerReceiver()
           
 
Method Summary
 void receiveFrom(Acceptor acceptor, ConnectionType[] connectionTypes, int numberOfThreads, long idleThreadPollDelay, long inactiveClientTimeOut)
          Registers a new Acceptor from which the ServerReceiver should process messages.
 void shutdown()
          Shut down this receiver.
 Message waitForMessage()
          Block until a message is available, or another thread has called shutdown().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServerReceiver

public ServerReceiver()
Method Detail

receiveFrom

public void receiveFrom(Acceptor acceptor,
                        ConnectionType[] connectionTypes,
                        int numberOfThreads,
                        long idleThreadPollDelay,
                        long inactiveClientTimeOut)
                 throws CommunicationException
Registers a new Acceptor from which the ServerReceiver should process messages. Actively polls connections of the given types for messages, de-serialises them, and queues them for retrieval using waitForMessage().

A single ServerReceiver can listen to messages from multiple Acceptors. You can register the same Acceptor with multiple ServerReceivers, but then there is no way of controlling which receiver will receive messages from a given Acceptor.

Parameters:
acceptor - Acceptor.
connectionTypes - Type of connections to listen for.
numberOfThreads - How many threads to dedicate to processing the Acceptor. The threads this method spawns just read, deserialise, and queue. Set numberOfThreads to the number of concurrent streams you expect to be able to read.
idleThreadPollDelay - Time in milliseconds that an idle thread should sleep if there are no sockets to process.
inactiveClientTimeOut - How long before we consider a client connection that presents no data to be inactive.
Throws:
CommunicationException - If this ServerReceiver has been shutdown.

waitForMessage

public Message waitForMessage()
                       throws CommunicationException
Block until a message is available, or another thread has called shutdown(). Typically called from a message dispatch loop.

Multiple threads can call this method, but only one thread will receive a given message.

Specified by:
waitForMessage in interface Receiver
Returns:
The message or null if shut down.
Throws:
CommunicationException - If an error occurred receiving a message.

shutdown

public void shutdown()
Shut down this receiver.

Specified by:
shutdown in interface Receiver


Copyright © 2000-2013. All Rights Reserved.