@Override
public void handleUpstream(ChannelHandlerContext context, ChannelEvent event)
throws Exception {
if (event instanceof ChannelStateEvent) {
ChannelStateEvent csEvent = (ChannelStateEvent)event;
LOGGER.log(Level.FINEST, "Channel state changed: {0}\n\n", csEvent);
if (csEvent.getValue() == null
&& csEvent.getState() == ChannelState.CONNECTED) { // a disconnect
LOGGER.log(Level.FINE, "Channel has been disconnected on us, "
+ "restarting the monitor.");
monitor.notifyDisconnected(); // connection has been dropped
} else if(csEvent.getState() == ChannelState.OPEN
&& !Boolean.valueOf(csEvent.getValue().toString())) {
LOGGER.log(Level.FINE, "Channel has been closed on us, "
+ "restarting the monitor.");
monitor.notifyDisconnected(); // connection has been closed
} else {
LOGGER.log(Level.FINER, "Channel state change is not a disconnect. "
+ "Event value is {0} and Channel State is {1}.",
new Object[]{csEvent.getValue().toString(),
csEvent.getState().toString()});
}
}
if (event.getChannel().isConnected()) {
super.handleUpstream(context, event);
}