public static Timer getTimer() { if (instance == null) { instance = new HashedWheelTimer(); } return instance; }
public HashedWheelTimeoutScheduler() { executorService = new HashedWheelTimer(); }
public HashedWheelScheduler() { executorService = new HashedWheelTimer(); }
public HashedWheelScheduler(ThreadFactory threadFactory) { executorService = new HashedWheelTimer(threadFactory); }
public HashedWheelTimeoutScheduler(ThreadFactory threadFactory) { executorService = new HashedWheelTimer(threadFactory); }
@Override public void init() { if (heartbeatCheck) { long tickDuration = TimeUnit.SECONDS.toMillis(1);//1s 每秒钟走一步,一个心跳周期内大致走一圈 int ticksPerWheel = (int) (CC.mp.core.max_heartbeat / tickDuration); this.timer = new HashedWheelTimer( new NamedThreadFactory(ThreadNames.T_CONN_TIMER), tickDuration, TimeUnit.MILLISECONDS, ticksPerWheel ); } }
protected void initTimer(MasterSlaveServersConfig config) { int[] timeouts = new int[]{config.getRetryInterval(), config.getTimeout()}; Arrays.sort(timeouts); int minTimeout = timeouts[0]; if (minTimeout % 100 != 0) { minTimeout = (minTimeout % 100) / 2; } else if (minTimeout == 100) { minTimeout = 50; } else { minTimeout = 100; } timer = new HashedWheelTimer(Executors.defaultThreadFactory(), minTimeout, TimeUnit.MILLISECONDS, 1024, false); connectionWatcher = new IdleConnectionWatcher(this, config); subscribeService = new PublishSubscribeService(this, config); }
protected void initTimer(MasterSlaveServersConfig config) { int[] timeouts = new int[]{config.getRetryInterval(), config.getTimeout()}; Arrays.sort(timeouts); int minTimeout = timeouts[0]; if (minTimeout % 100 != 0) { minTimeout = (minTimeout % 100) / 2; } else if (minTimeout == 100) { minTimeout = 50; } else { minTimeout = 100; } timer = new HashedWheelTimer(Executors.defaultThreadFactory(), minTimeout, TimeUnit.MILLISECONDS, 1024, false); connectionWatcher = new IdleConnectionWatcher(this, config); subscribeService = new PublishSubscribeService(this, config); }
@Override protected void doStart(Listener listener) throws Throwable { workerGroup = new NioEventLoopGroup(http_work, new DefaultThreadFactory(ThreadNames.T_HTTP_CLIENT)); b = new Bootstrap(); b.group(workerGroup); b.channel(NioSocketChannel.class); b.option(ChannelOption.SO_KEEPALIVE, true); b.option(ChannelOption.TCP_NODELAY, true); b.option(ChannelOption.SO_REUSEADDR, true); b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 4000); b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); b.handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast("decoder", new HttpResponseDecoder()); ch.pipeline().addLast("aggregator", new HttpObjectAggregator(maxContentLength)); ch.pipeline().addLast("encoder", new HttpRequestEncoder()); ch.pipeline().addLast("handler", new HttpClientHandler(NettyHttpClient.this)); } }); timer = new HashedWheelTimer(new NamedThreadFactory(T_HTTP_TIMER), 1, TimeUnit.SECONDS, 64); listener.onSuccess(); }
public HeartbeatManager() { this.timeouts = new ConcurrentHashMap<>(); this.timer = new HashedWheelTimer(new NamedThreadFactory("qmq-heartbeat")); this.timer.start(); }
private Timer newNettyTimer(AsyncHttpClientConfig config) { ThreadFactory threadFactory = config.getThreadFactory() != null ? config.getThreadFactory() : new DefaultThreadFactory(config.getThreadPoolName() + "-timer"); HashedWheelTimer timer = new HashedWheelTimer(threadFactory); timer.start(); return timer; }
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)); } return new DefaultAsyncHttpClient(builder.build()); }
private KeyedPoolImpl<PooledNettyClientResourceManager.PooledClientConnection> setUpConnectionPool( MetricsRegistry metricsRegistry, EventLoopGroup eventLoopGroup) { ScheduledExecutorService timedExecutor = new ScheduledThreadPoolExecutor(1); ExecutorService poolExecutor = MoreExecutors.newDirectExecutorService(); NettyClientMetrics clientMetrics = new NettyClientMetrics(metricsRegistry, "client_"); PooledNettyClientResourceManager resourceManager = new PooledNettyClientResourceManager(eventLoopGroup, new HashedWheelTimer(), clientMetrics); KeyedPoolImpl<PooledNettyClientResourceManager.PooledClientConnection> connectionPool = new KeyedPoolImpl<>(1, 1, 300000, 1, resourceManager, timedExecutor, poolExecutor, metricsRegistry); resourceManager.setPool(connectionPool); return connectionPool; }
public ConnectionPoolBrokerRequestHandler(Configuration config, RoutingTable routingTable, TimeBoundaryService timeBoundaryService, AccessControlFactory accessControlFactory, TableQueryQuotaManager tableQueryQuotaManager, BrokerMetrics brokerMetrics, LiveInstancesChangeListenerImpl liveInstanceChangeListener, MetricsRegistry metricsRegistry) { super(config, routingTable, timeBoundaryService, accessControlFactory, tableQueryQuotaManager, brokerMetrics); _liveInstanceChangeListener = liveInstanceChangeListener; TransportClientConf transportClientConf = new TransportClientConf(); transportClientConf.init(_config.subset(TRANSPORT_CONFIG_PREFIX)); // Set up connection pool _eventLoopGroup = new NioEventLoopGroup(); // Some of the client metrics use histogram which is doing synchronous operation, which are fixed overhead per // request/response // TODO: measure the overhead of this NettyClientMetrics clientMetrics = new NettyClientMetrics(metricsRegistry, "client_"); PooledNettyClientResourceManager resourceManager = new PooledNettyClientResourceManager(_eventLoopGroup, new HashedWheelTimer(), clientMetrics); _poolTimeoutExecutor = new ScheduledThreadPoolExecutor(50); _requestSenderPool = Executors.newCachedThreadPool(); ConnectionPoolConfig connectionPoolConfig = transportClientConf.getConnPool(); _connPool = new KeyedPoolImpl<>(connectionPoolConfig.getMinConnectionsPerServer(), connectionPoolConfig.getMaxConnectionsPerServer(), connectionPoolConfig.getIdleTimeoutMs(), connectionPoolConfig.getMaxBacklogPerServer(), resourceManager, _poolTimeoutExecutor, _requestSenderPool, metricsRegistry); resourceManager.setPool(_connPool); _scatterGather = new ScatterGatherImpl(_connPool, _requestSenderPool); }
@BeforeMethod public void setUp() throws Exception { _countDownLatch = new CountDownLatch(1); NettyTestUtils.LatchControlledRequestHandler requestHandler = new NettyTestUtils.LatchControlledRequestHandler(_countDownLatch); requestHandler.setResponse(NettyTestUtils.DUMMY_RESPONSE); NettyTestUtils.LatchControlledRequestHandlerFactory handlerFactory = new NettyTestUtils.LatchControlledRequestHandlerFactory(requestHandler); _nettyTCPServer = new NettyTCPServer(NettyTestUtils.DEFAULT_PORT, handlerFactory, null, 100, 1, 2); Thread serverThread = new Thread(_nettyTCPServer, "NettyTCPServer"); serverThread.start(); // Wait for at most 10 seconds for server to start NettyTestUtils.waitForServerStarted(_nettyTCPServer, 10 * 1000L); ServerInstance clientServer = new ServerInstance("localhost", NettyTestUtils.DEFAULT_PORT); _nettyTCPClientConnection = new NettyTCPClientConnection(clientServer, new NioEventLoopGroup(), new HashedWheelTimer(), new NettyClientMetrics(null, "abc")); }
@BeforeMethod public void setUp() throws Exception { _requestHandler = new NettyTestUtils.LatchControlledRequestHandler(null); _requestHandler.setResponse(NettyTestUtils.DUMMY_RESPONSE); NettyTestUtils.LatchControlledRequestHandlerFactory handlerFactory = new NettyTestUtils.LatchControlledRequestHandlerFactory(_requestHandler); _nettyTCPServer = new NettyTCPServer(NettyTestUtils.DEFAULT_PORT, handlerFactory, null, 100, 1, 6); Thread serverThread = new Thread(_nettyTCPServer, "NettyTCPServer"); serverThread.start(); // Wait for at most 10 seconds for server to start NettyTestUtils.waitForServerStarted(_nettyTCPServer, 10 * 1000L); _clientServer = new ServerInstance("localhost", NettyTestUtils.DEFAULT_PORT); _nettyTCPClientConnection = new NettyTCPClientConnection(_clientServer, new NioEventLoopGroup(), new HashedWheelTimer(), new NettyClientMetrics(null, "abc")); }
private void setup() { MetricsRegistry registry = new MetricsRegistry(); _timedExecutor = new ScheduledThreadPoolExecutor(1); _service = new ThreadPoolExecutor(10, 10, 10, TimeUnit.DAYS, new LinkedBlockingDeque<Runnable>()); _eventLoopGroup = new NioEventLoopGroup(10); _timer = new HashedWheelTimer(); NettyClientMetrics clientMetrics = new NettyClientMetrics(registry, "client_"); PooledNettyClientResourceManager rm = new PooledNettyClientResourceManager(_eventLoopGroup, _timer, clientMetrics); _pool = new KeyedPoolImpl<PooledNettyClientResourceManager.PooledClientConnection>(1, _maxActiveConnections, 300000, 10, rm, _timedExecutor, MoreExecutors.sameThreadExecutor(), registry); rm.setPool(_pool); _scatterGather = new ScatterGatherImpl(_pool, _service); for (AsyncReader r : _readerThreads) { r.start(); } }
public PulsarClientImpl(ClientConfigurationData conf, EventLoopGroup eventLoopGroup, ConnectionPool cnxPool) throws PulsarClientException { if (conf == null || isBlank(conf.getServiceUrl()) || eventLoopGroup == null) { throw new PulsarClientException.InvalidConfigurationException("Invalid client configuration"); } this.eventLoopGroup = eventLoopGroup; this.conf = conf; conf.getAuthentication().start(); this.cnxPool = cnxPool; externalExecutorProvider = new ExecutorProvider(conf.getNumListenerThreads(), getThreadFactory("pulsar-external-listener")); if (conf.getServiceUrl().startsWith("http")) { lookup = new HttpLookupService(conf, eventLoopGroup); } else { lookup = new BinaryProtoLookupService(this, conf.getServiceUrl(), conf.isUseTls(), externalExecutorProvider.getExecutor()); } timer = new HashedWheelTimer(getThreadFactory("pulsar-timer"), 1, TimeUnit.MILLISECONDS); producers = Maps.newIdentityHashMap(); consumers = Maps.newIdentityHashMap(); state.set(State.Open); }
private RedisClient(RedisClientConfig config) { RedisClientConfig copy = new RedisClientConfig(config); if (copy.getTimer() == null) { copy.setTimer(new HashedWheelTimer()); hasOwnTimer = true;
private RedisClient(RedisClientConfig config) { RedisClientConfig copy = new RedisClientConfig(config); if (copy.getTimer() == null) { copy.setTimer(new HashedWheelTimer()); hasOwnTimer = true;