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


Java EventLoop.execute方法代码示例

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


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

示例1: channelInactive

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
    LOG.info(">>> channelUnregistered");
    if (unrecognizedName) {
        LOG.info(">>> unrecognizedName retry");
        final EventLoop loop = ctx.channel().eventLoop();
        loop.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    client.retry(loop);
                } catch (InterruptedException e) {
                    LOG.info(">>> retry interrupted, shutdown");
                    client.stop();
                }
            }
        });
    } else {
        LOG.info(">>> shutdown sucessfully");
        client.stop();
    }
}
 
开发者ID:wxyzZ,项目名称:little_mitm,代码行数:23,代码来源:RetryClient.java

示例2: addAsync

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
public Future<Boolean> addAsync(final V value) {
    EventLoop loop = commandExecutor.getConnectionManager().getGroup().next();
    final Promise<Boolean> promise = loop.newPromise();

    loop.execute(new Runnable() {
        @Override
        public void run() {
            try {
                boolean result = add(value);
                promise.setSuccess(result);
            } catch (Exception e) {
                promise.setFailure(e);
            }
        }
    });

    return promise;
}
 
开发者ID:rollenholt-SourceReading,项目名称:redisson,代码行数:19,代码来源:RedissonSortedSet.java

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: start

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
void start() {
    if ( !running.get() && running.compareAndSet( false, true ) ) {
        EventLoop eventLoop = eventLoopRef.get();
        if ( eventLoop != null ) {
            eventLoop.execute( this );
        }
    }
}
 
开发者ID:GoMint,项目名称:ProxProx,代码行数:9,代码来源:ConnectionHandler.java

示例13: 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

示例14: buildNewDuplexObject

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
/**
 * Only called when we have established a NEW channel therefore it will use a simple
 * Incrementing counter to hand out unique identifiers for connections.
 * 
 * @param channel
 * @return
 */
public ContentToPronghornPipe buildNewDuplexObject(final Channel channel) {
    
    long threadId = Thread.currentThread().getId();        
    int pipeOrdinal = LongHashTable.getItem(threadsToOrdinals, threadId);
    int pipeIdx;                  
    if (0==pipeOrdinal) {
      //pick the next free pipes as ours, this thread has never seen a pipe before
      //threads are re-used across many connections so this sync code is only called when warming up
      synchronized(threadsToOrdinals) {              
          pipeOrdinal = ++assignedPipeCount;
          LongHashTable.setItem(threadsToOrdinals, threadId, pipeOrdinal);              
      } 
      pipeIdx = pipeOrdinal-1;
      channelLookup[pipeIdx] = new ServiceObjectHolder<Channel>(Channel.class, validator, true /*should grow*/); //WARNING: will use more memory
      
      subscriptionLookup[pipeIdx] = new MemberHolder(64);
      
      EventLoop eventLoop = channel.eventLoop();
      eventLoop.execute(new PronghornPipeToChannel(channelLookup[pipeIdx], fromPronghorn[pipeIdx], toPronghorn[pipeIdx], subscriptionLookup[pipeIdx], eventLoop));
      
    } else {
        pipeIdx = pipeOrdinal-1; 
    }
    
    //we know this is only called by the same thread for this channelId instance.
    return new ContentToPronghornPipe(channelLookup[pipeIdx].add(channel), toPronghorn[pipeIdx], pipeIdx);  
}
 
开发者ID:oci-pronghorn,项目名称:NettyStages,代码行数:35,代码来源:PronghornFullDuplexManager.java

示例15: doWrite

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
@Override
protected void doWrite(ChannelOutboundBuffer in) throws Exception {
    if (state < 2) {
        throw new NotYetConnectedException();
    }
    if (state > 2) {
        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);
            }
        });
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:42,代码来源:LocalChannel.java


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