本文整理匯總了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();
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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 );
}
}
}
示例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);
});
}
}
示例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);
}
示例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);
}
});
}
}