OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CalciteServerWrapper.java
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.mapd.parser.server;
18 
20 
21 import org.apache.thrift.server.TServer;
22 import org.apache.thrift.server.TThreadPoolServer;
23 import org.apache.thrift.transport.TSSLTransportFactory;
24 import org.apache.thrift.transport.TSSLTransportFactory.TSSLTransportParameters;
25 import org.apache.thrift.transport.TServerSocket;
26 import org.apache.thrift.transport.TServerTransport;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29 
30 import ai.heavy.thrift.calciteserver.CalciteServer.Processor;
31 
32 public class CalciteServerWrapper implements Runnable {
33  private final static Logger HEAVYDBLOGGER =
34  LoggerFactory.getLogger(CalciteServerWrapper.class);
36  private final Processor processor;
37  private TServer server;
38  private int heavyDBPort = 6274;
39  private String dataDir = ("data/");
40  private int calcitePort = 6279;
41  private boolean shutdown = false;
43 
45  handler = new CalciteServerHandler(heavyDBPort, dataDir, null, null, "");
46  processor = new ai.heavy.thrift.calciteserver.CalciteServer.Processor(handler);
47  }
48 
50  int heavyDBPort,
51  String dataDir,
52  String extensionFunctionsAstFile,
53  SockTransportProperties client_skT,
54  SockTransportProperties server_skT) {
56  heavyDBPort, dataDir, extensionFunctionsAstFile, client_skT, "");
57  processor = new ai.heavy.thrift.calciteserver.CalciteServer.Processor(handler);
58  this.calcitePort = calcitePort;
59  this.heavyDBPort = heavyDBPort;
60  this.server_skT_ = server_skT;
61  }
62 
64  int heavyDBPort,
65  String dataDir,
66  String extensionFunctionsAstFile,
67  SockTransportProperties client_skT,
68  SockTransportProperties server_skT,
69  String userDefinedFunctionsFile) {
70  handler = new CalciteServerHandler(heavyDBPort,
71  dataDir,
72  extensionFunctionsAstFile,
73  client_skT,
74  userDefinedFunctionsFile);
75  processor = new ai.heavy.thrift.calciteserver.CalciteServer.Processor(handler);
76  this.calcitePort = calcitePort;
77  this.heavyDBPort = heavyDBPort;
78  this.server_skT_ = server_skT;
79  try {
80  } catch (Exception e) {
81  e.printStackTrace();
82  }
83  }
84 
85  private void startServer(
86  ai.heavy.thrift.calciteserver.CalciteServer.Processor processor) {
87  try {
88  TServerTransport serverTransport = server_skT_.openServerTransport(calcitePort);
89  server = new TThreadPoolServer(
90  new TThreadPoolServer.Args(serverTransport).processor(processor));
91 
92  HEAVYDBLOGGER.debug("Starting a threaded pool server... Listening on port "
93  + calcitePort + " HEAVY.AI on port " + heavyDBPort);
94  handler.setServer(server);
95  server.serve();
96  // we have been told to shut down (only way to get to this piece of code
97  shutdown = true;
98 
99  } catch (Exception e) {
100  e.printStackTrace();
101  HEAVYDBLOGGER.error(" Calcite server Failed to start ");
102  shutdown = true;
103  }
104  }
105 
106  public void stopServer() {
107  server.stop();
108  shutdown = true;
109  }
110 
111  @Override
112  public void run() {
114  }
115 
116  boolean shutdown() {
117  return shutdown;
118  }
119 }
CalciteServerWrapper(int calcitePort, int heavyDBPort, String dataDir, String extensionFunctionsAstFile, SockTransportProperties client_skT, SockTransportProperties server_skT, String userDefinedFunctionsFile)
CalciteServerWrapper(int calcitePort, int heavyDBPort, String dataDir, String extensionFunctionsAstFile, SockTransportProperties client_skT, SockTransportProperties server_skT)
void startServer(ai.heavy.thrift.calciteserver.CalciteServer.Processor processor)