use of io.netty.util.HashedWheelTimer in project open-kilda by telstra.
the class BfdFeatureTest method createSwitchWithDescription.
private static IOFSwitch createSwitchWithDescription(SwitchDescription description) {
OFFactory factory = new OFFactoryVer13();
DatapathId dpid = DatapathId.of("1");
OFConnection connection = new OFConnection(dpid, factory, new LocalChannel(), OFAuxId.MAIN, new MockDebugCounterService(), new HashedWheelTimer());
OFSwitch sw = new OFSwitch(connection, factory, new OFSwitchManager(), dpid);
sw.setSwitchProperties(description);
return sw;
}
use of io.netty.util.HashedWheelTimer in project Singularity by HubSpot.
the class CompletableFutures method executeWithTimeout.
public static <T> CompletableFuture<T> executeWithTimeout(Callable<T> callable, ExecutorService executorService, HashedWheelTimer timer, long timeout, TimeUnit timeUnit) {
CompletableFuture<T> future = new CompletableFuture<>();
AtomicReference<Timeout> timeoutRef = new AtomicReference<>();
Future<Void> underlying = executorService.submit(() -> {
if (future.complete(callable.call())) {
Timeout timeout1 = timeoutRef.get();
if (timeout1 != null) {
timeout1.cancel();
}
}
return null;
});
timeoutRef.set(timer.newTimeout(ignored -> {
if (!future.isDone()) {
if (future.completeExceptionally(new TimeoutException())) {
underlying.cancel(true);
}
}
}, timeout, timeUnit));
return future;
}
Aggregations