Package io.netty.channel

Examples of io.netty.channel.EventLoop


    }

    final void clearEpollIn() {
        // Only clear if registered with an EventLoop as otherwise
        if (isRegistered()) {
            final EventLoop loop = eventLoop();
            final AbstractEpollUnsafe unsafe = (AbstractEpollUnsafe) unsafe();
            if (loop.inEventLoop()) {
                unsafe.clearEpollIn0();
            } else {
                // schedule a task to clear the EPOLLIN as it is not safe to modify it directly
                loop.execute(new OneTimeTask() {
                    @Override
                    public void run() {
                        if (!config().isAutoRead() && !unsafe.readPending) {
                            // Still no read triggered so clear it now
                            unsafe.clearEpollIn0();
View Full Code Here


        return shutdownOutput(newPromise());
    }

    @Override
    public ChannelFuture shutdownOutput(final ChannelPromise promise) {
        EventLoop loop = eventLoop();
        if (loop.inEventLoop()) {
            try {
                Native.shutdown(fd, false, true);
                outputShutdown = true;
                promise.setSuccess();
            } catch (Throwable t) {
                promise.setFailure(t);
            }
        } else {
            loop.execute(new Runnable() {
                @Override
                public void run() {
                    shutdownOutput(promise);
                }
            });
View Full Code Here

        final LocalChannel peer = this.peer;
        if (peer != null && peer.isActive()) {
            // Need to execute the close in the correct EventLoop
            // See https://github.com/netty/netty/issues/1777
            EventLoop eventLoop = peer.eventLoop();

            // Also check if the registration was not done yet. In this case we submit the close to the EventLoop
            // to make sure it is run after the registration completes.
            //
            // See https://github.com/netty/netty/issues/2144
            if (eventLoop.inEventLoop() && !registerInProgress) {
                peer.unsafe().close(unsafe().voidPromise());
            } else {
                peer.eventLoop().execute(new Runnable() {
                    @Override
                    public void run() {
View Full Code Here

            throw new ClosedChannelException();
        }

        final LocalChannel peer = this.peer;
        final ChannelPipeline peerPipeline = peer.pipeline();
        final EventLoop peerLoop = peer.eventLoop();

        if (peerLoop == eventLoop()) {
            for (;;) {
                Object msg = in.current();
                if (msg == null) {
                    break;
                }
                peer.inboundBuffer.add(msg);
                ReferenceCountUtil.retain(msg);
                in.remove();
            }
            finishPeerRead(peer, peerPipeline);
        } else {
            // Use a copy because the original msgs will be recycled by AbstractChannel.
            final Object[] msgsCopy = new Object[in.size()];
            for (int i = 0; i < msgsCopy.length; i ++) {
                msgsCopy[i] = ReferenceCountUtil.retain(in.current());
                in.remove();
            }

            peerLoop.execute(new Runnable() {
                @Override
                public void run() {
                    Collections.addAll(peer.inboundBuffer, msgsCopy);
                    finishPeerRead(peer, peerPipeline);
                }
View Full Code Here

      {
         return;
      }

      final SslHandler sslHandler = (SslHandler)channel.pipeline().get("ssl");
      EventLoop eventLoop = channel.eventLoop();
      boolean inEventLoop = eventLoop.inEventLoop();
      //if we are in an event loop we need to close the channel after the writes have finished
      if(!inEventLoop)
      {
         closeSSLAndChannel(sslHandler, channel);
      }
      else
      {
         eventLoop.execute(new Runnable()
         {
            @Override
            public void run()
            {
               closeSSLAndChannel(sslHandler, channel);
View Full Code Here

            else
            {
               promise = channel.voidPromise();
            }

            EventLoop eventLoop = channel.eventLoop();
            boolean inEventLoop = eventLoop.inEventLoop();
            if (!inEventLoop)
            {
               channel.writeAndFlush(buf, promise);
            }
            else
            {
                // create a task which will be picked up by the eventloop and trigger the write.
                // This is mainly needed as this method is triggered by different threads for the same channel.
                // if we not do this we may produce out of order writes.
                final Runnable task = new Runnable()
                {
                    @Override
                    public void run()
                    {
                        channel.writeAndFlush(buf, promise);
                    }
                };
                // execute the task on the eventloop
                eventLoop.execute(task);
            }


            // only try to wait if not in the eventloop otherwise we will produce a deadlock
            if (flush && !inEventLoop)
View Full Code Here

  @Override
  public synchronized EventLoop next() {
    if (workers.isEmpty()) {
      throw new IllegalStateException();
    } else {
      EventLoop worker = workers.get(pos).worker;
      pos++;
      checkPos();
      return worker;
    }
  }
View Full Code Here

    InternalTimerHandler(long timerID, Handler<Long> runnable, boolean periodic, long delay, ContextImpl context) {
      this.context = context;
      this.timerID = timerID;
      this.handler = runnable;
      this.periodic = periodic;
      EventLoop el = context.getEventLoop();
      Runnable toRun = () -> context.runOnContext(this);
      if (periodic) {
        future = el.scheduleAtFixedRate(toRun, delay, delay, TimeUnit.MILLISECONDS);
      } else {
        future = el.schedule(toRun, delay, TimeUnit.MILLISECONDS);
      }
      metrics.timerCreated(timerID);
    }
View Full Code Here

    Handlers<T> handlers = handlerMap.get(worker);
    return handlers == null ? null : handlers.chooseHandler();
  }

  public synchronized void addHandler(Handler<T> handler, ContextImpl context) {
    EventLoop worker = context.getEventLoop();
    availableWorkers.addWorker(worker);
    Handlers<T> handlers = new Handlers<T>();
    Handlers<T> prev = handlerMap.putIfAbsent(worker, handlers);
    if (prev != null) {
      handlers = prev;
View Full Code Here

    handlers.addHandler(new HandlerHolder<>(context, handler));
    hasHandlers = true;
  }

  public synchronized void removeHandler(Handler<T> handler, ContextImpl context) {
    EventLoop worker = context.getEventLoop();
    Handlers<T> handlers = handlerMap.get(worker);
    if (!handlers.removeHandler(new HandlerHolder<>(context, handler))) {
      throw new IllegalStateException("Can't find handler");
    }
    if (handlers.isEmpty()) {
View Full Code Here

TOP

Related Classes of io.netty.channel.EventLoop

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.