当前位置: 首页>>代码示例>>Java>>正文


Java EventLoop.inEventLoop方法代码示例

本文整理汇总了Java中io.netty.channel.EventLoop.inEventLoop方法的典型用法代码示例。如果您正苦于以下问题:Java EventLoop.inEventLoop方法的具体用法?Java EventLoop.inEventLoop怎么用?Java EventLoop.inEventLoop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.netty.channel.EventLoop的用法示例。


在下文中一共展示了EventLoop.inEventLoop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shutdownOutput

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
@Override
public ChannelFuture shutdownOutput(final ChannelPromise future) {
    EventLoop loop = eventLoop();
    if (loop.inEventLoop()) {
        try {
            socket.shutdownOutput();
            future.setSuccess();
        } catch (Throwable t) {
            future.setFailure(t);
        }
    } else {
        loop.execute(new Runnable() {
            @Override
            public void run() {
                shutdownOutput(future);
            }
        });
    }
    return future;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:21,代码来源:OioSocketChannel.java

示例2: shutdownOutput

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
@Override
public ChannelFuture shutdownOutput(final ChannelPromise promise) {
    Executor closeExecutor = ((NioSocketChannelUnsafe) unsafe()).closeExecutor();
    if (closeExecutor != null) {
        closeExecutor.execute(new OneTimeTask() {
            @Override
            public void run() {
                shutdownOutput0(promise);
            }
        });
    } else {
        EventLoop loop = eventLoop();
        if (loop.inEventLoop()) {
            shutdownOutput0(promise);
        } else {
            loop.execute(new OneTimeTask() {
                @Override
                public void run() {
                    shutdownOutput0(promise);
                }
            });
        }
    }
    return promise;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:26,代码来源:NioSocketChannel.java

示例3: clearEpollIn

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
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();
                    }
                }
            });
        }
    } else  {
        // The EventLoop is not registered atm so just update the flags so the correct value
        // will be used once the channel is registered
        flags &= ~readFlag;
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:26,代码来源:AbstractEpollChannel.java

示例4: shutdownOutput

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
@Override
public ChannelFuture shutdownOutput(final ChannelPromise promise) {
    Executor closeExecutor = ((EpollSocketChannelUnsafe) unsafe()).closeExecutor();
    if (closeExecutor != null) {
        closeExecutor.execute(new OneTimeTask() {
            @Override
            public void run() {
                shutdownOutput0(promise);
            }
        });
    } else {
        EventLoop loop = eventLoop();
        if (loop.inEventLoop()) {
            shutdownOutput0(promise);
        } else {
            loop.execute(new OneTimeTask() {
                @Override
                public void run() {
                    shutdownOutput0(promise);
                }
            });
        }
    }
    return promise;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:26,代码来源:EpollSocketChannel.java

示例5: release

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
@Override
public Future<Void> release(final K key, final Channel channel, final Promise<Void> promise) {
    requireNonNull(key, "key");
    requireNonNull(channel, "channel");
    requireNonNull(promise, "promise");

    try {
        EventLoop loop = channel.eventLoop();
        if (loop.inEventLoop()) {
            doRelease(key, channel, promise);
        } else {
            loop.execute(() -> doRelease(key, channel, promise));
        }
    } catch (Throwable cause) {
        closeAndFail(channel, cause, promise);
    }
    return promise;
}
 
开发者ID:line,项目名称:armeria,代码行数:19,代码来源:DefaultKeyedChannelPool.java

示例6: shutdownOutput

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
@Override
public ChannelFuture shutdownOutput(final ChannelPromise promise) {
    EventLoop loop = eventLoop();
    if (loop.inEventLoop()) {
        try {
            javaChannel().socket().shutdownOutput();
            promise.setSuccess();
        } catch (Throwable t) {
            promise.setFailure(t);
        }
    } else {
        loop.execute(new Runnable() {
            @Override
            public void run() {
                shutdownOutput(promise);
            }
        });
    }
    return promise;
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:21,代码来源:NioSocketChannel.java

示例7: pauseReceiver

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:31,代码来源:NettyClient.java

示例8: pauseReceiver

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:31,代码来源:NettyServerClient.java

示例9: send

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
@Override
public void send(WireCommand cmd) {
    Channel c = getChannel();
    // Work around for https://github.com/netty/netty/issues/3246
    EventLoop eventLoop = c.eventLoop();
    if (eventLoop.inEventLoop()) {
        eventLoop.execute(() -> writeAndFlush(c, cmd));
    } else {
        writeAndFlush(c, cmd);
    }
}
 
开发者ID:pravega,项目名称:pravega,代码行数:12,代码来源:ServerConnectionInboundHandler.java

示例10: send

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
/**
 * Sends a array of {@link Message}s.
 *
 * @param messages The messages
 */
public void send(Message... messages) {
    checkNotNull(messages, "messages");
    checkArgument(messages.length != 0, "messages cannot be empty");
    if (!this.channel.isActive()) {
        return;
    }
    final ChannelPromise voidPromise = this.channel.voidPromise();
    if (messages.length == 1) {
        this.channel.writeAndFlush(messages[0], voidPromise);
    } else {
        final EventLoop eventLoop = this.channel.eventLoop();
        if (eventLoop.inEventLoop()) {
            for (Message message : messages) {
                ReferenceCountUtil.retain(message);
                this.channel.writeAndFlush(message, voidPromise);
            }
        } else {
            // If there are more then one message, combine them inside the
            // event loop to reduce overhead of wakeup calls and object creation

            // Create a copy of the list, to avoid concurrent modifications
            final List<Message> messages0 = ImmutableList.copyOf(messages);
            messages0.forEach(ReferenceCountUtil::retain);
            eventLoop.submit(() -> {
                for (Message message0 : messages0) {
                    this.channel.writeAndFlush(message0, voidPromise);
                }
            });
        }
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:37,代码来源:NetworkSession.java

示例11: doClose

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
@Override
protected void doClose() throws Exception {
    if (state <= 2) {
        // Update all internal state before the closeFuture is notified.
        if (localAddress != null) {
            if (parent() == null) {
                LocalChannelRegistry.unregister(localAddress);
            }
            localAddress = null;
        }
        state = 3;
    }

    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() {
                    peer.unsafe().close(unsafe().voidPromise());
                }
            });
        }
        this.peer = null;
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:37,代码来源:LocalChannel.java

示例12: write

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
@Override
public final void write(ActiveMQBuffer buffer,
                        final boolean flush,
                        final boolean batched,
                        final ChannelFutureListener futureListener) {
   final int readableBytes = buffer.readableBytes();
   if (logger.isDebugEnabled()) {
      final int remainingBytes = this.writeBufferHighWaterMark - readableBytes;
      if (remainingBytes < 0) {
         logger.debug("a write request is exceeding by " + (-remainingBytes) + " bytes the writeBufferHighWaterMark size [ " + this.writeBufferHighWaterMark + " ] : consider to set it at least of " + readableBytes + " bytes");
      }
   }
   //no need to lock because the Netty's channel is thread-safe
   //and the order of write is ensured by the order of the write calls
   final EventLoop eventLoop = channel.eventLoop();
   final boolean inEventLoop = eventLoop.inEventLoop();
   if (!inEventLoop) {
      writeNotInEventLoop(buffer, flush, batched, futureListener);
   } else {
      // OLD COMMENT:
      // 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.
      // NOTE:
      // the submitted task does not effect in any way the current written size in the batch
      // until the loop will process it, leading to a longer life for the ActiveMQBuffer buffer!!!
      // To solve it, will be necessary to manually perform the count of the current batch instead of rely on the
      // Channel:Config::writeBufferHighWaterMark value.
      this.pendingWritesOnEventLoop += readableBytes;
      this.pendingWritesOnEventLoopView.lazySet(pendingWritesOnEventLoop);
      eventLoop.execute(() -> {
         this.pendingWritesOnEventLoop -= readableBytes;
         this.pendingWritesOnEventLoopView.lazySet(pendingWritesOnEventLoop);
         writeInEventLoop(buffer, flush, batched, futureListener);
      });
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:38,代码来源:NettyConnection.java

示例13: doClose

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
@Override
protected void doClose() throws Exception {
    if (state <= 2) {
        // Update all internal state before the closeFuture is notified.
        if (localAddress != null) {
            if (parent() == null) {
                LocalChannelRegistry.unregister(localAddress);
            }
            localAddress = null;
        }
        state = 3;
    }

    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();
        if (eventLoop.inEventLoop()) {
            peer.unsafe().close(unsafe().voidPromise());
        } else {
            peer.eventLoop().execute(new Runnable() {
                @Override
                public void run() {
                    peer.unsafe().close(unsafe().voidPromise());
                }
            });
        }
        this.peer = null;
    }
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:32,代码来源:LocalChannel.java

示例14: doClose

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
@Override
protected void doClose() throws Exception {
    if (state != State.CLOSED) {
        // Update all internal state before the closeFuture is notified.
        if (localAddress != null) {
            if (parent() == null) {
                LocalChannelRegistry.unregister(localAddress);
            }
            localAddress = null;
        }
        state = State.CLOSED;
    }

    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();
        if (eventLoop.inEventLoop()) {
            peer.unsafe().close(unsafe().voidPromise());
        } else {
            peer.eventLoop().execute(new Runnable() {
                @Override
                public void run() {
                    peer.unsafe().close(unsafe().voidPromise());
                }
            });
        }
        this.peer = null;
    }
}
 
开发者ID:nathanchen,项目名称:netty-netty-5.0.0.Alpha1,代码行数:32,代码来源:LocalChannel.java

示例15: sendWithFuture

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
/**
 * Sends a array of {@link Message}s and returns the {@link ChannelFuture}.
 *
 * @param messages The messages
 * @return The channel future
 */
public ChannelFuture sendWithFuture(Message... messages) {
    checkNotNull(messages, "messages");
    checkArgument(messages.length != 0, "messages cannot be empty");
    final ChannelPromise promise = this.channel.newPromise();
    if (!this.channel.isActive()) {
        return promise;
    }
    promise.addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
    // Don't bother checking if we are in the event loop,
    // there is only one message.
    if (messages.length == 1) {
        this.channel.writeAndFlush(messages[0], promise);
    } else {
        final EventLoop eventLoop = this.channel.eventLoop();
        final ChannelPromise voidPromise = this.channel.voidPromise();
        if (eventLoop.inEventLoop()) {
            final int last = messages.length - 1;
            for (int i = 0; i < last; i++) {
                ReferenceCountUtil.retain(messages[i]);
                this.channel.writeAndFlush(messages[i], voidPromise);
            }
            ReferenceCountUtil.retain(messages[last]);
            this.channel.writeAndFlush(messages[last], promise);
        } else {
            // If there are more then one message, combine them inside the
            // event loop to reduce overhead of wakeup calls and object creation

            // Create a copy of the list, to avoid concurrent modifications
            final List<Message> messages0 = ImmutableList.copyOf(messages);
            messages0.forEach(ReferenceCountUtil::retain);
            eventLoop.submit(() -> {
                final Iterator<Message> it0 = messages0.iterator();
                do {
                    final Message message0 = it0.next();
                    // Only use a normal channel promise for the last message
                    this.channel.writeAndFlush(message0, it0.hasNext() ? voidPromise : promise);
                } while (it0.hasNext());
            });
        }
    }
    return promise;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:49,代码来源:NetworkSession.java


注:本文中的io.netty.channel.EventLoop.inEventLoop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。