當前位置: 首頁>>代碼示例>>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方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的io.netty.channel.EventLoop.schedule方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。