private void connectRetry(ConnectResultListener listener) {
   _log.info("connecting: " + _server.toSimpleString());
   if (isClosingOrClosed()) {
     listener.onConnectFailure(new ClosedChannelException());
     return;
   } else if (!isConnecting()) {
     listener.onConnectFailure(new RuntimeException("unable to connect"));
   } else {
     // ChannelFuture future = _bootstrap.connect(_server.getAddress());
     // future.addListener(new MyConnectListener(listener));
     _handler.reset(); // reset state to make sure new connection starts with a blank Handler state
     _handler.setConnectionListener(new AbstractNettyConnectListener(listener));
     _bootstrap.connect(_server.getAddress());
   }
 }
  private static boolean canServe(ServerInfo s, Collection<String> sources) {
    List<String> supportedSources = s.getSources();

    for (String src : sources) {
      if (!supportedSources.contains(src)) return false;
    }

    return true;
  }
 /**
  * Creates an empty HttpRequest object with pre-filled standard headers
  *
  * @param uriString the request URL
  * @return the request object
  */
 protected HttpRequest createEmptyRequest(String uriString) {
   HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uriString);
   request.setHeader(HttpHeaders.Names.HOST, _server.getAddress().toString());
   request.setHeader(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
   request.setHeader(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP);
   String hostHdr = DbusHttpUtils.getLocalHostName();
   String svcHdr = DbusConstants.getServiceIdentifier();
   if (!hostHdr.isEmpty()) {
     request.setHeader(DatabusHttpHeaders.DBUS_CLIENT_HOST_HDR, hostHdr);
   }
   if (!svcHdr.isEmpty()) {
     request.setHeader(DatabusHttpHeaders.DBUS_CLIENT_SERVICE_HDR, svcHdr);
   }
   return request;
 }
  /** Closes the connection. Note: this method will block until the connection is actually closed */
  @Override
  public void close() {
    _log.info("closing connection to: " + _server.getAddress());
    final State newState = switchToClosing();
    if (State.CLOSING != newState && State.CLOSED != newState) {
      return;
    }

    if (null == _channel || !_channel.isConnected()) {
      switchToClosed();
    } else {
      _channel.close();
      awaitForCloseUninterruptibly();
    }
  }