Example #1
0
    @Override
    protected SelectChannelEndPoint newEndPoint(
        SocketChannel channel, SelectSet selectSet, SelectionKey key) throws IOException {
      // We're connected, cancel the connect timeout
      Timeout.Task connectTimeout = _connectingChannels.remove(channel);
      if (connectTimeout != null) connectTimeout.cancel();
      if (LOG.isDebugEnabled())
        LOG.debug("Channels with connection pending: {}", _connectingChannels.size());

      // key should have destination at this point (will be replaced by endpoint after this call)
      HttpDestination dest = (HttpDestination) key.attachment();

      SelectChannelEndPoint scep =
          new SelectChannelEndPoint(channel, selectSet, key, (int) _httpClient.getIdleTimeout());
      AsyncEndPoint ep = scep;

      if (dest.isSecure()) {
        LOG.debug("secure to {}, proxied={}", channel, dest.isProxied());
        ep = new UpgradableEndPoint(ep, newSslEngine(channel));
      }

      AsyncConnection connection =
          selectSet.getManager().newConnection(channel, ep, key.attachment());
      ep.setConnection(connection);

      AbstractHttpConnection httpConnection = (AbstractHttpConnection) connection;
      httpConnection.setDestination(dest);

      if (dest.isSecure() && !dest.isProxied()) ((UpgradableEndPoint) ep).upgrade();

      dest.onNewConnection(httpConnection);

      return scep;
    }
Example #2
0
    /* (non-Javadoc)
     * @see org.eclipse.io.nio.SelectorManager#connectionFailed(java.nio.channels.SocketChannel, java.lang.Throwable, java.lang.Object)
     */
    @Override
    protected void connectionFailed(SocketChannel channel, Throwable ex, Object attachment) {
      Timeout.Task connectTimeout = _connectingChannels.remove(channel);
      if (connectTimeout != null) connectTimeout.cancel();

      if (attachment instanceof HttpDestination)
        ((HttpDestination) attachment).onConnectionFailed(ex);
      else super.connectionFailed(channel, ex, attachment);
    }