本文整理汇总了Java中io.netty.util.concurrent.ScheduledFuture.cancel方法的典型用法代码示例。如果您正苦于以下问题:Java ScheduledFuture.cancel方法的具体用法?Java ScheduledFuture.cancel怎么用?Java ScheduledFuture.cancel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.util.concurrent.ScheduledFuture
的用法示例。
在下文中一共展示了ScheduledFuture.cancel方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: close
import io.netty.util.concurrent.ScheduledFuture; //导入方法依赖的package包/类
@Override
public void close() {
isRunning.set(false);
for (ScheduledFuture<?> f : scheduledFutures) {
f.cancel(true);
}
// wait for scheduled futures to cancel
while (scheduledFutures.stream().anyMatch((f) -> !f.isDone())) {
Uninterruptibles.sleepUninterruptibly(250, TimeUnit.MILLISECONDS);
}
// handle remaining items in the queue
while (counter.get() > 0) {
drainMessageQ();
}
connectionPool.close();
}
示例2: shutdown
import io.netty.util.concurrent.ScheduledFuture; //导入方法依赖的package包/类
/**
* Shutdown this client and close all open connections. The client should be discarded after calling shutdown.
*
* @param quietPeriod the quiet period as described in the documentation
* @param timeout the maximum amount of time to wait until the executor is shutdown regardless if a task was submitted
* during the quiet period
* @param timeUnit the unit of {@code quietPeriod} and {@code timeout}
*/
@Override
public void shutdown(long quietPeriod, long timeout, TimeUnit timeUnit) {
if (clusterTopologyRefreshActivated.compareAndSet(true, false)) {
ScheduledFuture<?> scheduledFuture = clusterTopologyRefreshFuture.get();
try {
scheduledFuture.cancel(false);
clusterTopologyRefreshFuture.set(null);
} catch (Exception e) {
logger.debug("Could not unschedule Cluster topology refresh", e);
}
}
super.shutdown(quietPeriod, timeout, timeUnit);
}
示例3: cancelRequestTimeout
import io.netty.util.concurrent.ScheduledFuture; //导入方法依赖的package包/类
private void cancelRequestTimeout()
{
ScheduledFuture<?> timeout = this.timeout.get();
if (timeout != null) {
timeout.cancel(false);
}
}
示例4: channelRegistered
import io.netty.util.concurrent.ScheduledFuture; //导入方法依赖的package包/类
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
super.channelRegistered(ctx);
Channel c = ctx.channel();
channel.set(c);
registeredFutureLatch.release(null); //release all futures waiting for channel registration to complete.
log.info("Connection established {} ", ctx);
c.write(new WireCommands.Hello(WireCommands.WIRE_VERSION, WireCommands.OLDEST_COMPATIBLE_VERSION), c.voidPromise());
ScheduledFuture<?> old = keepAliveFuture.getAndSet(c.eventLoop().scheduleWithFixedDelay(new KeepAliveTask(), 20, 10, TimeUnit.SECONDS));
if (old != null) {
old.cancel(false);
}
}
示例5: channelUnregistered
import io.netty.util.concurrent.ScheduledFuture; //导入方法依赖的package包/类
/**
* Disconnected.
* @see io.netty.channel.ChannelInboundHandler#channelUnregistered(io.netty.channel.ChannelHandlerContext)
*/
@Override
public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
registeredFutureLatch.reset();
ScheduledFuture<?> future = keepAliveFuture.get();
if (future != null) {
future.cancel(false);
}
channel.set(null);
processor.connectionDropped();
super.channelUnregistered(ctx);
}
示例6: run
import io.netty.util.concurrent.ScheduledFuture; //导入方法依赖的package包/类
@Override
public void run() {
isRun = true;
ScheduledFuture<?> timeoutFuture = get();
if (timeoutFuture != null) {
if (timeoutFuture.isDone() || !timeoutFuture.cancel(false)) {
// Timeout task ran already or is determined to run.
numActiveRequests.decrementAndGet();
return;
}
}
try (SafeCloseable ignored = RequestContext.push(ctx)) {
try {
final O actualRes = delegate().execute(ctx, req);
actualRes.completionFuture().whenCompleteAsync((unused, cause) -> {
numActiveRequests.decrementAndGet();
drain();
}, ctx.eventLoop());
deferred.delegate(actualRes);
} catch (Throwable t) {
numActiveRequests.decrementAndGet();
deferred.close(t);
}
}
}
示例7: cancelTimeout
import io.netty.util.concurrent.ScheduledFuture; //导入方法依赖的package包/类
boolean cancelTimeout() {
final ScheduledFuture<?> responseTimeoutFuture = this.responseTimeoutFuture;
if (responseTimeoutFuture == null) {
return true;
}
this.responseTimeoutFuture = null;
return responseTimeoutFuture.cancel(false);
}
示例8: sendTxManagerMessage
import io.netty.util.concurrent.ScheduledFuture; //导入方法依赖的package包/类
/**
* 向TxManager 发生消息
*
* @param heartBeat 定义的数据传输对象
* @return Object
*/
public Object sendTxManagerMessage(HeartBeat heartBeat) {
if (ctx != null && ctx.channel() != null && ctx.channel().isActive()) {
final String sendKey = IdWorkerUtils.getInstance().createTaskKey();
BlockTask sendTask = BlockTaskHelper.getInstance().getTask(sendKey);
heartBeat.setKey(sendKey);
ctx.writeAndFlush(heartBeat);
final ScheduledFuture<?> schedule = ctx.executor()
.schedule(() -> {
if (!sendTask.isNotify()) {
if (NettyMessageActionEnum.GET_TRANSACTION_GROUP_STATUS.getCode()
== heartBeat.getAction()) {
sendTask.setAsyncCall(objects -> NettyResultEnum.TIME_OUT.getCode());
} else if (NettyMessageActionEnum.FIND_TRANSACTION_GROUP_INFO.getCode()
== heartBeat.getAction()) {
sendTask.setAsyncCall(objects -> null);
} else {
sendTask.setAsyncCall(objects -> false);
}
sendTask.signal();
}
}, txConfig.getDelayTime(), TimeUnit.SECONDS);
//发送线程在此等待,等tm是否 正确返回(正确返回唤醒) 返回错误或者无返回通过上面的调度线程唤醒
sendTask.await();
//如果已经被唤醒,就不需要去执行调度线程了 ,关闭上面的调度线程池中的任务
if (!schedule.isDone()) {
schedule.cancel(false);
}
try {
return sendTask.getAsyncCall().callBack();
} catch (Throwable throwable) {
throwable.printStackTrace();
return null;
} finally {
BlockTaskHelper.getInstance().removeByKey(sendKey);
}
} else {
return null;
}
}