public void handleMessage(final Connection connection, final InputStream dataStream)
     throws IOException {
   final int cmd = readUnsignedByte(dataStream);
   if (cmd != Protocol.AUTH) {
     log.warnf(
         "Received unrecognized greeting code 0x%02x from %s",
         Integer.valueOf(cmd), connection.getPeerAddress());
     connection.close();
     return;
   }
   final int version = StreamUtils.readUnsignedByte(dataStream);
   if (version < 1) {
     log.warnf("Received connection with invalid version from %s", connection.getPeerAddress());
     connection.close();
     return;
   }
   final byte[] authCode = new byte[16];
   StreamUtils.readFully(dataStream, authCode);
   final ManagedProcess process = processController.getServerByAuthCode(authCode);
   if (process == null) {
     log.warnf(
         "Received connection with unknown credentials from %s", connection.getPeerAddress());
     StreamUtils.safeClose(connection);
     return;
   }
   log.tracef("Received authentic connection from %s", connection.getPeerAddress());
   connection.setMessageHandler(
       new ConnectedMessageHandler(processController, process.isInitial()));
   processController.addManagedConnection(connection);
   dataStream.close();
 }
 public void handleShutdown(final Connection connection) throws IOException {
   log.tracef("Received end-of-stream for connection");
   processController.removeManagedConnection(connection);
   connection.shutdownWrites();
 }
 public MessageHandler handleConnected(final Connection connection) throws IOException {
   log.tracef("Received connection from %s", connection.getPeerAddress());
   return new InitMessageHandler(processController);
 }
 public void handleFailure(final Connection connection, final IOException e)
     throws IOException {
   log.tracef(e, "Received failure of connection");
   connection.close();
 }
 public void handleShutdown(final Connection connection) throws IOException {
   log.tracef("Received end-of-stream for connection");
   connection.shutdownWrites();
 }
 public void handleFailure(final Connection connection, final IOException e) throws IOException {
   log.tracef(e, "Received failure of connection");
   processController.removeManagedConnection(connection);
   connection.close();
 }