Java Code Examples for io.netty.channel.Channel.eventLoop()

The following are Jave code examples for showing how to use eventLoop() of the io.netty.channel.Channel class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: xrpc   File: XrpcRequest.java   Source Code and License Vote up 5 votes
public XrpcRequest(FullHttpRequest request, Map<String, String> groups, Channel channel) {
  this.h1Request = request;
  this.h2Headers = null;
  this.groups = groups;
  this.upstreamChannel = channel;
  this.alloc = channel.alloc();
  this.eventLoop = channel.eventLoop();
  this.streamId = -1;
}
 
Example 2
Project: xrpc   File: XrpcRequest.java   Source Code and License Vote up 5 votes
public XrpcRequest(
    Http2Headers headers, Map<String, String> groups, Channel channel, int streamId) {
  this.h1Request = null;
  this.h2Headers = headers;
  this.groups = groups;
  this.upstreamChannel = channel;
  this.alloc = channel.alloc();
  this.eventLoop = channel.eventLoop();
  this.streamId = streamId;
}
 
Example 3
Project: hekate   File: NettyClient.java   Source Code and License Vote up 5 votes
private void pauseReceiver(boolean pause, Consumer<NetworkEndpoint<T>> callback) {
    ChannelContext localCtx = this.channelCtx;

    if (localCtx != null) {
        if (debug) {
            if (pause) {
                log.debug("Pausing outbound receiver [to={}]", id());
            } else {
                log.debug("Resuming outbound receiver [to={}]", id());
            }
        }

        Channel channel = localCtx.channel();
        EventLoop eventLoop = channel.eventLoop();

        if (eventLoop.inEventLoop()) {
            channel.config().setAutoRead(!pause);

            notifyOnReceivePause(pause, callback, channel);
        } else {
            eventLoop.execute(() -> {
                channel.config().setAutoRead(!pause);

                notifyOnReceivePause(pause, callback, channel);
            });
        }
    } else if (callback != null) {
        callback.accept(this);
    }
}
 
Example 4
Project: hekate   File: NettyServerClient.java   Source Code and License Vote up 5 votes
private void pauseReceiver(boolean pause, Consumer<NetworkEndpoint<Object>> callback) {
    ChannelHandlerContext localCtx = this.handlerCtx;

    if (localCtx != null) {
        if (debug) {
            if (pause) {
                log.debug("Pausing inbound receiver [from={}, protocol={}]", address(), protocol);
            } else {
                log.debug("Resuming Pausing inbound receiver [from={}, protocol={}]", address(), protocol);
            }
        }

        Channel channel = localCtx.channel();
        EventLoop eventLoop = channel.eventLoop();

        if (eventLoop.inEventLoop()) {
            channel.config().setAutoRead(!pause);

            notifyOnReceivePause(pause, callback, channel);
        } else {
            eventLoop.execute(() -> {
                channel.config().setAutoRead(!pause);

                notifyOnReceivePause(pause, callback, channel);
            });
        }
    } else if (callback != null) {
        callback.accept(this);
    }
}
 
Example 5
Project: hekate   File: NettyServerClient.java   Source Code and License Vote up 4 votes
private void init(Channel channel, HandshakeRequest request, HandlerRegistration handlerReg) {
    NettyServerHandlerConfig<Object> cfg = handlerReg.config();

    if (cfg.getLoggerCategory() != null) {
        log = LoggerFactory.getLogger(cfg.getLoggerCategory());

        debug = log.isDebugEnabled();
        trace = log.isTraceEnabled();
    }

    if (debug) {
        log.debug("Initialized connection [from={}, protocol={}]", address(), cfg.getProtocol());
    }

    this.eventLoop = channel.eventLoop();
    this.serverHandler = cfg.getHandler();
    this.handlerReg = handlerReg;
    this.metrics = handlerReg.metrics();
    this.codec = request.codec();

    // Register this client.
    handlerReg.add(this);

    if (metrics != null) {
        channel.pipeline().addFirst(new ChannelTrafficShapingHandler(0, 0, NettyClient.TRAFFIC_SHAPING_INTERVAL) {
            @Override
            protected void doAccounting(TrafficCounter counter) {
                metrics.onBytesReceived(counter.lastReadBytes());
                metrics.onBytesSent(counter.lastWrittenBytes());
            }
        });

        metrics.onConnect();
    }

    // Accept handshake.
    HandshakeAccept accepted = new HandshakeAccept(hbInterval, hbLossThreshold, hbDisabled);

    channel.writeAndFlush(accepted).addListener(future -> {
            if (channel.isOpen()) {
                connectNotified = true;

                // Notify on connect.
                serverHandler.onConnect(request.payload(), this);
            }
        }
    );
}