@Override
 public void handleEvent(JmxRemoteTunnelMessage messageEnvelope) {
   if (messageEnvelope.getCloseConnection()) {
     reset();
   } else {
     final Message message = (Message) messageEnvelope.getTunneledMessage();
     synchronized (this) {
       if (messageEnvelope.getInitConnection()) {
         if (messageConnection != null) {
           logger.warn(
               "Received a client connection initialization, resetting existing connection");
           reset();
         }
         messageConnection = new TunnelingMessageConnection(channel, true);
         acceptOk = true;
         notifyAll();
       } else if (messageConnection == null) {
         logger.warn("Received unexpected data message, connection is not yet established");
       } else {
         if (message != null) {
           messageConnection.incomingNetworkMessage(message);
         } else {
           logger.warn("Received tunneled message with no data, resetting connection");
           reset();
         }
       }
     }
   }
 }
 private synchronized void reset() {
   if (messageConnection != null) {
     messageConnection.close();
   }
   messageConnection = null;
   acceptOk = false;
   synchronized (jmxReadyLock) {
     sentReadyMessage = false;
   }
   notifyAll();
 }