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


Java EventLoop.schedule方法代码示例

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

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

示例1: scheduleTimeout

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
private <T> void scheduleTimeout(CompletableFuture<T> result, long timeoutMillis) {
    pendingFutures.add(result);
    if (isServerStopping()) {
        pendingFutures.remove(result);
        return;
    }

    final ScheduledFuture<?> timeoutFuture;
    if (timeoutMillis > 0) {
        final EventLoop eventLoop = RequestContext.current().eventLoop();
        timeoutFuture = eventLoop.schedule(() -> result.completeExceptionally(CANCELLATION_EXCEPTION),
                                           timeoutMillis, TimeUnit.MILLISECONDS);
    } else {
        timeoutFuture = null;
    }

    result.whenComplete((revision, cause) -> {
        if (timeoutFuture != null) {
            timeoutFuture.cancel(true);
        }
        pendingFutures.remove(result);
    });
}
 
开发者ID:line,项目名称:centraldogma,代码行数:24,代码来源:WatchService.java


示例2: operationComplete

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
@Override
public void operationComplete(ChannelFuture channelFuture) throws Exception {
    if (!channelFuture.isSuccess()) {
        channelFuture.channel().close();

        if (count.incrementAndGet() < MAX_RETRY) {
            final EventLoop loop = channelFuture.channel().eventLoop();

            loop.schedule(() -> {
                controller.connectRetry(this.ip, this.port, this);
            }, 1L, TimeUnit.SECONDS);
        } else {
            log.info("Connection to the ovsdb {}:{} failed",
                     this.ip.toString(), this.port.toString());
        }
    } else {
        handleNewNodeConnection(channelFuture.channel());
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:20,代码来源:Controller.java


示例3: pauseChannelProxy

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
/**
 * A Netty Channel is paused and don’t accept any command temporarily.
 *
 * @param channelProxy the specified channel proxy
 */
private void pauseChannelProxy(final ChannelProxy channelProxy) {
	channelProxy.paused();
	log.info("Pause a channel proxy from pool. channel proxy: {}", channelProxy);

	if (false == channelProxy.hasWaitingRequests()) {
		return;
	}

	final Channel channel = channelProxy.getChannel();
	EventLoop eventLoop = channel.eventLoop();
	eventLoop.schedule(new Runnable() {
		@Override
		public void run() {
			// cancel all waiting requests belong to this channel
			channelProxy.cancelWaitingRequests();
		}
	}, Constants.CANCEL_WAITING_REQUEST_DELAY, TimeUnit.SECONDS);
}
 
开发者ID:allan-huang,项目名称:remote-procedure-call,代码行数:24,代码来源:ClientChannelManager.java


示例4: stopChannelProxy

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
/**
 * Closes a Netty channel and stops accepting any command.
 *
 * @param channelProxy the specified channel proxy
 */
public void stopChannelProxy(final ChannelProxy channelProxy) {
	channelProxy.setStopped(true);

	final Channel channel = channelProxy.getChannel();
	EventLoop eventLoop = channel.eventLoop();
	eventLoop.schedule(new Runnable() {
		@Override
		public void run() {
			if (channelProxy.hasWaitingRequests()) {
				// cancel all waiting requests belong to this channel
				channelProxy.cancelWaitingRequests();
			}
			// close this unused channel
			channel.close();
		}
	}, Constants.CANCEL_WAITING_REQUEST_DELAY, TimeUnit.SECONDS);

	log.info("Stop a channel proxy from pool. channel proxy: {}", channelProxy);
}
 
开发者ID:allan-huang,项目名称:remote-procedure-call,代码行数:25,代码来源:ClientChannelManager.java


示例5: channelInactive

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
/**
 * Handles an inactive channel and tries to reconnects original remote server
 */
@Override
public void channelInactive(final ChannelHandlerContext context) throws Exception {
	log.info("Client is disconnected from server: {}", context.channel().remoteAddress());

	ChannelProxy channelProxy = ClientChannelManager.getInstance().findChannelProxy(context.channel());
	if (channelProxy == null || channelProxy.isStopped()) {
		log.warn("Fail to find any matching proxy of client channel or this client channel had been stopped.");
		return;
	}

	log.info("Reconnects to remote server after {} seconds.", Constants.RECONNECT_DELAY);

	// delay several seconds to reconnect the original remote server
	EventLoop eventLoop = context.channel().eventLoop();
	eventLoop.schedule(new Runnable() {
		@Override
		public void run() {
			reconnect(context);
		}
	}, Constants.RECONNECT_DELAY, TimeUnit.SECONDS);
}
 
开发者ID:allan-huang,项目名称:remote-procedure-call,代码行数:25,代码来源:ChannelHandlerAdapter.java


示例6: operationComplete

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
@Override
public void operationComplete(final ChannelFuture future) throws Exception {
    if (future.isCancelled()) {
        LOG.debug("Connection {} cancelled!", future);
    } else if (future.isSuccess()) {
        LOG.debug("Connection {} succeeded!", future);
        future.channel().closeFuture().addListener((ChannelFutureListener) channelFuture -> scheduleConnect());
    } else {
        if (this.delay > MAXIMUM_BACKOFF) {
            LOG.warn("The time of maximum backoff has been exceeded. No further connection attempts with BMP "
                    + "router {}.", this.remoteAddress);
            future.cancel(false);
            return;
        }
        final EventLoop loop = future.channel().eventLoop();
        loop.schedule(() -> this.bootstrap.connect().addListener(this), this.delay, TimeUnit.MILLISECONDS);
        LOG.info("The connection try to BMP router {} failed. Next reconnection attempt in {} milliseconds.",
                this.remoteAddress, this.delay);
        this.delay *= 2;
    }
}
 
开发者ID:opendaylight,项目名称:bgpcep,代码行数:22,代码来源:BmpDispatcherImpl.java


示例7: reconnect

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
synchronized void reconnect() {
    if (this.retryTimer == 0) {
        LOG.debug("Retry timer value is 0. Reconnection will not be attempted");
        this.setFailure(this.pending.cause());
        return;
    }

    final EventLoop loop = this.pending.channel().eventLoop();
    loop.schedule(() -> {
        synchronized (BGPProtocolSessionPromise.this) {
            if (BGPProtocolSessionPromise.this.peerSessionPresent) {
                LOG.debug("Connection to {} already exists", BGPProtocolSessionPromise.this.address);
                BGPProtocolSessionPromise.this.connectSkipped = true;
                return;
            }

            BGPProtocolSessionPromise.this.connectSkipped = false;
            LOG.debug("Attempting to connect to {}", BGPProtocolSessionPromise.this.address);
            final ChannelFuture reconnectFuture = BGPProtocolSessionPromise.this.bootstrap.connect();
            reconnectFuture.addListener(new BootstrapConnectListener());
            BGPProtocolSessionPromise.this.pending = reconnectFuture;
        }
    }, this.retryTimer, TimeUnit.SECONDS);
    LOG.debug("Next reconnection attempt in {}s", this.retryTimer);
}
 
开发者ID:opendaylight,项目名称:bgpcep,代码行数:26,代码来源:BGPProtocolSessionPromise.java


示例8: channelUnregistered

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
@Override
public void channelUnregistered(final ChannelHandlerContext ctx) throws Exception {
    if(log.isInfoEnabled()) {
        log.info("Sleeping for {}s before reconnect.", reconnectTimeUnit.toSeconds(reconnectDelay));
    }

    final ClientInfoClientHandler handler = this;
    final EventLoop loop = ctx.channel().eventLoop();
    loop.schedule(new Runnable() {
        @Override
        public void run() {
            log.info("Reconnecting");
            PeriodicConfigRetrievalClient.configureBootstrap(configServerChooser, handler, new Bootstrap(), loop,
                    idleReadTimeUnit,idleReadTimeout,connectionTimeoutInMillis);
        }
    }, reconnectDelay, reconnectTimeUnit);
}
 
开发者ID:tootedom,项目名称:spray-cache-spymemcached,代码行数:18,代码来源:ClientInfoClientHandler.java


示例9: operationComplete

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
@Override
public void operationComplete(ChannelFuture channelFuture) throws Exception {
    if (!channelFuture.isSuccess()) {
        channelFuture.channel().close();

        if (count.incrementAndGet() < MAX_RETRY) {
            final EventLoop loop = channelFuture.channel().eventLoop();

            loop.schedule(() -> {
                try {
                    controller.connectRetry(this.ip, this.port, this);
                } catch (Exception e) {
                    log.warn("Connection to the ovsdb server {}:{} failed(cause: {})", ip, port, e);
                }
            }, 1L, TimeUnit.SECONDS);
        } else {
            failhandler.accept(new Exception("max connection retry(" + MAX_RETRY + ") exceeded"));
        }
    } else {
        handleNewNodeConnection(channelFuture.channel());
    }
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:23,代码来源:Controller.java


示例10: operationComplete

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
@Override
public void operationComplete(ChannelFuture future) throws Exception {
    if (future.isSuccess()) {
        log.info(String.format(MSG_STATE,
                ofSwitch.dpid(),
                MSG_CONNECTED,
                controller.ip(),
                controller.port()));
        // FIXME add close future listener to handle connection lost
    } else {
        if (retryCount.getAndIncrement() > MAX_RETRY) {
            log.warn(String.format(MSG_STATE,
                    ofSwitch.dpid(),
                    MSG_FAILED,
                    controller.ip(),
                    controller.port()));
        } else {
            final EventLoop loop = future.channel().eventLoop();
            loop.schedule(this::connect, 1L, TimeUnit.SECONDS);
        }
    }
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:23,代码来源:OFConnectionHandler.java


示例11: channelUnregistered

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
@Override
public void channelUnregistered(final ChannelHandlerContext ctx) throws Exception {
    println("Sleeping for: " + UptimeClient.RECONNECT_DELAY + 's');

    final EventLoop loop = ctx.channel().eventLoop();
    loop.schedule(new Runnable() {
        @Override
        public void run() {
            println("Reconnecting to: " + UptimeClient.HOST + ':' + UptimeClient.PORT);
            UptimeClient.connect(UptimeClient.configureBootstrap(new Bootstrap(), loop));
        }
    }, UptimeClient.RECONNECT_DELAY, TimeUnit.SECONDS);
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:14,代码来源:UptimeClientHandler.java


示例12: scheduleReconnect

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
private void scheduleReconnect(final ChannelFuture channelFuture) {
    final EventLoop loop = channelFuture.channel().eventLoop();
    loop.schedule(new Runnable() {
        @Override
        public void run() {
            try {
                LOG.trace("Re-connecting to {} if needed", configuration.getAddress());
                doReconnectIfNeeded();
            } catch (Exception e) {
                LOG.warn("Error during re-connect to " + configuration.getAddress() + ". Will attempt again in "
                        + configuration.getReconnectInterval() + " millis. This exception is ignored.", e);
            }
        }
    }, configuration.getReconnectInterval(), TimeUnit.MILLISECONDS);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:16,代码来源:ClientModeTCPNettyServerBootstrapFactory.java


示例13: operationComplete

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
@Override
public void operationComplete(ChannelFuture future) throws Exception {
  if (!future.isSuccess()) {
    EventLoop eventLoop = future.channel().eventLoop();
    eventLoop.schedule(client::start, 1L, TimeUnit.SECONDS); 
  }
}
 
开发者ID:tonivade,项目名称:resp-server,代码行数:8,代码来源:ConnectionListener.java


示例14: channelUnregistered

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
@Override
public void channelUnregistered(final ChannelHandlerContext ctx)
        throws Exception {
    println("Sleeping for: " + UptimeClient.RECONNECT_DELAY + 's');

    final EventLoop loop = ctx.channel().eventLoop();
    loop.schedule(new Runnable() {
        @Override
        public void run() {
            println("Reconnecting to: " + ctx.channel().remoteAddress());
            client.configureBootstrap(new Bootstrap(), loop).connect();
        }
    }, UptimeClient.RECONNECT_DELAY, TimeUnit.SECONDS);
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:15,代码来源:UptimeClientHandler.java


示例15: operationComplete

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
@Override
public void operationComplete(final ChannelFuture future) throws Exception {
    if (future.isCancelled()) {
        LOG.debug("Connection {} cancelled!", future);
    } else if (future.isSuccess()) {
        LOG.debug("Connection {} succeeded!", future);
        future.channel().closeFuture().addListener((ChannelFutureListener) channelFuture -> scheduleConnect());
    } else {
        final EventLoop loop = future.channel().eventLoop();
        loop.schedule(() -> this.bootstrap.connect().addListener(this), this.delay, TimeUnit.MILLISECONDS);
        LOG.info("The connection try to BMP router {} failed. Next reconnection attempt in {} milliseconds.",
                this.remoteAddress, this.delay);
    }
}
 
开发者ID:opendaylight,项目名称:bgpcep,代码行数:15,代码来源:BmpMockDispatcher.java


示例16: operationComplete

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
@Override
public void operationComplete(final ChannelFuture cf) throws Exception {
    synchronized (this.lock) {
        if (PCCReconnectPromise.this.isCancelled()) {
            if (cf.isSuccess()) {
                PCCReconnectPromise.LOG.debug("Closing channels for cancelled promise {}");
                cf.channel().close();
            }
        } else if (cf.isSuccess()) {
            PCCReconnectPromise.LOG.debug("Promise connection is successful.");
        } else {
            PCCReconnectPromise.LOG.debug("Attempt to connect to {} failed",
                    PCCReconnectPromise.this.address, cf.cause());

            if (PCCReconnectPromise.this.retryTimer == 0) {
                PCCReconnectPromise.LOG.debug("Retry timer value is 0. Reconnection will not be attempted");
                PCCReconnectPromise.this.setFailure(cf.cause());
                return;
            }

            final EventLoop loop = cf.channel().eventLoop();
            loop.schedule(() -> {
                synchronized (PCCReconnectPromise.this) {
                    PCCReconnectPromise.LOG.debug("Attempting to connect to {}",
                            PCCReconnectPromise.this.address);
                    final Future<Void> reconnectFuture = PCCReconnectPromise.this.bootstrap.connect();
                    reconnectFuture.addListener(this);
                    PCCReconnectPromise.this.pending = reconnectFuture;
                }
            }, PCCReconnectPromise.this.retryTimer, TimeUnit.SECONDS);
            PCCReconnectPromise.LOG.debug("Next reconnection attempt in {}s",
                    PCCReconnectPromise.this.retryTimer);
        }
    }
}
 
开发者ID:opendaylight,项目名称:bgpcep,代码行数:36,代码来源:PCCReconnectPromise.java


示例17: channelInactive

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
@Override
public void channelInactive(final ChannelHandlerContext ctx) throws Exception {
    println("Disconnected from: " + ctx.channel().remoteAddress());

    println("Sleeping for: " + UptimeClient.RECONNECT_DELAY + 's');

    final EventLoop loop = ctx.channel().eventLoop();
    loop.schedule(new Runnable() {
        @Override
        public void run() {
            println("Reconnecting to: " + ctx.channel().remoteAddress());
            client.configureBootstrap(new Bootstrap(), loop).connect();
        }
    }, UptimeClient.RECONNECT_DELAY, TimeUnit.SECONDS);
}
 
开发者ID:nathanchen,项目名称:netty-netty-5.0.0.Alpha1,代码行数:16,代码来源:UptimeClientHandler.java


示例18: scheduleReconnect

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
private void scheduleReconnect(final ChannelHandlerContext ctx) {
  final EventLoop loop = ctx.channel().eventLoop();
  loop.schedule(new Runnable() {
    @Override
    public void run() {
      log.info("Reconnecting to {}", graphiteTarget);
      client.connect();
    }
  }, RECONNECT_DELAY_SEC, TimeUnit.SECONDS);
}
 
开发者ID:outbrain,项目名称:gruffalo,代码行数:11,代码来源:GraphiteChannelInboundHandler.java


示例19: operationComplete

import io.netty.channel.EventLoop; //导入方法依赖的package包/类
@Override
public void operationComplete(final ChannelFuture cf) throws Exception {
    synchronized (PCEPProtocolSessionPromise.this) {
        PCEPProtocolSessionPromise.LOG.debug("Promise {} connection resolved",
                PCEPProtocolSessionPromise.this);
        Preconditions.checkState(PCEPProtocolSessionPromise.this.pending.equals(cf));
        if (PCEPProtocolSessionPromise.this.isCancelled()) {
            if (cf.isSuccess()) {
                PCEPProtocolSessionPromise.LOG.debug("Closing channel for cancelled promise {}",
                        PCEPProtocolSessionPromise.this);
                cf.channel().close();
            }
        } else if (cf.isSuccess()) {
            PCEPProtocolSessionPromise.LOG.debug("Promise {} connection successful",
                    PCEPProtocolSessionPromise.this);
        } else {
            PCEPProtocolSessionPromise.LOG.debug("Attempt to connect to {} failed", 
                    PCEPProtocolSessionPromise.this.address, cf.cause());

            if (PCEPProtocolSessionPromise.this.retryTimer == 0) {
                PCEPProtocolSessionPromise.LOG
                        .debug("Retry timer value is 0. Reconnection will not be attempted");
                PCEPProtocolSessionPromise.this.setFailure(cf.cause());
                return;
            }

            final EventLoop loop = cf.channel().eventLoop();
            loop.schedule(() -> {
                synchronized (PCEPProtocolSessionPromise.this) {
                    PCEPProtocolSessionPromise.LOG.debug("Attempting to connect to {}",
                            PCEPProtocolSessionPromise.this.address);
                    final Future<Void> reconnectFuture = PCEPProtocolSessionPromise.this.b.connect();
                    reconnectFuture.addListener(BootstrapConnectListener.this);
                    PCEPProtocolSessionPromise.this.pending = reconnectFuture;
                }
            }, PCEPProtocolSessionPromise.this.retryTimer, TimeUnit.SECONDS);
            PCEPProtocolSessionPromise.LOG.debug("Next reconnection attempt in {}s",
                    PCEPProtocolSessionPromise.this.retryTimer);
        }
    }
}
 
开发者ID:opendaylight,项目名称:bgpcep,代码行数:42,代码来源:PCEPProtocolSessionPromise.java



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