public void run()
{
try {
ServerSocket serverSocket = null;
while(_running) {
if (serverSocket == null) {
try {
serverSocket = new ServerSocket(_port, 4);
_address = serverSocket.getInetAddress();
serverSocket.setSoTimeout(0);
} catch (IOException e) {
log().error("Cannot establish end point", e);
break;
}
log().info("Endpoint created at port "+_port);
}
try {
Socket socket = serverSocket.accept();
InetAddress address = socket.getInetAddress();
if (_running && _allow.contains(address)) {
_pool.spawn(new SessionClient(this, socket));
} else {
log().info("Connection from "+address.getHostName()+" rejected");
try {
socket.close();
} catch (Throwable t) {
}
}
} catch (InterruptedIOException e) {
} catch (IOException e) {
log().error(e);
try {
serverSocket.close();
} catch (Throwable t) {
}
serverSocket = null;
_address = null;
}
}
if (serverSocket != null) {
log().info("Endpoint at port "+_port+" closed");
serverSocket.close();
}
} catch (IOException e) {
log().error(e);
}
}