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

The following examples show how to use io.netty.channel.ChannelHandlerContext#disconnect() . 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: LispChannelHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt)
        throws Exception {

    if (evt instanceof IdleStateEvent) {
        IdleStateEvent event = (IdleStateEvent) evt;
        if (event.state() == IdleState.READER_IDLE) {
            log.info("READER_IDLE read timeout");
            ctx.disconnect();
        } else if (event.state() == IdleState.WRITER_IDLE) {
            log.info("WRITER_IDLE write timeout");
            ctx.disconnect();
        } else if (event.state() == IdleState.ALL_IDLE) {
            log.info("ALL_IDLE total timeout");
            ctx.disconnect();
        }
    }
}
 
Example 2
Source File: ChannelHandler.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
    // logger.error("network error ", cause);
    // lost the connection,get ip info
    String host = ((SocketChannel) ctx.channel()).remoteAddress().getAddress().getHostAddress();
    Integer port = ((SocketChannel) ctx.channel()).remoteAddress().getPort();

    logger.debug(
            " exceptionCaught, disconnect "
                    + host
                    + ":"
                    + String.valueOf(port)
                    + " ,"
                    + String.valueOf(ctx.channel().isActive()));

    ctx.disconnect();
    ctx.close();
}
 
Example 3
Source File: HttpConnectionHandler.java    From netty-http2 with Apache License 2.0 5 votes vote down vote up
@Override
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
    // HTTP/2 connection requirements:
    //
    // When either endpoint closes the transport-level connection,
    // it must first send a GOAWAY frame.
    //
    // Avoid NotYetConnectedException
    if (!ctx.channel().isActive()) {
        ctx.disconnect(promise);
    } else {
        sendGoAwayFrame(ctx, promise);
    }
}
 
Example 4
Source File: LoggingHandler.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
    if (logger.isEnabled(internalLevel)) {
        logger.log(internalLevel, format(ctx, "DISCONNECT"));
    }
    ctx.disconnect(promise);
}
 
Example 5
Source File: LoggingHandler.java    From netty.book.kor with MIT License 5 votes vote down vote up
@Override
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
    if (logger.isEnabled(internalLevel)) {
        logger.log(internalLevel, format(ctx, "DISCONNECT"));
    }
    ctx.disconnect(promise);
}
 
Example 6
Source File: SslHandler.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
private void closeOutboundAndChannel(
        final ChannelHandlerContext ctx, final ChannelPromise promise, boolean disconnect) throws Exception {
    if (!ctx.channel().isActive()) {
        if (disconnect) {
            ctx.disconnect(promise);
        } else {
            ctx.close(promise);
        }
        return;
    }

    outboundClosed = true;
    engine.closeOutbound();

    ChannelPromise closeNotifyPromise = ctx.newPromise();
    try {
        flush(ctx, closeNotifyPromise);
    } finally {
        // It's important that we do not pass the original ChannelPromise to safeClose(...) as when flush(....)
        // throws an Exception it will be propagated to the AbstractChannelHandlerContext which will try
        // to fail the promise because of this. This will then fail as it was already completed by safeClose(...).
        // We create a new ChannelPromise and try to notify the original ChannelPromise
        // once it is complete. If we fail to do so we just ignore it as in this case it was failed already
        // because of a propagated Exception.
        //
        // See https://github.com/netty/netty/issues/5931
        safeClose(ctx, closeNotifyPromise, ctx.newPromise().addListener(
                new ChannelPromiseNotifier(false, promise)));
    }
}
 
Example 7
Source File: FilterLogginglHandler.java    From netty-http-server with Apache License 2.0 4 votes vote down vote up
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) {
    ctx.disconnect(promise);
}
 
Example 8
Source File: ReliableChannelHandler.java    From riiablo with Apache License 2.0 4 votes vote down vote up
@Override
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
  Gdx.app.debug(TAG, "disconnect");
  ctx.disconnect(promise);
}
 
Example 9
Source File: KeyValueErrorMapHandler.java    From couchbase-jvm-core with Apache License 2.0 4 votes vote down vote up
@Override
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
    ctx.disconnect(promise);
}
 
Example 10
Source File: SpdyFrameCodec.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Override
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
    ctx.disconnect(promise);
}
 
Example 11
Source File: ConnectInterceptingHandler.java    From java-dcp-client with Apache License 2.0 4 votes vote down vote up
@Override
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
  ctx.disconnect(promise);
}
 
Example 12
Source File: NettyChannelHandlerAdapter.java    From Ak47 with Apache License 2.0 4 votes vote down vote up
@Override
public void disconnect(ChannelHandlerContext nettyctx, ChannelPromise promise)
        throws Exception {
    nettyctx.disconnect(promise);
}
 
Example 13
Source File: TsiFrameHandler.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
@Override
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) {
  ctx.disconnect(promise);
}
 
Example 14
Source File: FlushConsolidationHandler.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
@Override
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
    // Try to flush one last time if flushes are pending before disconnect the channel.
    resetReadAndFlushIfNeeded(ctx);
    ctx.disconnect(promise);
}
 
Example 15
Source File: EndpointedChannelHandler.java    From riiablo with Apache License 2.0 4 votes vote down vote up
@Override
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
  if (DEBUG_CALLS) Gdx.app.debug(TAG, "disconnect");
  ctx.disconnect(promise);
}
 
Example 16
Source File: ReliableChannelHandler.java    From riiablo with Apache License 2.0 4 votes vote down vote up
@Override
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
  Gdx.app.debug(TAG, "disconnect");
  ctx.disconnect(promise);
}
 
Example 17
Source File: AbstractHttpHandler.java    From bazel with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("FutureReturnValueIgnored")
@Override
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) {
  failAndResetUserPromise(new ClosedChannelException());
  ctx.disconnect(promise);
}
 
Example 18
Source File: KeyValueAuthHandler.java    From couchbase-jvm-core with Apache License 2.0 4 votes vote down vote up
@Override
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
    ctx.disconnect(promise);
}
 
Example 19
Source File: KeyValueSelectBucketHandler.java    From couchbase-jvm-core with Apache License 2.0 4 votes vote down vote up
@Override
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
    ctx.disconnect(promise);
}
 
Example 20
Source File: RntbdRequestManager.java    From azure-cosmosdb-java with MIT License 2 votes vote down vote up
/**
 * Called once a disconnect operation is made.
 *
 * @param context the {@link ChannelHandlerContext} for which the disconnect operation is made
 * @param promise the {@link ChannelPromise} to notify once the operation completes
 */
@Override
public void disconnect(final ChannelHandlerContext context, final ChannelPromise promise) {
    this.traceOperation(context, "disconnect");
    context.disconnect(promise);
}