}
@Override
protected void doHandle(final MessageInputStream message) {
ROOT_LOGGER.tracef("%s handling incoming data", this);
final SimpleDataInput input = new SimpleDataInput(Marshalling.createByteInput(message));
Exception error = null;
ManagementRequestHeader requestHeader = null;
ManagementRequestHandler requestHandler = null;
boolean wasPing = false;
try {
ManagementProtocolHeader header;
header = ManagementProtocolHeader.parse(input);
switch (header.getType()) {
case ManagementProtocol.TYPE_REQUEST:
requestHeader = (ManagementRequestHeader)header;
requestHandler = requestReceiver.readRequest(requestHeader, input);
break;
case ManagementProtocol.TYPE_RESPONSE:
gotIncomingResponse();
responseReceiver.handleResponse((ManagementResponseHeader)header, input);
break;
case ManagementProtocol.TYPE_BYE_BYE:
ROOT_LOGGER.tracef("Received bye bye on %s, closing", this);
close();
break;
case ManagementProtocol.TYPE_PING:
wasPing = true;
ROOT_LOGGER.tracef("Received ping on %s", this);
break;
case ManagementProtocol.TYPE_PONG:
ROOT_LOGGER.tracef("Received pong on %s", this);
gotIncomingResponse();
break;
}
} catch (Exception e) {
error = e;
ROOT_LOGGER.tracef(e, "%s error handling incoming data", this);
} finally {
ROOT_LOGGER.tracef("%s done handling incoming data", this);
try {
//Consume the rest of the output if any
while (input.read() != -1) {
}
} catch (IOException ignore) {
}
IoUtils.safeClose(input);