Search in sources :

Example 31 with HashedWheelTimer

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;
}
Also used : OFSwitchManager(net.floodlightcontroller.core.internal.OFSwitchManager) OFConnection(net.floodlightcontroller.core.internal.OFConnection) MockDebugCounterService(net.floodlightcontroller.debugcounter.MockDebugCounterService) OFFactoryVer13(org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13) LocalChannel(io.netty.channel.local.LocalChannel) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) DatapathId(org.projectfloodlight.openflow.types.DatapathId) HashedWheelTimer(io.netty.util.HashedWheelTimer) OFSwitch(net.floodlightcontroller.core.internal.OFSwitch) IOFSwitch(net.floodlightcontroller.core.IOFSwitch)

Example 32 with HashedWheelTimer

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;
}
Also used : ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) Timeout(io.netty.util.Timeout) Collection(java.util.Collection) BiFunction(java.util.function.BiFunction) TimeoutException(java.util.concurrent.TimeoutException) Callable(java.util.concurrent.Callable) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Future(java.util.concurrent.Future) CompletionStage(java.util.concurrent.CompletionStage) HashedWheelTimer(io.netty.util.HashedWheelTimer) Collector(java.util.stream.Collector) ExecutorService(java.util.concurrent.ExecutorService) CompletableFuture(java.util.concurrent.CompletableFuture) Timeout(io.netty.util.Timeout) AtomicReference(java.util.concurrent.atomic.AtomicReference) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

HashedWheelTimer (io.netty.util.HashedWheelTimer)32 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)17 NettyClientMetrics (com.linkedin.pinot.transport.metrics.NettyClientMetrics)16 EventLoopGroup (io.netty.channel.EventLoopGroup)15 Test (org.testng.annotations.Test)13 ByteBuf (io.netty.buffer.ByteBuf)12 ServerInstance (com.linkedin.pinot.common.response.ServerInstance)10 ResponseFuture (com.linkedin.pinot.transport.netty.NettyClientConnection.ResponseFuture)8 MetricsRegistry (com.yammer.metrics.core.MetricsRegistry)8 ExecutorService (java.util.concurrent.ExecutorService)8 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)8 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)7 AsyncResponseFuture (com.linkedin.pinot.transport.common.AsyncResponseFuture)7 NettyClientConnection (com.linkedin.pinot.transport.netty.NettyClientConnection)6 PooledNettyClientResourceManager (com.linkedin.pinot.transport.netty.PooledNettyClientResourceManager)6 Timer (io.netty.util.Timer)6 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)6 BrokerMetrics (com.linkedin.pinot.common.metrics.BrokerMetrics)5 KeyedPoolImpl (com.linkedin.pinot.transport.pool.KeyedPoolImpl)5 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)5