io.netty.channel.Channel#eventLoop ( )源码实例Demo

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

源代码1 项目: netty-4.1.22   文件: SimpleChannelPool.java
@Override
    public Future<Void> release(final Channel channel, final Promise<Void> promise) {
        checkNotNull(channel, "channel");
        checkNotNull(promise, "promise");
        try {
            EventLoop loop = channel.eventLoop();
            if (loop.inEventLoop()) {
                doReleaseChannel(channel, promise);
            } else {
                loop.execute(new Runnable() {
                    @Override
                    public void run() {
//                        释放channel
                        doReleaseChannel(channel, promise);
                    }
                });
            }
        } catch (Throwable cause) {
//            关闭channel,发布promise失败事件
            closeAndFail(channel, cause, promise);
        }
        return promise;
    }
 
源代码2 项目: pravega   文件: ClientConnectionImpl.java
private void write(Append cmd) throws ConnectionFailedException {
    Channel channel = nettyHandler.getChannel();
    EventLoop eventLoop = channel.eventLoop();
    ChannelPromise promise = channel.newPromise();
    promise.addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(ChannelFuture future) {
            throttle.release(cmd.getDataLength());
            nettyHandler.setRecentMessage();
            if (!future.isSuccess()) {
                future.channel().pipeline().fireExceptionCaught(future.cause());
            }
        }
    });
    // Work around for https://github.com/netty/netty/issues/3246
    eventLoop.execute(() -> {
        try {
            if (!closed.get()) {
                channel.write(cmd, promise);
            }
        } catch (Exception e) {
            channel.pipeline().fireExceptionCaught(e);
        }
    });
    Exceptions.handleInterrupted(() -> throttle.acquire(cmd.getDataLength()));
}
 
源代码3 项目: pravega   文件: ClientConnectionImpl.java
private void write(WireCommand cmd) throws ConnectionFailedException {
    Channel channel = nettyHandler.getChannel();
    EventLoop eventLoop = channel.eventLoop();
    ChannelPromise promise = channel.newPromise();
    promise.addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(ChannelFuture future) {
            nettyHandler.setRecentMessage();
            if (!future.isSuccess()) {
                future.channel().pipeline().fireExceptionCaught(future.cause());
            }
        }
    });
    // Work around for https://github.com/netty/netty/issues/3246
    eventLoop.execute(() -> {
        try {
            if (!closed.get()) {
                channel.write(cmd, promise);
            }
        } catch (Exception e) {
            channel.pipeline().fireExceptionCaught(e);
        }
    });
}
 
源代码4 项目: netty-4.1.22   文件: SimpleChannelPool.java
/**
     * Tries to retrieve healthy channel from the pool if any or creates a new channel otherwise.尝试从池中检索健康通道(如果有的话)或创建新的通道。
     * @param promise the promise to provide acquire result.
     * @return future for acquiring a channel.
     */
    private Future<Channel> acquireHealthyFromPoolOrNew(final Promise<Channel> promise) {
        try {
//            从deque中获取一个channel,这里是用双端队列存储的channel
            final Channel ch = pollChannel();
            if (ch == null) {
                // No Channel left in the pool bootstrap a new Channel池中没有剩余通道引导新通道
                Bootstrap bs = bootstrap.clone();
                bs.attr(POOL_KEY, this);
//                如果channel不存在就创建一个
                ChannelFuture f = connectChannel(bs);
                if (f.isDone()) {
//                    promise发布连接成功事件
                    notifyConnect(f, promise);
                } else {
                    f.addListener(new ChannelFutureListener() {
                        @Override
                        public void operationComplete(ChannelFuture future) throws Exception {
                            notifyConnect(future, promise);
                        }
                    });
                }
                return promise;
            }
            EventLoop loop = ch.eventLoop();
            if (loop.inEventLoop()) {
                doHealthCheck(ch, promise);
            } else {
                loop.execute(new Runnable() {
                    @Override
                    public void run() {
                        doHealthCheck(ch, promise);
                    }
                });
            }
        } catch (Throwable cause) {
            promise.tryFailure(cause);
        }
        return promise;
    }
 
