com.threerings.nio.conman
Class ServerSocketChannelAcceptor

java.lang.Object
  extended by com.threerings.nio.conman.ServerSocketChannelAcceptor
All Implemented Interfaces:
Lifecycle.BaseComponent, Lifecycle.ShutdownComponent

public class ServerSocketChannelAcceptor
extends Object
implements Lifecycle.ShutdownComponent

Binds sockets on a given hostname for a set of ports for tcp connections, and passes accepted connections into a connection manager.


Field Summary
protected  String _bindHostname
           
protected  ConnectionManager _conMan
           
protected  int[] _ports
           
protected  List<ServerSocketChannel> _ssockets
           
 
Constructor Summary
ServerSocketChannelAcceptor(String socketHostname, int[] socketPorts, ConnectionManager mgr)
          Configures the connection manager with the hostname and ports on which it will listen for socket connections.
 
Method Summary
protected  void acceptConnections(int port)
           
 boolean bind()
          Bind to the socket ports and return true if any of the binds succeeded.
protected  void configureSocket(ServerSocketChannel ssocket)
          Override to perform any desired additional socket configuration before binding.
 void shutdown()
          Unbind our listening sockets.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_ports

protected final int[] _ports

_bindHostname

protected final String _bindHostname

_conMan

protected final ConnectionManager _conMan

_ssockets

protected List<ServerSocketChannel> _ssockets
Constructor Detail

ServerSocketChannelAcceptor

public ServerSocketChannelAcceptor(String socketHostname,
                                   int[] socketPorts,
                                   ConnectionManager mgr)
Configures the connection manager with the hostname and ports on which it will listen for socket connections. This must be called before the connection manager is started as the sockets will be bound at that time.

Parameters:
socketHostname - the hostname to which we bind our sockets or null to bind to all interfaces.
socketPorts - the ports on which to listen for TCP connection.
Method Detail

bind

public boolean bind()
Bind to the socket ports and return true if any of the binds succeeded.


shutdown

public void shutdown()
Unbind our listening sockets.

Specified by:
shutdown in interface Lifecycle.ShutdownComponent

acceptConnections

protected void acceptConnections(int port)
                          throws IOException
Throws:
IOException

configureSocket

protected void configureSocket(ServerSocketChannel ssocket)
                        throws IOException
Override to perform any desired additional socket configuration before binding. Be sure to call the superclass implementation.

Throws:
IOException