io.netty.channel.ChannelFuture#isCancelled ( )源码实例Demo

下面列出了io.netty.channel.ChannelFuture#isCancelled ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: armeria   文件: KeepAliveHandler.java
@Override
public void operationComplete(ChannelFuture future) throws Exception {
    if (future.isSuccess()) {
        logger.debug("{} PING write successful", channel);
        final EventLoop el = channel.eventLoop();
        shutdownFuture = el.schedule(shutdownRunnable, pingIdleTimeNanos, TimeUnit.NANOSECONDS);
        pingState = PingState.PENDING_PING_ACK;
        resetStopwatch();
    } else {
        // Mostly because the channel is already closed. So ignore and change state to IDLE.
        // If the channel is closed, we change state to SHUTDOWN on destroy.
        if (!future.isCancelled() && Exceptions.isExpected(future.cause())) {
            logger.debug("{} PING write failed", channel, future.cause());
        }
        if (pingState != PingState.SHUTDOWN) {
            pingState = PingState.IDLE;
        }
    }
}
 
源代码2 项目: redisson   文件: RedisExecutor.java
private void checkWriteFuture(ChannelFuture future, RPromise<R> attemptPromise, RedisConnection connection) {
    if (future.isCancelled() || attemptPromise.isDone()) {
        return;
    }

    if (!future.isSuccess()) {
        exception = new WriteRedisConnectionException(
                "Unable to write command into connection! Node source: " + source + ", connection: " + connection +
                ", command: " + LogHelper.toString(command, params)
                + " after " + attempt + " retry attempts", future.cause());
        if (attempt == attempts) {
            attemptPromise.tryFailure(exception);
        }
        return;
    }

    timeout.cancel();

    scheduleResponseTimeout(attemptPromise, connection);
}
 
源代码3 项目: bgpcep   文件: BmpDispatcherImpl.java
@Override
public void operationComplete(final ChannelFuture future) throws Exception {
    if (future.isCancelled()) {
        LOG.debug("Connection {} cancelled!", future);
    } else if (future.isSuccess()) {
        LOG.debug("Connection {} succeeded!", future);
        future.channel().closeFuture().addListener((ChannelFutureListener) channelFuture -> scheduleConnect());
    } else {
        if (this.delay > MAXIMUM_BACKOFF) {
            LOG.warn("The time of maximum backoff has been exceeded. No further connection attempts with BMP "
                    + "router {}.", this.remoteAddress);
            future.cancel(false);
            return;
        }
        final EventLoop loop = future.channel().eventLoop();
        loop.schedule(() -> this.bootstrap.connect().addListener(this), this.delay, TimeUnit.MILLISECONDS);
        LOG.info("The connection try to BMP router {} failed. Next reconnection attempt in {} milliseconds.",
                this.remoteAddress, this.delay);
        this.delay *= 2;
    }
}
 
源代码4 项目: octo-rpc   文件: NettyClient.java
@Override
protected void doConnect() {
    ChannelFuture future = null;
    if (isClosed()) {
        logger.warn("{} closed, won't do channel connect", this.toString());
    }
    try {
        future = bootstrap.connect(getRemoteAddress());
        future.awaitUninterruptibly();
        if (future.isCancelled()) {
            throw new TransportException("Failed connect to server " + getRemoteAddress() + " from " + getClass().getName() + ", cause it be cancelled");
        } else if (!future.isSuccess()) {
            String errorMsg = future.cause() != null ? future.cause().getMessage() : "";
            throw new TransportException("Failed connect to server " + getRemoteAddress() + " from " + getClass().getName() + "[timeout:" + connTimeout + "ms], cause:" + errorMsg, future.cause());
        }
        NettyChannel oldChannel = this.channel;
        NettyChannel newChannel = ChannelManager.getOrAddChannel(future.channel());
        this.channel = newChannel;

        // 关闭旧的连接
        if (oldChannel != null) {
            if (oldChannel.isConnected()) {
                logger.info("Close old netty channel:{} and create new netty channel:{}", oldChannel, newChannel);
                oldChannel.close();
            }
        }

    } catch (Exception e) {
        if (e instanceof TransportException) {
            throw e;
        }
        throw new TransportException("Failed to connect to server " + getRemoteAddress(), e);
    } finally {
        if (future != null && !isConnected()) {
            future.cancel(true);
        }
    }
}
 
源代码5 项目: TakinRPC   文件: RpcClient.java
@Override
public void operationComplete(ChannelFuture future) throws Exception {
    if (future.isDone() && future.isSuccess()) {
        set(new NettyRpcChannel(future.channel()));
    } else if (future.isDone() && future.cause() != null) {
        setException(future.cause());
    } else if (future.isDone() && future.isCancelled()) {
        cancel(false);
    }
}
 
源代码6 项目: bgpcep   文件: BmpMockDispatcher.java
@Override
public void operationComplete(final ChannelFuture future) throws Exception {
    if (future.isCancelled()) {
        LOG.debug("Connection {} cancelled!", future);
    } else if (future.isSuccess()) {
        LOG.debug("Connection {} succeeded!", future);
        future.channel().closeFuture().addListener((ChannelFutureListener) channelFuture -> scheduleConnect());
    } else {
        final EventLoop loop = future.channel().eventLoop();
        loop.schedule(() -> this.bootstrap.connect().addListener(this), this.delay, TimeUnit.MILLISECONDS);
        LOG.info("The connection try to BMP router {} failed. Next reconnection attempt in {} milliseconds.",
                this.remoteAddress, this.delay);
    }
}
 
源代码7 项目: netty-http2   文件: HttpStreamEncoder.java
public void operationComplete(ChannelFuture future) throws Exception {
    if (future.isSuccess()) {
        ctx.writeAndFlush(msg, promise);
    } else if (future.isCancelled()) {
        ReferenceCountUtil.release(msg);
        promise.cancel(true);
    } else {
        ReferenceCountUtil.release(msg);
        promise.setFailure(future.cause());
    }
}