org.elkoserver.foundation.net
Class NetworkManager

java.lang.Object
  extended by org.elkoserver.foundation.net.NetworkManager

public class NetworkManager
extends Object

Manage network connections between this server and other entities.


Field Summary
static int MAX_MSG_LENGTH
          Maximum length message that a connection will be able to receive.
static boolean TheDebugReplyFlag
          Special debug support: if this flag is set to true, errors generated by received messages will result in a 'debug' message being sent in reply.
 
Constructor Summary
NetworkManager(ConnectionCountMonitor connectionCountMonitor, BootProperties props, LoadMonitor loadMonitor, Runner runner)
          Construct a NetworkManager for this server.
 
Method Summary
 void connectionCount(int adjust)
          Keep track of the number of connections.
 void connectTCP(String hostPort, MessageHandlerFactory handlerFactory, ByteIOFramerFactory framerFactory, Trace trace)
          Make a TCP connection to another host given a host:port address.
 void connectVia(String connectionManagerClassName, String propRoot, String hostPort, MessageHandlerFactory handlerFactory, Trace msgTrace)
          Make a connection to another host given a host:port address using a named connection manager class.
 NetAddr listenHTTP(String listenAddress, MessageHandlerFactory innerHandlerFactory, String rootURI, HTTPFramer httpFramer, boolean secure, Trace trace)
          Begin listening for incoming HTTP connections on some port.
 NetAddr listenRTCP(String listenAddress, MessageHandlerFactory innerHandlerFactory, Trace msgTrace, boolean secure)
          Begin listening for incoming RTCP connections on some port.
 NetAddr listenTCP(String listenAddress, MessageHandlerFactory handlerFactory, ByteIOFramerFactory framerFactory, boolean secure, Trace portTrace)
          Begin listening for incoming TCP connections on some port.
 NetAddr listenVia(String connectionManagerClassName, String propRoot, String listenAddress, MessageHandlerFactory handlerFactory, Trace msgTrace, boolean secure)
          Begin listening for incoming connections on some port using a named connection manager class.
 NetAddr listenWebSocket(String listenAddress, MessageHandlerFactory innerHandlerFactory, String socketURI, Trace msgTrace, boolean secure)
          Begin listening for incoming WebSocket connections on some port.
 BootProperties props()
          Get this server's properties.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_MSG_LENGTH

public static final int MAX_MSG_LENGTH
Maximum length message that a connection will be able to receive.

See Also:
Constant Field Values

TheDebugReplyFlag

public static boolean TheDebugReplyFlag
Special debug support: if this flag is set to true, errors generated by received messages will result in a 'debug' message being sent in reply. Normally (when the flag is false), from the sender's perspective such errors will be silently swallowed.

Constructor Detail

NetworkManager

public NetworkManager(ConnectionCountMonitor connectionCountMonitor,
                      BootProperties props,
                      LoadMonitor loadMonitor,
                      Runner runner)
Construct a NetworkManager for this server.

Parameters:
connectionCountMonitor - Monitor for tracking session count.
props - Boot properties for this server.
loadMonitor - Load monitor for tracking system load.
runner - The Runner managing this server's run queue.
Method Detail

connectionCount

public void connectionCount(int adjust)
Keep track of the number of connections.

Parameters:
adjust - Adjustment being made to the number of active connections, plus or minus.

connectTCP

public void connectTCP(String hostPort,
                       MessageHandlerFactory handlerFactory,
                       ByteIOFramerFactory framerFactory,
                       Trace trace)
Make a TCP connection to another host given a host:port address.

Parameters:
hostPort - The host name (or IP address) and port to connect to, separated by a colon. For example, "bithlo.example.com:8002".
handlerFactory - Message handler factory to provide the handler for the connection that results from this operation.
framerFactory - Byte I/O framer factory for the new connection.
trace - Trace object to use for activity on the new connection.

connectVia

public void connectVia(String connectionManagerClassName,
                       String propRoot,
                       String hostPort,
                       MessageHandlerFactory handlerFactory,
                       Trace msgTrace)
