io.netty.util.concurrent.DefaultThreadFactory Java Examples
The following examples show how to use
io.netty.util.concurrent.DefaultThreadFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractNettyClient.java From qmq with Apache License 2.0 | 6 votes |
public synchronized void start(NettyClientConfig config) { if (started.get()) { return; } initHandler(); Bootstrap bootstrap = new Bootstrap(); eventLoopGroup = new NioEventLoopGroup(1, new DefaultThreadFactory(clientName + "-boss")); eventExecutors = new DefaultEventExecutorGroup(config.getClientWorkerThreads(), new DefaultThreadFactory(clientName + "-worker")); connectManager = new NettyConnectManageHandler(bootstrap, config.getConnectTimeoutMillis()); bootstrap.group(this.eventLoopGroup) .channel(NioSocketChannel.class) .option(ChannelOption.TCP_NODELAY, true) .option(ChannelOption.SO_KEEPALIVE, false) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.getConnectTimeoutMillis()) .option(ChannelOption.SO_SNDBUF, config.getClientSocketSndBufSize()) .option(ChannelOption.SO_RCVBUF, config.getClientSocketRcvBufSize()) .handler(newChannelInitializer(config, eventExecutors, connectManager)); started.set(true); }
Example #2
Source File: ConnectionPoolTest.java From pulsar with Apache License 2.0 | 6 votes |
@Test public void testSingleIpAddress() throws Exception { ClientConfigurationData conf = new ClientConfigurationData(); EventLoopGroup eventLoop = EventLoopUtil.newEventLoopGroup(1, new DefaultThreadFactory("test")); ConnectionPool pool = Mockito.spy(new ConnectionPool(conf, eventLoop)); conf.setServiceUrl(serviceUrl); PulsarClientImpl client = new PulsarClientImpl(conf, eventLoop, pool); List<InetAddress> result = Lists.newArrayList(); result.add(InetAddress.getByName("127.0.0.1")); Mockito.when(pool.resolveName("non-existing-dns-name")).thenReturn(CompletableFuture.completedFuture(result)); client.newProducer().topic("persistent://sample/standalone/ns/my-topic").create(); client.close(); eventLoop.shutdownGracefully(); }
Example #3
Source File: ConnectionPoolTest.java From pulsar with Apache License 2.0 | 6 votes |
@Test public void testDoubleIpAddress() throws Exception { String serviceUrl = "pulsar://non-existing-dns-name:" + pulsar.getBrokerListenPort().get(); ClientConfigurationData conf = new ClientConfigurationData(); EventLoopGroup eventLoop = EventLoopUtil.newEventLoopGroup(1, new DefaultThreadFactory("test")); ConnectionPool pool = Mockito.spy(new ConnectionPool(conf, eventLoop)); conf.setServiceUrl(serviceUrl); PulsarClientImpl client = new PulsarClientImpl(conf, eventLoop, pool); List<InetAddress> result = Lists.newArrayList(); // Add a non existent IP to the response to check that we're trying the 2nd address as well result.add(InetAddress.getByName("127.0.0.99")); result.add(InetAddress.getByName("127.0.0.1")); Mockito.when(pool.resolveName("non-existing-dns-name")).thenReturn(CompletableFuture.completedFuture(result)); // Create producer should succeed by trying the 2nd IP client.newProducer().topic("persistent://sample/standalone/ns/my-topic").create(); client.close(); eventLoop.shutdownGracefully(); }
Example #4
Source File: ConnectionPoolTest.java From pulsar with Apache License 2.0 | 6 votes |
@Test public void testNoConnectionPool() throws Exception { ClientConfigurationData conf = new ClientConfigurationData(); conf.setConnectionsPerBroker(0); EventLoopGroup eventLoop = EventLoopUtil.newEventLoopGroup(8, new DefaultThreadFactory("test")); ConnectionPool pool = Mockito.spy(new ConnectionPool(conf, eventLoop)); InetSocketAddress brokerAddress = InetSocketAddress.createUnresolved("127.0.0.1", pulsar.getBrokerListenPort().get()); IntStream.range(1, 5).forEach(i -> { pool.getConnection(brokerAddress).thenAccept(cnx -> { Assert.assertTrue(cnx.channel().isActive()); pool.releaseConnection(cnx); Assert.assertTrue(cnx.channel().isActive()); }); }); Assert.assertEquals(pool.getPoolSize(), 0); pool.closeAllConnections(); pool.close(); }
Example #5
Source File: ByteEchoPeerBase.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
public void run() throws Exception { final ThreadFactory connectFactory = new DefaultThreadFactory("rendezvous"); final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1, connectFactory, NioUdtProvider.BYTE_PROVIDER); try { final Bootstrap bootstrap = new Bootstrap(); bootstrap.group(connectGroup) .channelFactory(NioUdtProvider.BYTE_RENDEZVOUS) .handler(new ChannelInitializer<UdtChannel>() { @Override protected void initChannel(UdtChannel ch) throws Exception { ch.pipeline().addLast( new LoggingHandler(LogLevel.INFO), new ByteEchoPeerHandler(messageSize)); } }); final ChannelFuture future = bootstrap.connect(peerAddress, myAddress).sync(); future.channel().closeFuture().sync(); } finally { connectGroup.shutdownGracefully(); } }
Example #6
Source File: ConnectionPoolTest.java From pulsar with Apache License 2.0 | 6 votes |
@Test public void testEnableConnectionPool() throws Exception { ClientConfigurationData conf = new ClientConfigurationData(); conf.setConnectionsPerBroker(5); EventLoopGroup eventLoop = EventLoopUtil.newEventLoopGroup(8, new DefaultThreadFactory("test")); ConnectionPool pool = Mockito.spy(new ConnectionPool(conf, eventLoop)); InetSocketAddress brokerAddress = InetSocketAddress.createUnresolved("127.0.0.1", pulsar.getBrokerListenPort().get()); IntStream.range(1, 10).forEach(i -> { pool.getConnection(brokerAddress).thenAccept(cnx -> { Assert.assertTrue(cnx.channel().isActive()); pool.releaseConnection(cnx); Assert.assertTrue(cnx.channel().isActive()); }); }); Assert.assertTrue(pool.getPoolSize() <= 5 && pool.getPoolSize() > 0); pool.closeAllConnections(); pool.close(); }
Example #7
Source File: ProxyTest.java From pulsar with Apache License 2.0 | 6 votes |
private static PulsarClient getClientActiveConsumerChangeNotSupported(ClientConfigurationData conf) throws Exception { ThreadFactory threadFactory = new DefaultThreadFactory("pulsar-client-io", Thread.currentThread().isDaemon()); EventLoopGroup eventLoopGroup = EventLoopUtil.newEventLoopGroup(conf.getNumIoThreads(), threadFactory); ConnectionPool cnxPool = new ConnectionPool(conf, eventLoopGroup, () -> { return new ClientCnx(conf, eventLoopGroup, ProtocolVersion.v11_VALUE) { @Override protected void handleActiveConsumerChange(CommandActiveConsumerChange change) { throw new UnsupportedOperationException(); } }; }); return new PulsarClientImpl(conf, eventLoopGroup, cnxPool); }
Example #8
Source File: HelloWorldServer.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
/** * 如果有参数值指定了要自定义线程池,则根据参数值确定线程池大小并创建线程池 */ private static Executor getExecutor(String[] args) { Executor executor = null; if (args != null && args.length == 2 && "set-thread-pool".equals(args[0])) { String numStr = args[1]; int nThreads = 0; if (MathUtils.isInteger(numStr)) { nThreads = Integer.parseInt(numStr); } if (nThreads == 0) { nThreads = Runtime.getRuntime().availableProcessors() * 2; } ThreadFactory factory = new DefaultThreadFactory("grpc-server-executor", true); executor = Executors.newFixedThreadPool(nThreads, factory); } return executor; }
Example #9
Source File: ProxyParserTest.java From pulsar with Apache License 2.0 | 6 votes |
private static PulsarClient getClientActiveConsumerChangeNotSupported(ClientConfigurationData conf) throws Exception { ThreadFactory threadFactory = new DefaultThreadFactory("pulsar-client-io", Thread.currentThread().isDaemon()); EventLoopGroup eventLoopGroup = EventLoopUtil.newEventLoopGroup(conf.getNumIoThreads(), threadFactory); ConnectionPool cnxPool = new ConnectionPool(conf, eventLoopGroup, () -> { return new ClientCnx(conf, eventLoopGroup, ProtocolVersion.v11_VALUE) { @Override protected void handleActiveConsumerChange(CommandActiveConsumerChange change) { throw new UnsupportedOperationException(); } }; }); return new PulsarClientImpl(conf, eventLoopGroup, cnxPool); }
Example #10
Source File: PulsarService.java From pulsar with Apache License 2.0 | 6 votes |
public PulsarService(ServiceConfiguration config, Optional<WorkerService> functionWorkerService, Consumer<Integer> processTerminator) { // Validate correctness of configuration PulsarConfigurationLoader.isComplete(config); // validate `advertisedAddress`, `advertisedListeners`, `internalListenerName` Map<String, AdvertisedListener> result = MultipleListenerValidator.validateAndAnalysisAdvertisedListener(config); if (result != null) { this.advertisedListeners = Collections.unmodifiableMap(result); } else { this.advertisedListeners = Collections.unmodifiableMap(Collections.emptyMap()); } state = State.Init; // use `internalListenerName` listener as `advertisedAddress` this.bindAddress = ServiceConfigurationUtils.getDefaultOrConfiguredAddress(config.getBindAddress()); if (!this.advertisedListeners.isEmpty()) { this.advertisedAddress = this.advertisedListeners.get(config.getInternalListenerName()).getBrokerServiceUrl().getHost(); } else { this.advertisedAddress = advertisedAddress(config); } this.brokerVersion = PulsarVersion.getVersion(); this.config = config; this.shutdownService = new MessagingServiceShutdownHook(this, processTerminator); this.loadManagerExecutor = Executors .newSingleThreadScheduledExecutor(new DefaultThreadFactory("pulsar-load-manager")); this.functionWorkerService = functionWorkerService; }
Example #11
Source File: Client.java From Summer with Apache License 2.0 | 6 votes |
public Client(int id, ClientConfig config) throws SchedulerException { this.id = id; log.info("client cluster {}", config.getCluster()); log.info("client serverName {}", config.getServerName()); log.info("client address {}", config.getAddress()); log.info("client port {}", config.getPort()); log.info("client protocol {}", config.getProtocol()); log.info("client charset {}", config.getCharset()); log.info("client password {}", config.getPassword()); log.info("client workerThread {}", config.getWorkerThread()); log.info("client eventThread {}", config.getEventThread()); log.info("client msgLength {}", config.getMsgLength()); log.info("client heartSec {}", config.getHeartSec()); log.info("client reconnectMs {}", config.getReconnectMs()); log.info("client syncRemoteTimeOutMs {}", config.getSyncRemoteTimeOutMs()); log.info("client connectNum {}", config.getConnectNum()); workerGroup = new NioEventLoopGroup(config.getWorkerThread(), new DefaultThreadFactory("ClientWorker", true)); clientContext = new ClientContext(config, this, new NioEventLoopGroup(config.getEventThread(), new DefaultThreadFactory("ClientEvent", true))); clientRemote = new ClientRemote(clientContext); startCheckHeartTimeTask(); }
Example #12
Source File: NettyHttpClient.java From mpush with Apache License 2.0 | 6 votes |
@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(); }
Example #13
Source File: Server.java From Summer with Apache License 2.0 | 6 votes |
public static Server create(ServerConfig config) { log.info("server cluster {}", config.getCluster()); log.info("server serverName {}", config.getServerName()); log.info("server address {}", config.getAddress()); log.info("server port {}", config.getPort()); log.info("server protocol {}", config.getProtocol()); log.info("server charset {}", config.getCharset()); log.info("server password {}", config.getPassword()); log.info("server bossThread {}", config.getBossThread()); log.info("server workerThread {}", config.getWorkerThread()); log.info("server eventThread {}", config.getEventThread()); log.info("server msgLength {}", config.getMsgLength()); log.info("server heartSec {}", config.getHeartSec()); log.info("server coldDownMs {}", config.getColdDownMs()); log.info("server allowAddressEnable {}", config.isAllowAddressEnable()); log.info("server allowAddressList {}", Arrays.toString(config.getAllowAddressList())); log.info("server optionSoBacklog {}", config.getOptionSoBacklog()); config.setUseMainServerThreadPool(false); return new Server(config, new NioEventLoopGroup(config.getBossThread(), new DefaultThreadFactory("ServerBoss")), new NioEventLoopGroup(config.getWorkerThread(), new DefaultThreadFactory("ServerWorker")), Executors.newFixedThreadPool(ThreadCountUtil.convert(config.getEventThread()), new DefaultThreadFactory("ServerEvent")), Executors.newSingleThreadExecutor(new DefaultThreadFactory("ServerPush"))); }
Example #14
Source File: PartitionedProducerImplTest.java From pulsar with Apache License 2.0 | 6 votes |
@Test public void testGetStats() throws Exception { String topicName = "test-stats"; ClientConfigurationData conf = new ClientConfigurationData(); conf.setServiceUrl("pulsar://localhost:6650"); conf.setStatsIntervalSeconds(100); ThreadFactory threadFactory = new DefaultThreadFactory("client-test-stats", Thread.currentThread().isDaemon()); EventLoopGroup eventLoopGroup = EventLoopUtil.newEventLoopGroup(conf.getNumIoThreads(), threadFactory); PulsarClientImpl clientImpl = new PulsarClientImpl(conf, eventLoopGroup); ProducerConfigurationData producerConfData = new ProducerConfigurationData(); producerConfData.setMessageRoutingMode(MessageRoutingMode.CustomPartition); producerConfData.setCustomMessageRouter(new CustomMessageRouter()); assertEquals(Long.parseLong("100"), clientImpl.getConfiguration().getStatsIntervalSeconds()); PartitionedProducerImpl impl = new PartitionedProducerImpl( clientImpl, topicName, producerConfData, 1, null, null, null); impl.getStats(); }
Example #15
Source File: NettySharedConnPool.java From eagle with Apache License 2.0 | 6 votes |
public NettySharedConnPool(MergeConfig config, NettyClient client) { poolName = "eagleClientPool-" + poolNum.getAndIncrement(); this.config = config; this.client = client; totalConnections = new AtomicInteger(0); connectionBag = new ConcurrentBag<>(this); ThreadFactory threadFactory = new DefaultThreadFactory(poolName + " housekeeper", true); int maxClientConnection = config.getExtInt(ConfigEnum.maxClientConnection.getName(), ConfigEnum.maxClientConnection.getIntValue()); this.addConnectionExecutor = createThreadPoolExecutor(maxClientConnection, poolName + " connection adder", threadFactory, new ThreadPoolExecutor.DiscardPolicy()); this.closeConnectionExecutor = createThreadPoolExecutor(maxClientConnection, poolName + " connection closer", threadFactory, new ThreadPoolExecutor.CallerRunsPolicy()); this.houseKeepingExecutorService = new ScheduledThreadPoolExecutor(1, threadFactory, new ThreadPoolExecutor.DiscardPolicy()); this.houseKeepingExecutorService.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); this.houseKeepingExecutorService.setRemoveOnCancelPolicy(true); this.houseKeepingExecutorService.scheduleWithFixedDelay(new HouseKeeper(), 100L, HOUSEKEEPING_PERIOD_MS, MILLISECONDS); fillPool(); }
Example #16
Source File: ZookeeperLeaderElector.java From titus-control-plane with Apache License 2.0 | 6 votes |
private LeaderLatch createNewLeaderLatch(String leaderPath) { final LeaderLatch newLeaderLatch = new LeaderLatch(curator, leaderPath, "127.0.0.1"); newLeaderLatch.addListener( new LeaderLatchListener() { @Override public void isLeader() { announceLeader(); } @Override public void notLeader() { leaderActivator.stopBeingLeader(); } }, Executors.newSingleThreadExecutor(new DefaultThreadFactory("LeaderLatchListener-%s"))); return newLeaderLatch; }
Example #17
Source File: ProjectManagerExtension.java From centraldogma with Apache License 2.0 | 6 votes |
/** * Configures an {@link Executor}, {@link ProjectManager} and {@link CommandExecutor}, * then starts the {@link CommandExecutor} and initializes internal projects. */ @Override public void before(ExtensionContext context) throws Exception { tempDir.create(); final Executor repositoryWorker = newWorker(); purgeWorker = Executors.newSingleThreadScheduledExecutor( new DefaultThreadFactory("purge-worker", true)); projectManager = newProjectManager(repositoryWorker, purgeWorker); executor = newCommandExecutor(projectManager, repositoryWorker); executor.start().get(); ProjectInitializer.initializeInternalProject(executor); afterExecutorStarted(); }
Example #18
Source File: PluginGroup.java From centraldogma with Apache License 2.0 | 6 votes |
/** * Returns a new {@link PluginGroup} which holds the {@link Plugin}s loaded from the classpath. * {@code null} is returned if there is no {@link Plugin} whose target equals to the specified * {@code target}. * * @param classLoader which is used to load the {@link Plugin}s * @param target the {@link PluginTarget} which would be loaded */ @Nullable static PluginGroup loadPlugins(ClassLoader classLoader, PluginTarget target, CentralDogmaConfig config) { requireNonNull(classLoader, "classLoader"); requireNonNull(target, "target"); requireNonNull(config, "config"); final ServiceLoader<Plugin> loader = ServiceLoader.load(Plugin.class, classLoader); final Builder<Plugin> plugins = new Builder<>(); for (Plugin plugin : loader) { if (target == plugin.target() && plugin.isEnabled(config)) { plugins.add(plugin); } } final List<Plugin> list = plugins.build(); if (list.isEmpty()) { return null; } return new PluginGroup(list, Executors.newSingleThreadExecutor(new DefaultThreadFactory( "plugins-for-" + target.name().toLowerCase().replace("_", "-"), true))); }
Example #19
Source File: NettyClientImpl.java From mango with Apache License 2.0 | 6 votes |
public NettyClientImpl(URL url) { super(url); this.remoteAddress = new InetSocketAddress(url.getHost(), url.getPort()); this.timeout = url.getIntParameter(URLParam.requestTimeout.getName(), URLParam.requestTimeout.getIntValue()); this.scheduledExecutorService = Executors.newScheduledThreadPool(5, new DefaultThreadFactory(String.format("%s-%s", Constants.FRAMEWORK_NAME, "future"))); this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() { @Override public void run() { scanRpcFutureTable(); } }, 0, 5000, TimeUnit.MILLISECONDS); }
Example #20
Source File: LoadSimulationClient.java From pulsar with Apache License 2.0 | 6 votes |
/** * Create a LoadSimulationClient with the given JCommander arguments. * * @param arguments * Arguments to configure this from. */ public LoadSimulationClient(final MainArguments arguments) throws Exception { payloadCache = new ConcurrentHashMap<>(); topicsToTradeUnits = new ConcurrentHashMap<>(); admin = PulsarAdmin.builder() .serviceHttpUrl(arguments.serviceURL) .build(); client = PulsarClient.builder() .serviceUrl(arguments.serviceURL) .connectionsPerBroker(4) .ioThreads(Runtime.getRuntime().availableProcessors()) .statsInterval(0, TimeUnit.SECONDS) .build(); port = arguments.port; executor = Executors.newCachedThreadPool(new DefaultThreadFactory("test-client")); }
Example #21
Source File: BrokerService.java From pulsar with Apache License 2.0 | 5 votes |
/** * Schedules and monitors publish-throttling for broker that has publish-throttling configured. It also * disables and shutdowns publish-rate-limiter monitor for broker task if broker disables it. */ public synchronized void setupBrokerPublishRateLimiterMonitor() { // set broker PublishRateLimiterMonitor long brokerTickTimeMs = pulsar().getConfiguration().getBrokerPublisherThrottlingTickTimeMillis(); if (brokerTickTimeMs > 0) { if (this.brokerPublishRateLimiterMonitor == null) { this.brokerPublishRateLimiterMonitor = Executors.newSingleThreadScheduledExecutor( new DefaultThreadFactory("pulsar-broker-publish-rate-limiter-monitor")); if (brokerTickTimeMs > 0) { // schedule task that sums up publish-rate across all cnx on a topic, // and check the rate limit exceeded or not. brokerPublishRateLimiterMonitor.scheduleAtFixedRate( safeRun(() -> checkBrokerPublishThrottlingRate()), brokerTickTimeMs, brokerTickTimeMs, TimeUnit.MILLISECONDS); // schedule task that refreshes rate-limiting bucket brokerPublishRateLimiterMonitor.scheduleAtFixedRate( safeRun(() -> refreshBrokerPublishRate()), 1, 1, TimeUnit.SECONDS); } } } else { // disable publish-throttling for broker. if (this.brokerPublishRateLimiterMonitor != null) { try { this.brokerPublishRateLimiterMonitor.awaitTermination(30, TimeUnit.SECONDS); } catch (InterruptedException e) { log.warn("failed to shutdown brokerPublishRateLimiterMonitor", e); } // make sure topics are not being throttled refreshBrokerPublishRate(); this.brokerPublishRateLimiterMonitor = null; } } }
Example #22
Source File: SameThreadOrderedSafeExecutor.java From pulsar with Apache License 2.0 | 5 votes |
public SameThreadOrderedSafeExecutor() { super( "same-thread-executor", 1, new DefaultThreadFactory("test"), NullStatsLogger.INSTANCE, false, false, 100000, -1, false); }
Example #23
Source File: Server.java From cute-proxy with BSD 2-Clause "Simplified" License | 5 votes |
public void start() throws Exception { ServerBootstrap bootstrap = new ServerBootstrap(); master = new NioEventLoopGroup(1, new DefaultThreadFactory("netty-master")); worker = new NioEventLoopGroup( Math.min(Runtime.getRuntime().availableProcessors() * 2, 16), new DefaultThreadFactory("netty-worker")); bootstrap.group(master, worker) .channel(NioServerSocketChannel.class) .localAddress(new InetSocketAddress(setting.port())) .childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) { int timeoutSeconds = setting.timeout(); var idleStateHandler = new IdleStateHandler(timeoutSeconds, timeoutSeconds, timeoutSeconds, TimeUnit.SECONDS); ch.pipeline().addLast(idleStateHandler); ch.pipeline().addLast(new CloseTimeoutChannelHandler()); var protocolDetector = new ProtocolDetector( new Socks5ProxyMatcher(messageListener, sslContextManager, proxyHandlerSupplier), new Socks4ProxyMatcher(messageListener, sslContextManager, proxyHandlerSupplier), new HttpConnectProxyMatcher(messageListener, sslContextManager, proxyHandlerSupplier), new HttpProxyMatcher(messageListener, proxyHandlerSupplier), new HttpMatcher(sslContextManager) ); ch.pipeline().addLast("protocol-detector", protocolDetector); } }); bindFuture = bootstrap.bind().sync(); logger.info("proxy server start"); }
Example #24
Source File: GrpcServer.java From rpc-thunderdome with Apache License 2.0 | 5 votes |
public static void main(String... args) throws Exception { logger.info("starting server"); String host = System.getProperty("host", "0.0.0.0"); int port = Integer.getInteger("port", 8001); boolean useEpoll = Boolean.getBoolean("usePoll"); Class channel; if (useEpoll) { channel = EpollServerSocketChannel.class; } else { channel = NioServerSocketChannel.class; } ThreadFactory tf = new DefaultThreadFactory("server-elg-", true /*daemon */); NioEventLoopGroup boss = new NioEventLoopGroup(1, tf); NioEventLoopGroup worker = new NioEventLoopGroup(0, tf); NettyServerBuilder builder = NettyServerBuilder.forPort(port) .bossEventLoopGroup(boss) .workerEventLoopGroup(worker) .channelType(channel) .addService(new DefaultService()) .directExecutor() .maxConcurrentCallsPerConnection(Runtime.getRuntime().availableProcessors() * 256) .flowControlWindow(NettyChannelBuilder.DEFAULT_FLOW_CONTROL_WINDOW * 10); io.grpc.Server start = builder.build(); start.start(); logger.info("server started"); start.awaitTermination(); }
Example #25
Source File: SchedulerManager.java From pulsar with Apache License 2.0 | 5 votes |
public synchronized void initialize() { if (!isRunning) { log.info("Initializing scheduler manager"); executorService = new ThreadPoolExecutor(1, 5, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(5)); executorService.setThreadFactory(new ThreadFactoryBuilder().setNameFormat("worker-scheduler-%d").build()); scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(new DefaultThreadFactory("worker-assignment-topic-compactor")); scheduleCompaction(this.scheduledExecutorService, workerConfig.getTopicCompactionFrequencySec()); producer = createProducer(pulsarClient, workerConfig); isRunning = true; lastMessageProduced = null; } }
Example #26
Source File: ZookeeperCacheTest.java From pulsar with Apache License 2.0 | 5 votes |
/** * This tests verifies that {{@link ZooKeeperDataCache} invalidates the cache if the get-operation time-out on that * path. * * @throws Exception */ @Test public void testTimedOutZKCacheRequestInvalidates() throws Exception { OrderedScheduler executor = OrderedScheduler.newSchedulerBuilder().build(); ScheduledExecutorService scheduledExecutor = Executors.newScheduledThreadPool(2); ExecutorService zkExecutor = Executors.newSingleThreadExecutor(new DefaultThreadFactory("mockZk")); MockZooKeeper zkSession = spy(MockZooKeeper.newInstance(MoreExecutors.newDirectExecutorService())); String path = "test"; doNothing().when(zkSession).getData(anyString(), any(Watcher.class), any(DataCallback.class), any()); zkClient.create("/test", new byte[0], null, null); // add readOpDelayMs so, main thread will not serve zkCacahe-returned future and let zkExecutor-thread handle // callback-result process ZooKeeperCache zkCacheService = new LocalZooKeeperCache(zkSession, 1, executor); ZooKeeperDataCache<String> zkCache = new ZooKeeperDataCache<String>(zkCacheService) { @Override public String deserialize(String key, byte[] content) throws Exception { return new String(content); } }; // try to do get on the path which will time-out and async-cache will have non-completed Future try { zkCache.get(path); } catch (Exception e) { // Ok } retryStrategically((test) -> { return zkCacheService.dataCache.getIfPresent(path) == null; }, 5, 1000); assertNull(zkCacheService.dataCache.getIfPresent(path)); executor.shutdown(); zkExecutor.shutdown(); scheduledExecutor.shutdown(); }
Example #27
Source File: ProxyService.java From pulsar with Apache License 2.0 | 5 votes |
public ProxyService(ProxyConfiguration proxyConfig, AuthenticationService authenticationService) throws IOException { checkNotNull(proxyConfig); this.proxyConfig = proxyConfig; this.clientCnxs = Sets.newConcurrentHashSet(); this.topicStats = Maps.newConcurrentMap(); this.lookupRequestSemaphore = new AtomicReference<Semaphore>( new Semaphore(proxyConfig.getMaxConcurrentLookupRequests(), false)); if (proxyConfig.getProxyLogLevel().isPresent()) { proxyLogLevel = Integer.valueOf(proxyConfig.getProxyLogLevel().get()); } else { proxyLogLevel = 0; } this.acceptorGroup = EventLoopUtil.newEventLoopGroup(1, acceptorThreadFactory); this.workerGroup = EventLoopUtil.newEventLoopGroup(numThreads, workersThreadFactory); this.authenticationService = authenticationService; statsExecutor = Executors .newSingleThreadScheduledExecutor(new DefaultThreadFactory("proxy-stats-executor")); statsExecutor.schedule(()->{ this.clientCnxs.forEach(cnx -> { cnx.getDirectProxyHandler().getInboundChannelRequestsRate().calculateRate(); }); this.topicStats.forEach((topic, stats) -> { stats.calculate(); }); }, 60, TimeUnit.SECONDS); }
Example #28
Source File: SingleThreadServer.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
private void start() throws IOException { int port = 50051; Executor executorPool = Executors.newFixedThreadPool(1, new DefaultThreadFactory("grpc-server-executor", true)); EventLoopGroup workerEventLoopGroup = new NioEventLoopGroup(1, new DefaultThreadFactory("grpc-worker-group", true)); //server = ServerBuilder.forPort(port) server = NettyServerBuilder.forPort(port) .executor(executorPool)// 自定义grpc服务端线程池 .workerEventLoopGroup(workerEventLoopGroup)// 自定义netty的worker线程池 .addService(new GreeterImpl()) .build() .start(); logger.info("Server started, listening on " + port); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { // Use stderr here since the logger may have been reset by its JVM shutdown hook. System.err.println("*** shutting down gRPC server since JVM is shutting down"); SingleThreadServer.this.stop(); System.err.println("*** server shut down"); } }); }
Example #29
Source File: PartitionedProducerConsumerTest.java From pulsar with Apache License 2.0 | 5 votes |
@BeforeClass @Override protected void setup() throws Exception { super.internalSetup(); super.producerBaseSetup(); executor = Executors.newFixedThreadPool(1, new DefaultThreadFactory("PartitionedProducerConsumerTest")); }
Example #30
Source File: NettyServerImpl.java From mango with Apache License 2.0 | 5 votes |
public NettyServerImpl(URL url, MessageRouter router){ super(url); this.localAddress = new InetSocketAddress(url.getPort()); this.router = router; this.pool = new ThreadPoolExecutor(url.getIntParameter(URLParam.minWorkerThread.getName(), URLParam.minWorkerThread.getIntValue()), url.getIntParameter(URLParam.maxWorkerThread.getName(), URLParam.maxWorkerThread.getIntValue()), 120, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new DefaultThreadFactory(String.format("%s-%s", Constants.FRAMEWORK_NAME, "biz"))); }