protected void shutdown() {
close();
}
public void run() {
Socket socket = null;
InputStream is = null;
OutputStream os = null;
try {
// After a stop we needs to create anew the listen socket.
if (listen == null) {
// creates a server socket listening on configured port
listen = createServerSocket();
}
NetworkInputStream nis = new NetworkInputStream();
while (running) {
try {
canStop = true;
// Get the connection
try {
if (this.logmon.isLoggable(BasicLevel.DEBUG))
this.logmon.log(BasicLevel.DEBUG, this.getName() + ", waiting connection");
socket = listen.accept();
} catch (IOException exc) {
if (this.logmon.isLoggable(BasicLevel.DEBUG))
this.logmon.log(BasicLevel.DEBUG, this.getName() + ", interrupted");
continue;
}
canStop = false;
setSocketOption(socket);
if (this.logmon.isLoggable(BasicLevel.DEBUG))
this.logmon.log(BasicLevel.DEBUG, this.getName() + ", connected");
// Read the message,
os = socket.getOutputStream();
is = socket.getInputStream();
Message msg = nis.readMessage(is);
if (this.logmon.isLoggable(BasicLevel.DEBUG))
this.logmon.log(BasicLevel.DEBUG, this.getName() + ", msg received");
deliver(msg);
if (this.logmon.isLoggable(BasicLevel.DEBUG))
this.logmon.log(BasicLevel.DEBUG, this.getName() + ", send ack");
// then send the acknowledge.
os.write(0);
os.flush();
} catch (Exception exc) {
this.logmon.log(BasicLevel.ERROR, this.getName() + ", closed", exc);
} finally {
nis.clean();
try {
if (os != null) os.close();
} catch (Exception exc) {}
os = null;
try {
if (is != null) is.close();
} catch (Exception exc) {}
is = null;
try {
if (socket != null) socket.close();
} catch (Exception exc) {}
socket = null;
}
}
} catch (IOException exc) {