Methods Summary |
---|
protected void | accept_loop()
while( isRunning() ) {
try {
SocketChannel client_channel = server_channel.accept();
last_accept_time = SystemTime.getCurrentTime();
client_channel.configureBlocking( false );
listener.newConnectionAccepted( server_channel, client_channel );
}
catch( AsynchronousCloseException e ) {
/* is thrown when stop() is called */
}
catch( Throwable t ) {
Debug.out( t );
try { Thread.sleep( 500 ); }catch( Exception e ) { e.printStackTrace(); }
}
}
|
public java.net.InetAddress | getBoundToAddress()
if( server_channel != null ) {
return server_channel.socket().getInetAddress();
}
return null;
|
public long | getTimeOfLastAccept()
return last_accept_time;
|
public boolean | isRunning()Is this selector actively running
if( server_channel != null && server_channel.isOpen() ) return true;
return false;
|
public void | start()Start the server and begin accepting incoming connections.
try{
this_mon.enter();
if( !isRunning() ) {
try {
server_channel = ServerSocketChannel.open();
server_channel.socket().setReuseAddress( true );
if( receive_buffer_size > 0 ) server_channel.socket().setReceiveBufferSize( receive_buffer_size );
server_channel.socket().bind( bind_address, 1024 );
if (Logger.isEnabled()) Logger.log(new LogEvent(LOGID, "TCP incoming server socket " + bind_address));
AEThread accept_thread = new AEThread( "VServerSelector:port" + bind_address.getPort() ) {
public void runSupport() {
accept_loop();
}
};
accept_thread.setDaemon( true );
accept_thread.start();
}
catch( Throwable t ) {
Debug.out( t );
Logger.log(new LogAlert(LogAlert.UNREPEATABLE, "ERROR, unable to bind TCP incoming server socket to " +bind_address.getPort(), t));
}
last_accept_time = SystemTime.getCurrentTime(); //init to now
}
}finally{
this_mon.exit();
}
|
public void | stop()Stop the server.
try{
this_mon.enter();
if( server_channel != null ) {
try {
server_channel.close();
server_channel = null;
}
catch( Throwable t ) { Debug.out( t ); }
}
}finally{
this_mon.exit();
}
|