本文整理了Java中io.netty.util.Timeout
类的一些代码示例,展示了Timeout
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Timeout
类的具体详情如下:
包路径:io.netty.util.Timeout
类名称:Timeout
[英]A handle associated with a TimerTask that is returned by a Timer.
[中]与计时器返回的计时器任务相关联的句柄。
代码示例来源:origin: redisson/redisson
@Override
public void operationComplete(Future<R> future) throws Exception {
if (scheduledFuture != null) {
scheduledFuture.cancel();
}
synchronized (listener) {
connectionManager.getShutdownPromise().removeListener(listener);
}
// handling cancel operation for blocking commands
if (future.isCancelled() && !details.getAttemptPromise().isDone()) {
log.debug("Canceled blocking operation {} used {}", details.getCommand(), connection);
connection.forceFastReconnectAsync().addListener(new FutureListener<Void>() {
@Override
public void operationComplete(Future<Void> future) throws Exception {
details.getAttemptPromise().cancel(true);
}
});
return;
}
if (future.cause() instanceof RedissonShutdownException) {
details.getAttemptPromise().tryFailure(future.cause());
}
}
});
代码示例来源:origin: apache/pulsar
private void stop() {
writeLock.lock();
try {
if (timeout != null && !timeout.isCancelled()) {
timeout.cancel();
}
this.clear();
} finally {
writeLock.unlock();
}
}
代码示例来源:origin: mrniko/netty-socketio
private void replaceScheduledFuture(final SchedulerKey key, final Timeout newTimeout) {
final Timeout oldTimeout;
if (newTimeout.isExpired()) {
// no need to put already expired timeout to scheduledFutures map.
// simply remove old timeout
oldTimeout = scheduledFutures.remove(key);
} else {
oldTimeout = scheduledFutures.put(key, newTimeout);
}
// if there was old timeout, cancel it
if (oldTimeout != null) {
oldTimeout.cancel();
}
}
}
代码示例来源:origin: AsyncHttpClient/async-http-client
public void cancel() {
if (cancelled.compareAndSet(false, true)) {
if (requestTimeout != null) {
requestTimeout.cancel();
RequestTimeoutTimerTask.class.cast(requestTimeout.task()).clean();
}
if (readTimeout != null) {
readTimeout.cancel();
ReadTimeoutTimerTask.class.cast(readTimeout.task()).clean();
}
}
}
代码示例来源:origin: qunarcorp/qmq
public void refreshHeartbeat(T key, TimerTask task, long timeout, TimeUnit unit) {
Timeout context = timer.newTimeout(task, timeout, unit);
final Timeout old = timeouts.put(key, context);
if (old != null && !old.isCancelled() && !old.isExpired()) {
old.cancel();
}
}
代码示例来源:origin: redisson/redisson
protected <R, V> void checkAttemptFuture(final NodeSource source, final AsyncDetails<V, R> details,
Future<R> future, final boolean ignoreRedirect) {
details.getTimeout().cancel();
if (future.isCancelled()) {
return;
details.removeMainPromiseListener();
if (future.cause() instanceof RedisMovedException && !ignoreRedirect) {
RedisMovedException ex = (RedisMovedException) future.cause();
if (source.getRedirect() == Redirect.MOVED) {
details.getMainPromise().tryFailure(new RedisException("MOVED redirection loop detected. Node " + source.getAddr() + " has further redirect to " + ex.getUrl()));
代码示例来源:origin: digitalpetri/modbus
if (t.isCancelled()) return;
if (!f.isSuccess()) {
PendingRequest<?> p = pendingRequests.remove(txId);
if (p != null) {
p.promise.completeExceptionally(f.cause());
p.timeout.cancel();
代码示例来源:origin: apache/pulsar
public void cancelStatsTimeout() {
if (statTimeout != null) {
statTimeout.cancel();
statTimeout = null;
}
}
代码示例来源:origin: redisson/redisson
@Override
public void operationComplete(Future<Void> future) throws Exception {
if (future.isCancelled() && connectionFuture.cancel(false)) {
log.debug("Connection obtaining canceled for batch");
details.getTimeout().cancel();
if (attemptPromise.cancel(false)) {
free(entry);
}
}
}
};
代码示例来源:origin: traccar/traccar
@Override
public void run(Timeout timeout) {
if (!timeout.isCancelled()) {
updateDevice(deviceId, Device.STATUS_UNKNOWN, null);
}
}
}, deviceTimeout, TimeUnit.MILLISECONDS));
代码示例来源:origin: mrniko/netty-socketio
@Override
public void schedule(final SchedulerKey key, final Runnable runnable, long delay, TimeUnit unit) {
Timeout timeout = executorService.newTimeout(new TimerTask() {
@Override
public void run(Timeout timeout) throws Exception {
try {
runnable.run();
} finally {
scheduledFutures.remove(key);
}
}
}, delay, unit);
if (!timeout.isExpired()) {
scheduledFutures.put(key, timeout);
}
}
代码示例来源:origin: AsyncHttpClient/async-http-client
scheduleNewIdleChannelDetector(timeout.task());
代码示例来源:origin: redisson/redisson
protected <R, V> void checkAttemptFuture(final NodeSource source, final AsyncDetails<V, R> details,
Future<R> future, final boolean ignoreRedirect) {
details.getTimeout().cancel();
if (future.isCancelled()) {
return;
details.removeMainPromiseListener();
if (future.cause() instanceof RedisMovedException && !ignoreRedirect) {
RedisMovedException ex = (RedisMovedException) future.cause();
if (source.getRedirect() == Redirect.MOVED) {
details.getMainPromise().tryFailure(new RedisException("MOVED redirection loop detected. Node " + source.getAddr() + " has further redirect to " + ex.getUrl()));
代码示例来源:origin: apache/incubator-pinot
protected void cancelLastRequestTimeout() {
if (null != _lastRequestTimeout) {
_lastRequestTimeout.cancel(); //If task is already executed, no side-effect
_lastRequestTimeout = null;
}
}
代码示例来源:origin: redisson/redisson
@Override
public void operationComplete(Future<Void> future) throws Exception {
if (future.isCancelled() && connectionFuture.cancel(false)) {
log.debug("Connection obtaining canceled for batch");
details.getTimeout().cancel();
if (attemptPromise.cancel(false)) {
free(entry);
}
}
}
};
代码示例来源:origin: org.asynchttpclient/async-http-client-netty4-provider
public void cancel() {
if (cancelled.compareAndSet(false, true)) {
if (requestTimeout != null) {
requestTimeout.cancel();
RequestTimeoutTimerTask.class.cast(requestTimeout.task()).clean();
requestTimeout = null;
}
if (readTimeout != null) {
readTimeout.cancel();
ReadTimeoutTimerTask.class.cast(readTimeout.task()).clean();
readTimeout = null;
}
}
}
}
代码示例来源:origin: apache/pulsar
@Override
public void run(Timeout timeout) throws Exception {
if (timeout.isCancelled()) {
return;
}
CompletableFuture<Void> recheckFuture = new CompletableFuture<>();
List<CompletableFuture<Void>> futures = Lists.newArrayListWithExpectedSize(2);
client.getLookup().getTopicsUnderNamespace(namespaceName, subscriptionMode).thenAccept(topics -> {
if (log.isDebugEnabled()) {
log.debug("Get topics under namespace {}, topics.size: {}", namespaceName.toString(), topics.size());
topics.forEach(topicName ->
log.debug("Get topics under namespace {}, topic: {}", namespaceName.toString(), topicName));
}
List<String> newTopics = PulsarClientImpl.topicsPatternFilter(topics, topicsPattern);
List<String> oldTopics = PatternMultiTopicsConsumerImpl.this.getTopics();
futures.add(topicsChangeListener.onTopicsAdded(topicsListsMinus(newTopics, oldTopics)));
futures.add(topicsChangeListener.onTopicsRemoved(topicsListsMinus(oldTopics, newTopics)));
FutureUtil.waitForAll(futures)
.thenAccept(finalFuture -> recheckFuture.complete(null))
.exceptionally(ex -> {
log.warn("[{}] Failed to recheck topics change: {}", topic, ex.getMessage());
recheckFuture.completeExceptionally(ex);
return null;
});
});
// schedule the next re-check task
client.timer().newTimeout(PatternMultiTopicsConsumerImpl.this,
Math.min(1, conf.getPatternAutoDiscoveryPeriod()), TimeUnit.MINUTES);
}
代码示例来源:origin: mrniko/netty-socketio
@Override
public void scheduleCallback(final SchedulerKey key, final Runnable runnable, long delay, TimeUnit unit) {
Timeout timeout = executorService.newTimeout(new TimerTask() {
@Override
public void run(Timeout timeout) throws Exception {
ctx.executor().execute(new Runnable() {
@Override
public void run() {
try {
runnable.run();
} finally {
scheduledFutures.remove(key);
}
}
});
}
}, delay, unit);
if (!timeout.isExpired()) {
scheduledFutures.put(key, timeout);
}
}
代码示例来源:origin: org.asynchttpclient/async-http-client-netty4
scheduleNewIdleChannelDetector(timeout.task());
代码示例来源:origin: org.redisson/redisson
protected <R, V> void checkAttemptFuture(final NodeSource source, final AsyncDetails<V, R> details,
Future<R> future, final boolean ignoreRedirect) {
details.getTimeout().cancel();
if (future.isCancelled()) {
return;
details.removeMainPromiseListener();
if (future.cause() instanceof RedisMovedException && !ignoreRedirect) {
RedisMovedException ex = (RedisMovedException) future.cause();
if (source.getRedirect() == Redirect.MOVED) {
details.getMainPromise().tryFailure(new RedisException("MOVED redirection loop detected. Node " + source.getAddr() + " has further redirect to " + ex.getUrl()));
内容来源于网络,如有侵权,请联系作者删除!