net.grinder.communication
Class Acceptor

java.lang.Object
  extended by net.grinder.communication.Acceptor

public final class Acceptor
extends Object

Active object that accepts connections on a ServerSocket.

Author:
Philip Aston

Nested Class Summary
static interface Acceptor.Listener
          Listener interface.
static class Acceptor.ShutdownException
          Indicates the Acceptor has been shut down.
 
Constructor Summary
Acceptor(String addressString, int port, int numberOfThreads, TimeAuthority timeAuthority)
          Constructor.
 
Method Summary
 void addListener(ConnectionType connectionType, Acceptor.Listener listener)
          Add a new listener.
 int getNumberOfConnections()
          The number of connections that have been accepted and are still active.
 Exception getPendingException()
          Asynchronous exception handling.
 int getPort()
          Get the port this Acceptor is listening on.
 void shutdown()
          Shut down this acceptor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Acceptor

public Acceptor(String addressString,
                int port,
                int numberOfThreads,
                TimeAuthority timeAuthority)
         throws CommunicationException
Constructor.

Parameters:
addressString - The TCP address to listen on. Zero-length string => listen on all interfaces.
port - The TCP port to listen to. 0 => use any free port.
numberOfThreads - Number of acceptor threads.
timeAuthority - Knows the time.
Throws:
CommunicationException - If server socket could not be bound.
Method Detail

shutdown

public void shutdown()
              throws CommunicationException
Shut down this acceptor.

Throws:
CommunicationException - If an IO exception occurs.

getPort

public int getPort()
Get the port this Acceptor is listening on.

Returns:
The port.

getPendingException

public Exception getPendingException()
Asynchronous exception handling.

Returns:
The exception, or null if this Acceptor has been shut down.

getNumberOfConnections

public int getNumberOfConnections()
The number of connections that have been accepted and are still active. Used by the unit tests.

Returns:
The number of accepted connections.

addListener

public void addListener(ConnectionType connectionType,
                        Acceptor.Listener listener)
Add a new listener.

Parameters:
connectionType - The connection type.
listener - The listener.


Copyright © 2000-2013. All Rights Reserved.