Java Code Examples for io.netty.channel.ChannelHandlerContext#connect()

The following examples show how to use io.netty.channel.ChannelHandlerContext#connect() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HandshakeTimeoutHandler.java    From java-dcp-client with Apache License 2.0 6 votes vote down vote up
@Override
public void connect(final ChannelHandlerContext ctx, final SocketAddress remoteAddress,
                    final SocketAddress localAddress, final ChannelPromise promise) throws Exception {
  ctx.connect(remoteAddress, localAddress, promise);
  ctx.pipeline().remove(this);

  final Runnable fireDeadlineEvent = new Runnable() {
    /**
     * If there is a {@link ConnectInterceptingHandler} remaining in the pipeline,
     * it will respond to this event by failing the connection. If there are none
     * in the pipeline, the handshake is complete and this event is ignored.
     */
    @Override
    public void run() {
      LOGGER.debug("Firing handshake deadline event.");
      ctx.fireUserEventTriggered(HANDSHAKE_DEADLINE_EVENT);
    }
  };

  LOGGER.debug("Handshake timeout is {} {}.", timeout, timeoutUnit);
  ctx.executor().schedule(fireDeadlineEvent, timeout, timeoutUnit);
}
 
Example 2
Source File: ConnectInterceptingHandler.java    From java-dcp-client with Apache License 2.0 6 votes vote down vote up
/**
 * Intercept the connect phase and store the original promise.
 */
@Override
public void connect(final ChannelHandlerContext ctx, final SocketAddress remoteAddress,
                    final SocketAddress localAddress, final ChannelPromise promise) throws Exception {
  originalPromise = promise;
  ChannelPromise inboundPromise = ctx.newPromise();
  inboundPromise.addListener(new GenericFutureListener<Future<Void>>() {
    @Override
    public void operationComplete(Future<Void> future) throws Exception {
      if (!future.isSuccess() && !originalPromise.isDone()) {
        originalPromise.setFailure(future.cause());
      }
    }
  });
  ctx.connect(remoteAddress, localAddress, inboundPromise);
}
 
Example 3
Source File: AbstractHttpHandler.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("FutureReturnValueIgnored")
@Override
public void connect(
    ChannelHandlerContext ctx,
    SocketAddress remoteAddress,
    SocketAddress localAddress,
    ChannelPromise promise) {
  ctx.connect(remoteAddress, localAddress, promise);
}
 
Example 4
Source File: HttpClientPipelineConfigurator.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Override
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress,
                    ChannelPromise promise) throws Exception {

    // Remember the requested remote address for later use.
    final InetSocketAddress inetRemoteAddr = (InetSocketAddress) remoteAddress;
    this.remoteAddress = inetRemoteAddr;

    // Configure the pipeline.
    final Channel ch = ctx.channel();
    ChannelUtil.disableWriterBufferWatermark(ch);

    final ChannelPipeline p = ch.pipeline();
    p.addLast(new FlushConsolidationHandler());
    p.addLast(ReadSuppressingAndChannelDeactivatingHandler.INSTANCE);

    try {
        if (sslCtx != null) {
            configureAsHttps(ch, inetRemoteAddr);
        } else {
            configureAsHttp(ch);
        }
    } catch (Throwable t) {
        promise.tryFailure(t);
        ctx.close();
    } finally {
        if (p.context(this) != null) {
            p.remove(this);
        }
    }

    ctx.connect(remoteAddress, localAddress, promise);
}
 
Example 5
Source File: KeyValueErrorMapHandler.java    From couchbase-jvm-core with Apache License 2.0 5 votes vote down vote up
@Override
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress,
                    ChannelPromise promise) throws Exception {
    originalPromise = promise;
    ChannelPromise downPromise = ctx.newPromise();
    downPromise.addListener(new GenericFutureListener<Future<Void>>() {
        @Override
        public void operationComplete(Future<Void> future) throws Exception {
            if (!future.isSuccess() && !originalPromise.isDone()) {
                originalPromise.setFailure(future.cause());
            }
        }
    });
    ctx.connect(remoteAddress, localAddress, downPromise);
}
 
Example 6
Source File: TsiFrameHandler.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Override
public void connect(
    ChannelHandlerContext ctx,
    SocketAddress remoteAddress,
    SocketAddress localAddress,
    ChannelPromise promise) {
  ctx.connect(remoteAddress, localAddress, promise);
}
 
