protected static void safeWriteResponse(
     final Channel channel, final ManagementProtocolHeader header, final Exception error) {
   if (header.getType() == ManagementProtocol.TYPE_REQUEST) {
     try {
       writeResponse(channel, (ManagementRequestHeader) header, error);
     } catch (IOException ioe) {
       ioe.printStackTrace();
     }
   }
 }
 @Override
 public void handleMessage(
     final Channel channel, final DataInput input, final ManagementProtocolHeader header)
     throws IOException {
   final byte type = header.getType();
   if (type == ManagementProtocol.TYPE_REQUEST) {
     final ManagementRequestHeader request = (ManagementRequestHeader) header;
     handleMessage(channel, input, request);
   } else {
     safeWriteResponse(channel, header, MESSAGES.unrecognizedType(type));
     channel.close();
   }
 }
 protected static void writeHeader(final ManagementProtocolHeader header, final OutputStream os)
     throws IOException {
   final FlushableDataOutput output = ProtocolUtils.wrapAsDataOutput(os);
   header.write(output);
   output.flush();
 }