@Override
 public void connectionOpened(final Connection connection) throws IOException {
   final Channel channel =
       openChannel(connection, CHANNEL_SERVICE_TYPE, configuration.getOptionMap());
   if (setChannel(channel)) {
     channel.receiveMessage(channelHandler.getReceiver());
     channel.addCloseHandler(channelHandler);
     try {
       // Start the registration process
       channelHandler.executeRequest(new RegisterHostControllerRequest(), null).getResult().get();
     } catch (Exception e) {
       if (e.getCause() instanceof IOException) {
         throw (IOException) e.getCause();
       }
       throw new IOException(e);
     }
     // Registered
     registered();
   } else {
     channel.closeAsync();
   }
 }
 @Override
 public void close() throws IOException {
   synchronized (this) {
     try {
       if (isConnected()) {
         try {
           channelHandler
               .executeRequest(new UnregisterModelControllerRequest(), null)
               .getResult()
               .await();
         } catch (InterruptedException e) {
           Thread.currentThread().interrupt();
         }
       }
     } finally {
       try {
         connectionManager.shutdown();
       } finally {
         super.close();
       }
     }
   }
 }