Example 7
Source File: LoggingHandler.java    From netty.book.kor with MIT License 5 votes vote down vote up
@Override
public void connect(
        ChannelHandlerContext ctx,
        SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception {
    if (logger.isEnabled(internalLevel)) {
        logger.log(internalLevel, format(ctx, "CONNECT", remoteAddress, localAddress));
    }
    ctx.connect(remoteAddress, localAddress, promise);
}
 
Example 8
Source File: TsiFrameHandler.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Override
public void connect(
    ChannelHandlerContext ctx,
    SocketAddress remoteAddress,
    SocketAddress localAddress,
    ChannelPromise promise) {
  ctx.connect(remoteAddress, localAddress, promise);
}
 
Example 9
Source File: KeyValueSelectBucketHandler.java    From couchbase-jvm-core with Apache License 2.0 5 votes vote down vote up
@Override
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress,
                    ChannelPromise promise) throws Exception {
    originalPromise = promise;
    ChannelPromise downPromise = ctx.newPromise();
    downPromise.addListener(new GenericFutureListener<Future<Void>>() {
        @Override
        public void operationComplete(Future<Void> future) throws Exception {
            if (!future.isSuccess() && !originalPromise.isDone()) {
                originalPromise.setFailure(future.cause());
            }
        }
    });
    ctx.connect(remoteAddress, localAddress, downPromise);
}
 
Example 10
Source File: LoggingHandler.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
public void connect(
        ChannelHandlerContext ctx,
        SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception {
    if (logger.isEnabled(internalLevel)) {
        logger.log(internalLevel, format(ctx, "CONNECT", remoteAddress, localAddress));
    }
    ctx.connect(remoteAddress, localAddress, promise);
}
 
Example 11
Source File: ProxyHandler.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
public final void connect(
        ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress,
        ChannelPromise promise) throws Exception {

    if (destinationAddress != null) {
        promise.setFailure(new ConnectionPendingException());
        return;
    }

    destinationAddress = remoteAddress;
    ctx.connect(proxyAddress, localAddress, promise);
}
 
Example 12
Source File: KeyValueFeatureHandler.java    From couchbase-jvm-core with Apache License 2.0 5 votes vote down vote up
@Override
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress,
    ChannelPromise promise) throws Exception {
    originalPromise = promise;
    ChannelPromise downPromise = ctx.newPromise();
    downPromise.addListener(new GenericFutureListener<Future<Void>>() {
        @Override
        public void operationComplete(Future<Void> future) throws Exception {
            if (!future.isSuccess() && !originalPromise.isDone()) {
                originalPromise.setFailure(future.cause());
            }
        }
    });
    ctx.connect(remoteAddress, localAddress, downPromise);
}
 
Example 13
Source File: FilterLogginglHandler.java    From netty-http-server with Apache License 2.0 4 votes vote down vote up
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) {
    ctx.connect(remoteAddress, localAddress, promise);
}
 
Example 14
Source File: SslHandler.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
@Override
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress,
                    ChannelPromise promise) throws Exception {
    ctx.connect(remoteAddress, localAddress, promise);
}
 
Example 15
Source File: AbstractSniHandler.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
@Override
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress,
                    ChannelPromise promise) throws Exception {
    ctx.connect(remoteAddress, localAddress, promise);
}
 
Example 16
Source File: SpdyFrameCodec.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Override
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress,
                    ChannelPromise promise) throws Exception {
    ctx.connect(remoteAddress, localAddress, promise);
}
 
Example 17
Source File: Http2ConnectionHandler.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
@Override
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress,
                    ChannelPromise promise) throws Exception {
    ctx.connect(remoteAddress, localAddress, promise);
}
 
Example 18
Source File: EndpointedChannelHandler.java    From riiablo with Apache License 2.0 4 votes vote down vote up
@Override
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception {
  if (DEBUG_CALLS) Gdx.app.debug(TAG, "connect");
  ctx.connect(remoteAddress, localAddress, promise);
}
 
Example 19
Source File: EndpointedChannelHandler.java    From riiablo with Apache License 2.0 4 votes vote down vote up
@Override
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception {
  if (DEBUG_CALLS) Gdx.app.debug(TAG, "connect");
  ctx.connect(remoteAddress, localAddress, promise);
}
 
Example 20
Source File: NettyChannelHandlerAdapter.java    From Ak47 with Apache License 2.0 4 votes vote down vote up
@Override
public void connect(ChannelHandlerContext nettyctx, SocketAddress remoteAddress,
        SocketAddress localAddress, ChannelPromise promise)
        throws Exception {
    nettyctx.connect(remoteAddress, localAddress, promise);
}