VirtualNonBlockingServerChannelSelectorpublic class VirtualNonBlockingServerChannelSelector extends Object implements com.aelitis.azureus.core.networkmanager.VirtualServerChannelSelectorVirtual server socket channel for listening and accepting incoming connections. |
Fields Summary |
---|
private static final LogIDs | LOGID | private List | server_channels | private final InetAddress | bind_address | private int | start_port | private int | num_ports | private final int | receive_buffer_size | private final VirtualBlockingServerChannelSelector.SelectListener | listener | protected AEMonitor | this_mon | private long | last_accept_time |
Constructors Summary |
---|
public VirtualNonBlockingServerChannelSelector(InetSocketAddress bind_address, int so_rcvbuf_size, VirtualBlockingServerChannelSelector.SelectListener listener)Create a new server listening on the given address and reporting to the given listener.
this( bind_address.getAddress(), bind_address.getPort(), 1, so_rcvbuf_size, listener );
| public VirtualNonBlockingServerChannelSelector(InetAddress _bind_address, int _start_port, int _num_ports, int _so_rcvbuf_size, VirtualBlockingServerChannelSelector.SelectListener _listener)
bind_address = _bind_address;
start_port = _start_port;
num_ports = _num_ports;
receive_buffer_size = _so_rcvbuf_size;
listener = _listener;
|
Methods Summary |
---|
public java.net.InetAddress | getBoundToAddress()
if ( server_channels.size() == 0 ){
return( null);
}
ServerSocketChannel server_channel = (ServerSocketChannel)server_channels.get(0);
return server_channel.socket().getInetAddress();
| public long | getTimeOfLastAccept()
return last_accept_time;
| public boolean | isRunning()Is this selector actively running
if ( server_channels.size() == 0 ){
return( false);
}
ServerSocketChannel server_channel = (ServerSocketChannel)server_channels.get(0);
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() ) {
for (int i=start_port;i<start_port+num_ports;i++){
try {
final ServerSocketChannel server_channel = ServerSocketChannel.open();
server_channels.add( server_channel );
server_channel.socket().setReuseAddress( true );
if( receive_buffer_size > 0 ) server_channel.socket().setReceiveBufferSize( receive_buffer_size );
server_channel.socket().bind( new InetSocketAddress( bind_address, i ), 1024 );
if (Logger.isEnabled()) Logger.log(new LogEvent(LOGID, "TCP incoming server socket " + bind_address));
server_channel.configureBlocking( false );
VirtualAcceptSelector.getSingleton().register(
server_channel,
new VirtualAcceptSelector.AcceptListener()
{
public void
newConnectionAccepted(
SocketChannel channel )
{
last_accept_time = SystemTime.getCurrentTime();
listener.newConnectionAccepted( server_channel, channel );
}
});
}catch( Throwable t ) {
Debug.out( t );
Logger.log(new LogAlert(LogAlert.UNREPEATABLE, "ERROR, unable to bind TCP incoming server socket to " +i, t));
}
}
last_accept_time = SystemTime.getCurrentTime(); //init to now
}
}finally{
this_mon.exit();
}
| public void | stop()Stop the server.
try{
this_mon.enter();
for (int i=0;i<server_channels.size();i++){
try {
ServerSocketChannel server_channel = (ServerSocketChannel)server_channels.get(i);
VirtualAcceptSelector.getSingleton().cancel( server_channel );
server_channel.close();
}
catch( Throwable t ) { Debug.out( t ); }
}
server_channels.clear();
}finally{
this_mon.exit();
}
|
|