merlimat commented on a change in pull request #548: PIP-1 - Introduce Pulsar proxy component URL: https://github.com/apache/incubator-pulsar/pull/548#discussion_r126598774
########## File path: pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyService.java ########## @@ -0,0 +1,243 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.pulsar.proxy.server; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.io.Closeable; +import java.io.IOException; +import java.net.InetAddress; +import java.net.UnknownHostException; + +import org.apache.commons.lang.SystemUtils; +import org.apache.pulsar.broker.ServiceConfiguration; +import org.apache.pulsar.broker.authentication.AuthenticationService; +import org.apache.pulsar.broker.authorization.AuthorizationManager; +import org.apache.pulsar.broker.cache.ConfigurationCacheService; +import org.apache.pulsar.client.api.Authentication; +import org.apache.pulsar.client.api.ClientConfiguration; +import org.apache.pulsar.client.impl.ConnectionPool; +import org.apache.pulsar.client.impl.PulsarClientImpl; +import org.apache.pulsar.zookeeper.LocalZooKeeperConnectionService; +import org.apache.pulsar.zookeeper.ZooKeeperClientFactory; +import org.apache.pulsar.zookeeper.ZooKeeperSessionWatcher.ShutdownService; +import org.apache.pulsar.zookeeper.ZookeeperClientFactoryImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.netty.bootstrap.ServerBootstrap; +import io.netty.buffer.PooledByteBufAllocator; +import io.netty.channel.AdaptiveRecvByteBufAllocator; +import io.netty.channel.ChannelOption; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.epoll.EpollChannelOption; +import io.netty.channel.epoll.EpollEventLoopGroup; +import io.netty.channel.epoll.EpollMode; +import io.netty.channel.epoll.EpollServerSocketChannel; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.nio.NioServerSocketChannel; +import io.netty.util.concurrent.DefaultThreadFactory; + +/** + * Pulsar proxy service + */ +public class ProxyService implements Closeable { + + private final ProxyConfiguration proxyConfig; + private final String serviceUrl; + private final String serviceUrlTls; + private ConfigurationCacheService configurationCacheService; + private AuthenticationService authenticationService; + private AuthorizationManager authorizationManager; + private ZooKeeperClientFactory zkClientFactory = null; + + private final EventLoopGroup acceptorGroup; + private final EventLoopGroup workerGroup; + private final DefaultThreadFactory acceptorThreadFactory = new DefaultThreadFactory("pulsar-discovery-acceptor"); + private final DefaultThreadFactory workersThreadFactory = new DefaultThreadFactory("pulsar-discovery-io"); + + // ConnectionPool is used by the proxy to issue lookup requests + private final PulsarClientImpl client; + + private final Authentication clientAuthentication; + + private BrokerDiscoveryProvider discoveryProvider; + + private LocalZooKeeperConnectionService localZooKeeperConnectionService; + + private static final int numThreads = Runtime.getRuntime().availableProcessors(); + + public ProxyService(ProxyConfiguration proxyConfig) throws IOException { + checkNotNull(proxyConfig); + this.proxyConfig = proxyConfig; + + String hostname; + try { + hostname = InetAddress.getLocalHost().getHostName(); + } catch (UnknownHostException e) { + throw new RuntimeException(e); + } + this.serviceUrl = String.format("pulsar://%s:%d/", hostname, proxyConfig.getServicePort()); + this.serviceUrlTls = String.format("pulsar://%s:%d/", hostname, proxyConfig.getServicePortTls()); + + EventLoopGroup acceptorEventLoop, workersEventLoop; + if (SystemUtils.IS_OS_LINUX) { Review comment: I didn't know about `Epoll.isAvailable()`, probably was introduced later in Netty. Then we can just use that check, no need to verify we are on Linux. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
