net.grinder.communication
Class FanOutServerSender

java.lang.Object
  extended by net.grinder.communication.FanOutServerSender
All Implemented Interfaces:
Sender

public final class FanOutServerSender
extends Object

Manages the sending of messages to many TCP clients.

Author:
Philip Aston

Constructor Summary
FanOutServerSender(Acceptor acceptor, ConnectionType connectionType, int numberOfThreads)
          Constructor.
 
Method Summary
protected  Address getAddress(ResourcePool.Resource resource)
          Return the address of a socket.
protected  net.grinder.communication.ResourcePool getResourcePool()
          Allow subclasses to access the resource pool.
 boolean isShutdown()
          Return whether we are shutdown.
protected  OutputStream resourceToOutputStream(ResourcePool.Resource resource)
          Return an output stream from a socket resource.
 void send(Address address, Message message)
          Send a message to a particular address.
 void send(Message message)
          Send the given message.
 void shutdown()
          Shut down this sender.
protected  void writeAddressedMessage(Address address, Message message)
          Send a message.
protected  void writeMessage(Message message)
          Send a message.
protected static void writeMessageToStream(Message message, OutputStream stream)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FanOutServerSender

public FanOutServerSender(Acceptor acceptor,
                          ConnectionType connectionType,
                          int numberOfThreads)
                   throws Acceptor.ShutdownException
Constructor.

Parameters:
acceptor - Acceptor.
connectionType - Connection type.
numberOfThreads - Number of sender threads to use.
Throws:
Acceptor.ShutdownException - If the acceptor has been shutdown.
Method Detail

send

public void send(Address address,
                 Message message)
          throws CommunicationException
Send a message to a particular address.

Parameters:
address - Address to send message to.
message - The message.
Throws:
CommunicationException - If an error occurs.

resourceToOutputStream

protected OutputStream resourceToOutputStream(ResourcePool.Resource resource)
                                       throws CommunicationException
Return an output stream from a socket resource.

Parameters:
resource - The resource.
Returns:
The output stream.
Throws:
CommunicationException - If the output stream could not be obtained from the socket.

getAddress

protected Address getAddress(ResourcePool.Resource resource)
Return the address of a socket.

Parameters:
resource - The resource.
Returns:
The address, or null if the socket has no address.

writeMessage

protected final void writeMessage(Message message)
                           throws CommunicationException
Send a message.

Parameters:
message - The message.
Throws:
IOException - If an error occurs.
CommunicationException

writeAddressedMessage

protected final void writeAddressedMessage(Address address,
                                           Message message)
                                    throws CommunicationException
Send a message.

Parameters:
message - The message.
Throws:
IOException - If an error occurs.
CommunicationException

getResourcePool

protected final net.grinder.communication.ResourcePool getResourcePool()
Allow subclasses to access the resource pool.

Returns:
The resource pool.

shutdown

public void shutdown()
Shut down this sender.

Specified by:
shutdown in interface Sender

send

public final void send(Message message)
                throws CommunicationException
Send the given message.

Specified by:
send in interface Sender
Parameters:
message - A Message.
Throws:
CommunicationException - If an error occurs.

writeMessageToStream

protected static final void writeMessageToStream(Message message,
                                                 OutputStream stream)
                                          throws IOException
Throws:
IOException

isShutdown

public boolean isShutdown()
Return whether we are shutdown.

Returns:
true if and only if we are shut down.


Copyright © 2000-2013. All Rights Reserved.