List of usage examples for io.netty.util HashedWheelTimer HashedWheelTimer
public HashedWheelTimer(ThreadFactory threadFactory)
From source file:com.datastax.driver.core.NettyOptions.java
License:Apache License
/** * Return the {@link Timer} instance used by Read Timeouts and Speculative Execution. * <p/>//from ww w. j a v a 2s. c o m * This hook is invoked only once at {@link Cluster} initialization; * the returned instance will be kept in use throughout the cluster lifecycle. * <p/> * Typically, implementors would return a newly-created instance; * it is however possible to re-use a shared instance, but in this * case implementors should also override {@link #onClusterClose(Timer)} * to prevent the shared instance to be closed when the cluster is closed. * <p/> * The default implementation returns a new instance created by {@link HashedWheelTimer#HashedWheelTimer(ThreadFactory)}. * * @param threadFactory The {@link ThreadFactory} to use when creating a new {@link HashedWheelTimer} instance; * The driver will provide its own internal thread factory here. * It is safe to ignore it and use another thread factory. Note however that for optimal * performance it is recommended to use a factory that returns * {@link io.netty.util.concurrent.FastThreadLocalThread} instances (such as Netty's * {@link java.util.concurrent.Executors.DefaultThreadFactory}). * @return the {@link Timer} instance to use. */ public Timer timer(ThreadFactory threadFactory) { return new HashedWheelTimer(threadFactory); }
From source file:com.digitalpetri.opcua.stack.core.Stack.java
License:Apache License
/** * @return a shared {@link HashedWheelTimer}. *///from w w w. j av a 2 s . c om public static synchronized HashedWheelTimer sharedWheelTimer() { if (WHEEL_TIMER == null) { ThreadFactory threadFactory = r -> { Thread thread = new Thread(r, "ua-netty-wheel-timer"); thread.setDaemon(true); return thread; }; WHEEL_TIMER = new HashedWheelTimer(threadFactory); } return WHEEL_TIMER; }
From source file:com.ibasco.agql.core.session.DefaultSessionManager.java
License:Open Source License
@SuppressWarnings("unchecked") public DefaultSessionManager(AbstractSessionIdFactory factory) { sessionTimer = new HashedWheelTimer( new ThreadFactoryBuilder().setNameFormat("timeout-%d").setDaemon(true).build()); directory = new HashMap<>(); this.factory = (factory != null) ? factory : new DefaultSessionIdFactory(); this.factory.setLookup(directory); }
From source file:com.lambdaworks.redis.resource.DefaultClientResources.java
License:Apache License
protected DefaultClientResources(Builder builder) { if (builder.eventLoopGroupProvider == null) { int ioThreadPoolSize = builder.ioThreadPoolSize; if (ioThreadPoolSize < MIN_IO_THREADS) { logger.info("ioThreadPoolSize is less than {} ({}), setting to: {}", MIN_IO_THREADS, ioThreadPoolSize, MIN_IO_THREADS); ioThreadPoolSize = MIN_IO_THREADS; }/*from w w w . j av a 2s. co m*/ this.sharedEventLoopGroupProvider = false; this.eventLoopGroupProvider = new DefaultEventLoopGroupProvider(ioThreadPoolSize); } else { this.sharedEventLoopGroupProvider = true; this.eventLoopGroupProvider = builder.eventLoopGroupProvider; } if (builder.eventExecutorGroup == null) { int computationThreadPoolSize = builder.computationThreadPoolSize; if (computationThreadPoolSize < MIN_COMPUTATION_THREADS) { logger.info("computationThreadPoolSize is less than {} ({}), setting to: {}", MIN_COMPUTATION_THREADS, computationThreadPoolSize, MIN_COMPUTATION_THREADS); computationThreadPoolSize = MIN_COMPUTATION_THREADS; } eventExecutorGroup = DefaultEventLoopGroupProvider.createEventLoopGroup(DefaultEventExecutorGroup.class, computationThreadPoolSize); sharedEventExecutor = false; } else { sharedEventExecutor = true; eventExecutorGroup = builder.eventExecutorGroup; } if (builder.timer == null) { timer = new HashedWheelTimer(new DefaultThreadFactory("lettuce-timer")); sharedTimer = false; } else { timer = builder.timer; sharedTimer = true; } if (builder.eventBus == null) { eventBus = new DefaultEventBus(new RxJavaEventExecutorGroupScheduler(eventExecutorGroup)); } else { eventBus = builder.eventBus; } if (builder.commandLatencyCollector == null) { if (DefaultCommandLatencyCollector.isAvailable()) { if (builder.commandLatencyCollectorOptions != null) { commandLatencyCollector = new DefaultCommandLatencyCollector( builder.commandLatencyCollectorOptions); } else { commandLatencyCollector = new DefaultCommandLatencyCollector( DefaultCommandLatencyCollectorOptions.create()); } } else { logger.debug("LatencyUtils/HdrUtils are not available, metrics are disabled"); builder.commandLatencyCollectorOptions = DefaultCommandLatencyCollectorOptions.disabled(); commandLatencyCollector = DefaultCommandLatencyCollector.disabled(); } sharedCommandLatencyCollector = false; } else { sharedCommandLatencyCollector = true; commandLatencyCollector = builder.commandLatencyCollector; } commandLatencyPublisherOptions = builder.commandLatencyPublisherOptions; if (commandLatencyCollector.isEnabled() && commandLatencyPublisherOptions != null) { metricEventPublisher = new DefaultCommandLatencyEventPublisher(eventExecutorGroup, commandLatencyPublisherOptions, eventBus, commandLatencyCollector); } else { metricEventPublisher = null; } if (builder.dnsResolver == null) { dnsResolver = DnsResolvers.JVM_DEFAULT; } else { dnsResolver = builder.dnsResolver; } reconnectDelay = builder.reconnectDelay; }
From source file:io.druid.server.emitter.HttpEmitterModule.java
License:Apache License
static AsyncHttpClient createAsyncHttpClient(String nameFormat, String timerThreadNameFormat, @Nullable SSLContext sslContext) { final DefaultAsyncHttpClientConfig.Builder builder = new DefaultAsyncHttpClientConfig.Builder() .setThreadFactory(Execs.makeThreadFactory(nameFormat)) .setNettyTimer(new HashedWheelTimer(Execs.makeThreadFactory(timerThreadNameFormat))); if (sslContext != null) { builder.setSslContext(new JdkSslContext(sslContext, true, ClientAuth.NONE)); }/* ww w .ja v a2 s. c o m*/ return new DefaultAsyncHttpClient(builder.build()); }
From source file:io.lettuce.core.resource.DefaultClientResources.java
License:Apache License
protected DefaultClientResources(Builder builder) { this.builder = builder; if (builder.eventLoopGroupProvider == null) { int ioThreadPoolSize = builder.ioThreadPoolSize; if (ioThreadPoolSize < MIN_IO_THREADS) { logger.info("ioThreadPoolSize is less than {} ({}), setting to: {}", MIN_IO_THREADS, ioThreadPoolSize, MIN_IO_THREADS); ioThreadPoolSize = MIN_IO_THREADS; }// ww w . j a v a2s.c om this.sharedEventLoopGroupProvider = false; this.eventLoopGroupProvider = new DefaultEventLoopGroupProvider(ioThreadPoolSize); } else { this.sharedEventLoopGroupProvider = true; this.eventLoopGroupProvider = builder.eventLoopGroupProvider; } if (builder.eventExecutorGroup == null) { int computationThreadPoolSize = builder.computationThreadPoolSize; if (computationThreadPoolSize < MIN_COMPUTATION_THREADS) { logger.info("computationThreadPoolSize is less than {} ({}), setting to: {}", MIN_COMPUTATION_THREADS, computationThreadPoolSize, MIN_COMPUTATION_THREADS); computationThreadPoolSize = MIN_COMPUTATION_THREADS; } eventExecutorGroup = DefaultEventLoopGroupProvider.createEventLoopGroup(DefaultEventExecutorGroup.class, computationThreadPoolSize); sharedEventExecutor = false; } else { sharedEventExecutor = true; eventExecutorGroup = builder.eventExecutorGroup; } if (builder.timer == null) { timer = new HashedWheelTimer(new DefaultThreadFactory("lettuce-timer")); sharedTimer = false; } else { timer = builder.timer; sharedTimer = true; } if (builder.eventBus == null) { eventBus = new DefaultEventBus(Schedulers.fromExecutor(eventExecutorGroup)); } else { eventBus = builder.eventBus; } if (builder.commandLatencyCollector == null) { if (DefaultCommandLatencyCollector.isAvailable()) { if (builder.commandLatencyCollectorOptions != null) { commandLatencyCollector = CommandLatencyCollector .create(builder.commandLatencyCollectorOptions); } else { commandLatencyCollector = CommandLatencyCollector .create(CommandLatencyCollectorOptions.create()); } } else { logger.debug("LatencyUtils/HdrUtils are not available, metrics are disabled"); builder.commandLatencyCollectorOptions = CommandLatencyCollectorOptions.disabled(); commandLatencyCollector = CommandLatencyCollector.disabled(); } sharedCommandLatencyCollector = false; } else { sharedCommandLatencyCollector = true; commandLatencyCollector = builder.commandLatencyCollector; } commandLatencyPublisherOptions = builder.commandLatencyPublisherOptions; if (commandLatencyCollector.isEnabled() && commandLatencyPublisherOptions != null) { metricEventPublisher = new DefaultCommandLatencyEventPublisher(eventExecutorGroup, commandLatencyPublisherOptions, eventBus, commandLatencyCollector); } else { metricEventPublisher = null; } if (builder.dnsResolver == null) { dnsResolver = DnsResolvers.UNRESOLVED; } else { dnsResolver = builder.dnsResolver; } if (builder.socketAddressResolver == null) { socketAddressResolver = SocketAddressResolver.create(dnsResolver); } else { socketAddressResolver = builder.socketAddressResolver; } reconnectDelay = builder.reconnectDelay; nettyCustomizer = builder.nettyCustomizer; tracing = builder.tracing; }
From source file:net.hasor.rsf.utils.TimerManager.java
License:Apache License
public TimerManager(int defaultTimeout, String name, ClassLoader loader) { this.defaultTimeout = defaultTimeout; name = Hasor.assertIsNotNull(name);/*from ww w . j av a 2 s .c o m*/ this.timer = new HashedWheelTimer(new NameThreadFactory(name + "-Timer-%s", loader)); }
From source file:qunar.tc.qmq.service.HeartbeatManager.java
License:Apache License
public HeartbeatManager() { this.timeouts = new ConcurrentHashMap<>(); this.timer = new HashedWheelTimer(new NamedThreadFactory("qmq-heartbeat")); this.timer.start(); }