Github user sounakr commented on a diff in the pull request:

    https://github.com/apache/carbondata/pull/1152#discussion_r126904754
  
    --- Diff: 
core/src/main/java/org/apache/carbondata/core/dictionary/server/DictionaryServer.java
 ---
    @@ -14,153 +14,28 @@
      * See the License for the specific language governing permissions and
      * limitations under the License.
      */
    -package org.apache.carbondata.core.dictionary.server;
    -
    -import org.apache.carbondata.common.logging.LogService;
    -import org.apache.carbondata.common.logging.LogServiceFactory;
    -import org.apache.carbondata.core.constants.CarbonCommonConstants;
    -import 
org.apache.carbondata.core.dictionary.generator.key.DictionaryMessage;
    -import 
org.apache.carbondata.core.dictionary.generator.key.DictionaryMessageType;
    -import org.apache.carbondata.core.util.CarbonProperties;
    -
    -import io.netty.bootstrap.ServerBootstrap;
    -import io.netty.channel.ChannelInitializer;
    -import io.netty.channel.ChannelOption;
    -import io.netty.channel.ChannelPipeline;
    -import io.netty.channel.EventLoopGroup;
    -import io.netty.channel.nio.NioEventLoopGroup;
    -import io.netty.channel.socket.SocketChannel;
    -import io.netty.channel.socket.nio.NioServerSocketChannel;
    -import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
    -
    -/**
    - * Dictionary Server to generate dictionary keys.
    - */
    -public class DictionaryServer {
    -
    -  private static final LogService LOGGER =
    -          
LogServiceFactory.getLogService(DictionaryServer.class.getName());
     
    -  private DictionaryServerHandler dictionaryServerHandler;
    -
    -  private EventLoopGroup boss;
    -  private EventLoopGroup worker;
    -  private int port;
    -  private static Object lock = new Object();
    -  private static DictionaryServer INSTANCE = null;
    +package org.apache.carbondata.core.dictionary.server;
     
    -  private DictionaryServer(int port) {
    -    startServer(port);
    -  }
    +import org.apache.spark.SparkConf;
     
    -  public static DictionaryServer getInstance(int port) {
    -    if (INSTANCE == null) {
    -      synchronized (lock) {
    -        if (INSTANCE == null) {
    -          INSTANCE = new DictionaryServer(port);
    -        }
    -      }
    -    }
    -    return INSTANCE;
    -  }
    +public interface DictionaryServer {
     
    -  /**
    -   * start dictionary server
    -   *
    -   * @param port
    -   */
    -  private void startServer(int port) {
    -    dictionaryServerHandler = new DictionaryServerHandler();
    -    String workerThreads = CarbonProperties.getInstance()
    -        .getProperty(CarbonCommonConstants.DICTIONARY_WORKER_THREADS,
    -            CarbonCommonConstants.DICTIONARY_WORKER_THREADS_DEFAULT);
    -    boss = new NioEventLoopGroup(1);
    -    worker = new NioEventLoopGroup(Integer.parseInt(workerThreads));
    -    // Configure the server.
    -    bindToPort(port);
    -  }
    +  public void startServer(SparkConf conf, String host, int port);
     
    -  /**
    -   * Binds dictionary server to an available port.
    -   *
    -   * @param port
    -   */
    -  private void bindToPort(int port) {
    -    long start = System.currentTimeMillis();
    -    // Configure the server.
    -    int i = 0;
    -    while (i < 10) {
    -      int newPort = port + i;
    -      try {
    -        ServerBootstrap bootstrap = new ServerBootstrap();
    -        bootstrap.group(boss, worker);
    -        bootstrap.channel(NioServerSocketChannel.class);
    -        bootstrap.childHandler(new ChannelInitializer<SocketChannel>() {
    -          @Override public void initChannel(SocketChannel ch) throws 
Exception {
    -            ChannelPipeline pipeline = ch.pipeline();
    -            pipeline
    -                .addLast("LengthDecoder",
    -                    new LengthFieldBasedFrameDecoder(1048576, 0,
    -                        2, 0, 2));
    -            pipeline.addLast("DictionaryServerHandler", 
dictionaryServerHandler);
    -          }
    -        });
    -        bootstrap.childOption(ChannelOption.SO_KEEPALIVE, true);
    -        bootstrap.bind(newPort).sync();
    -        LOGGER.audit("Dictionary Server started, Time spent " + 
(System.currentTimeMillis() - start)
    -            + " Listening on port " + newPort);
    -        this.port = newPort;
    -        break;
    -      } catch (Exception e) {
    -        LOGGER.error(e, "Dictionary Server Failed to bind to port:");
    -        if (i == 9) {
    -          throw new RuntimeException("Dictionary Server Could not bind to 
any port");
    -        }
    -      }
    -      i++;
    -    }
    -  }
    +  public void bindToPort(SparkConf orgConf, String host, int port);
     
    -  /**
    -   *
    -   * @return Port on which the DictionaryServer has started.
    -   */
    -  public int getPort() {
    -    return port;
    -  }
    +  public void shutdown()throws Exception;
     
    -  /**
    -   * shutdown dictionary server
    -   *
    -   * @throws Exception
    -   */
    -  public void shutdown() throws Exception {
    -    LOGGER.info("Shutting down dictionary server");
    -    worker.shutdownGracefully();
    -    boss.shutdownGracefully();
    -  }
    +  public String findLocalIpAddress();
     
    +  public String getHost();
     
    +  public int getPort();
     
    -  /**
    -   * Write dictionary to the store.
    -   * @throws Exception
    -   */
    -  public void writeDictionary() throws Exception {
    -    DictionaryMessage key = new DictionaryMessage();
    -    key.setType(DictionaryMessageType.WRITE_DICTIONARY);
    -    dictionaryServerHandler.processMessage(key);
    -  }
    +  public String getSecretKey();
    --- End diff --
    
    Done


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to