Make a connection to another host given a host:port address using a named connection manager class.

Parameters:
connectionManagerClassName - Fully qualified class name of the connection manager class to use to make this connection.
propRoot - Prefix string for all the properties describing the connection that is to be made.
hostPort - The host name (or IP address) and port to connect to, separated by a colon. For example, "bithlo.example.com:8002".
handlerFactory - Message handler factory to provide the handler for the connection that results from this operation.
msgTrace - Trace object for logging message traffic.

listenHTTP

public NetAddr listenHTTP(String listenAddress,
                          MessageHandlerFactory innerHandlerFactory,
                          String rootURI,
                          HTTPFramer httpFramer,
                          boolean secure,
                          Trace trace)
                   throws IOException
Begin listening for incoming HTTP connections on some port.

Parameters:
listenAddress - Host name and port to listen for connections on.
innerHandlerFactory - Message handler factory to provide message handlers for messages passed inside HTTP requests on connections made to this port.
rootURI - The root URI that GETs and POSTs must reference.
httpFramer - HTTP framer to interpret HTTP POSTs and format HTTP replies.
secure - If true, use SSL.
trace - Trace object to use for activity on this connection.
Returns:
the address that ended up being listened upon
Throws:
IOException

listenRTCP

public NetAddr listenRTCP(String listenAddress,
                          MessageHandlerFactory innerHandlerFactory,
                          Trace msgTrace,
                          boolean secure)
                   throws IOException
Begin listening for incoming RTCP connections on some port.

Parameters:
listenAddress - Host name and port to listen for connections on.
innerHandlerFactory - Message handler factory to provide message handlers for messages passed inside RTCP requests on connections made to this port.
msgTrace - Trace object for logging message traffice
secure - If true, use SSL.
Returns:
the address that ended up being listened upon
Throws:
IOException

listenWebSocket

public NetAddr listenWebSocket(String listenAddress,
                               MessageHandlerFactory innerHandlerFactory,
                               String socketURI,
                               Trace msgTrace,
                               boolean secure)
                        throws IOException
Begin listening for incoming WebSocket connections on some port.

Parameters:
listenAddress - Host name and port to listen for connections on.
innerHandlerFactory - Message handler factory to provide message handlers for messages passed inside WebSocket frames on connections made to this port.
socketURI - The WebSocket URI that browsers connect to
msgTrace - Trace object for logging message traffice
secure - If true, use SSL.
Returns:
the address that ended up being listened upon
Throws:
IOException

listenTCP

public NetAddr listenTCP(String listenAddress,
                         MessageHandlerFactory handlerFactory,
                         ByteIOFramerFactory framerFactory,
                         boolean secure,
                         Trace portTrace)
                  throws IOException
Begin listening for incoming TCP connections on some port.

Parameters:
listenAddress - Host name and port to listen for connections on.
handlerFactory - Message handler factory to provide message handlers for connections made to this port.
framerFactory - Byte I/O framer factory for the new connection.
secure - If true, use SSL.
portTrace - Trace object for logging activity associated with this port & its connections
Returns:
the address that ended up being listened upon
Throws:
IOException

listenVia

public NetAddr listenVia(String connectionManagerClassName,
                         String propRoot,
                         String listenAddress,
                         MessageHandlerFactory handlerFactory,
                         Trace msgTrace,
                         boolean secure)
                  throws IOException
Begin listening for incoming connections on some port using a named connection manager class.

Parameters:
connectionManagerClassName - Fully qualified class name of the connection manager class to use to make this connection.
propRoot - Prefix string for all the properties describing the listener that is to be started.
listenAddress - Host name and port to listen for connections on.
handlerFactory - Message handler factory to provide message handlers for connections made to this port.
msgTrace - Trace object for logging message traffic.
secure - If true, use a secure connection pathway (e.g., SSL).
Returns:
the address that ended up being listened upon
Throws:
IOException - if the requested connection manager was unavailable.

props

public BootProperties props()
Get this server's properties.

Returns:
the properties