Methods Summary |
---|
protected abstract void | checkConnection()Called by this class to check a client connection.
|
protected abstract void | doStart()Tells a client to re-start again.
|
protected abstract void | doStop()Tells a client to stop because failing to call checkConnection.
|
public void | gotIOException(java.io.IOException ioe)Called by a client to inform of getting an IOException.
restart(ioe);
|
private void | restart(java.io.IOException ioe)
// check state
synchronized(lock) {
if (state == TERMINATED) {
throw new IOException("The client has been closed.");
} else if (state == FAILED) { // already failed to re-start by another thread
throw ioe;
} else if (state == RE_CONNECTING) {
// restart process has been called by another thread
// we need to wait
while(state == RE_CONNECTING) {
try {
lock.wait();
} catch (InterruptedException ire) {
// be asked to give up
InterruptedIOException iioe = new InterruptedIOException(ire.toString());
EnvHelp.initCause(iioe, ire);
throw iioe;
}
}
if (state == TERMINATED) {
throw new IOException("The client has been closed.");
} else if (state != CONNECTED) {
// restarted is failed by another thread
throw ioe;
}
} else {
state = RE_CONNECTING;
lock.notifyAll();
}
}
// re-starting
try {
doStart();
synchronized(lock) {
if (state == TERMINATED) {
throw new IOException("The client has been closed.");
}
state = CONNECTED;
lock.notifyAll();
}
return;
} catch (Exception e) {
logger.warning("restart", "Failed to restart: " + e);
logger.debug("restart",e);
synchronized(lock) {
if (state == TERMINATED) {
throw new IOException("The client has been closed.");
}
state = FAILED;
lock.notifyAll();
}
try {
doStop();
} catch (Exception eee) {
// OK.
// We know there is a problem.
}
terminate();
throw ioe;
}
|
public void | terminate()Terminates this object.
synchronized(lock) {
if (state == TERMINATED) {
return;
}
state = TERMINATED;
lock.notifyAll();
if (checker != null)
checker.stop();
}
|