源代码5 项目: ftdc   文件: FtdClientPool.java
@Override
public Future<Boolean> isHealthy(Channel channel) {
	EventLoop loop = channel.eventLoop();
	if(!channel.isActive()) {
		logger.warn("local addr: {}, remote addr {} , channel not active, closed..", channel.localAddress(), channel.remoteAddress());
	}
	return channel.isActive() ? loop.newSucceededFuture(Boolean.TRUE) : loop.newSucceededFuture(Boolean.FALSE);
}
 
源代码6 项目: xrpc   文件: XrpcRequest.java
public XrpcRequest(
    FullHttpRequest request,
    ServerContext connectionContext,
    Map<String, String> groups,
    Channel channel) {
  this.h1Request = request;
  this.h2Headers = null;
  this.connectionContext = connectionContext;
  this.groups = groups;
  this.upstreamChannel = channel;
  this.alloc = channel.alloc();
  this.eventLoop = channel.eventLoop();
  this.h2Data = null;
}
 
源代码7 项目: xrpc   文件: XrpcRequest.java
public XrpcRequest(
    Http2Headers headers,
    ServerContext connectionContext,
    Map<String, String> groups,
    Channel channel) {
  this.h1Request = null;
  this.h2Headers = headers;
  this.connectionContext = connectionContext;
  this.groups = groups;
  this.upstreamChannel = channel;
  this.alloc = channel.alloc();
  this.eventLoop = channel.eventLoop();
  this.h2Data = alloc.compositeBuffer();
}
 
源代码8 项目: aws-sdk-java-v2   文件: ReleaseOnceChannelPool.java
@Override
public Future<Void> release(Channel channel) {
    if (shouldRelease(channel)) {
        return delegate.release(channel);
    } else {
        return new SucceededFuture<>(channel.eventLoop(), null);
    }
}
 
源代码9 项目: pravega   文件: ServerConnectionInboundHandler.java
@Override
public void send(WireCommand cmd) {
    Channel c = getChannel();
    // Work around for https://github.com/netty/netty/issues/3246
    EventLoop eventLoop = c.eventLoop();
    eventLoop.execute(() -> write(c, cmd));
}
 
源代码10 项目: catalyst   文件: NettyHandler.java
/**
 * Returns the current execution context or creates one.
 */
private ThreadContext getOrCreateContext(Channel channel) {
  ThreadContext context = ThreadContext.currentContext();
  if (context != null) {
    return context;
  }
  return new SingleThreadContext(Thread.currentThread(), channel.eventLoop(), this.context.serializer().clone());
}
 
源代码11 项目: xio   文件: XioConnectionPool.java
@Override
public Future<Boolean> isHealthy(Channel channel) {
  EventLoop loop = channel.eventLoop();
  if (channel.isActive()) {
    passedHealthCheckCount.incrementAndGet();
    return loop.newSucceededFuture(Boolean.TRUE);
  } else {
    failedHealthCheckCount.incrementAndGet();
    return loop.newSucceededFuture(Boolean.FALSE);
  }
}
 
源代码12 项目: netty-4.1.22   文件: ChannelHealthChecker.java
@Override
public Future<Boolean> isHealthy(Channel channel) {
    EventLoop loop = channel.eventLoop();
    return channel.isActive()? loop.newSucceededFuture(Boolean.TRUE) : loop.newSucceededFuture(Boolean.FALSE);
}
 
源代码13 项目: turbo-rpc   文件: BatchSender.java
public BatchSender(Channel channel) {
	this.channel = channel;
	this.voidPromise = channel.voidPromise();
	this.eventLoop = channel.eventLoop();
}
 
源代码14 项目: servicetalk   文件: NettyChannelPublisher.java
NettyChannelPublisher(Channel channel, Predicate<T> terminalSignalPredicate, CloseHandler closeHandler) {
    this.eventLoop = channel.eventLoop();
    this.channel = channel;
    this.closeHandler = closeHandler;
    this.terminalSignalPredicate = requireNonNull(terminalSignalPredicate);
}
 
源代码15 项目: blynk-server   文件: Session.java
public boolean isSameEventLoop(Channel channel) {
    return initialEventLoop == channel.eventLoop();
}
 
源代码16 项目: netty-zmtp   文件: BatchFlusher.java
public BatchFlusher(final Channel channel, final int maxPending) {
  this.channel = channel;
  this.maxPending = maxPending;
  this.eventLoop = channel.eventLoop();
}