OmniSciDB  085a039ca4
 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 package com.mapd.parser.server;
17 
19 
20 import org.apache.thrift.server.TServer;
21 import org.apache.thrift.server.TThreadPoolServer;
22 import org.apache.thrift.transport.TSSLTransportFactory;
23 import org.apache.thrift.transport.TSSLTransportFactory.TSSLTransportParameters;
24 import org.apache.thrift.transport.TServerSocket;
25 import org.apache.thrift.transport.TServerTransport;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28 
29 import ai.heavy.thrift.calciteserver.CalciteServer.Processor;
30 
35 public class CalciteServerWrapper implements Runnable {
36  private final static Logger HEAVYDBLOGGER =
37  LoggerFactory.getLogger(CalciteServerWrapper.class);
39  private final Processor processor;
40  private TServer server;
41  private int heavyDBPort = 6274;
42  private String dataDir = ("data/");
43  private int calcitePort = 6279;
44  private boolean shutdown = false;
46 
48  handler = new CalciteServerHandler(heavyDBPort, dataDir, null, null, "");
49  processor = new ai.heavy.thrift.calciteserver.CalciteServer.Processor(handler);
50  }
51 
53  int heavyDBPort,
54  String dataDir,
55  String extensionFunctionsAstFile,
56  SockTransportProperties client_skT,
57  SockTransportProperties server_skT) {
59  heavyDBPort, dataDir, extensionFunctionsAstFile, client_skT, "");
60  processor = new ai.heavy.thrift.calciteserver.CalciteServer.Processor(handler);
61  this.calcitePort = calcitePort;
62  this.heavyDBPort = heavyDBPort;
63  this.server_skT_ = server_skT;
64  }
65 
67  int heavyDBPort,
68  String dataDir,
69  String extensionFunctionsAstFile,
70  SockTransportProperties client_skT,
71  SockTransportProperties server_skT,
72  String userDefinedFunctionsFile) {
73  handler = new CalciteServerHandler(heavyDBPort,
74  dataDir,
75  extensionFunctionsAstFile,
76  client_skT,
77  userDefinedFunctionsFile);
78  processor = new ai.heavy.thrift.calciteserver.CalciteServer.Processor(handler);
79  this.calcitePort = calcitePort;
80  this.heavyDBPort = heavyDBPort;
81  this.server_skT_ = server_skT;
82  try {
83  } catch (Exception e) {
84  e.printStackTrace();
85  }
86  }
87 
88  private void startServer(
89  ai.heavy.thrift.calciteserver.CalciteServer.Processor processor) {
90  try {
91  TServerTransport serverTransport = server_skT_.openServerTransport(calcitePort);
92  server = new TThreadPoolServer(
93  new TThreadPoolServer.Args(serverTransport).processor(processor));
94 
95  HEAVYDBLOGGER.debug("Starting a threaded pool server... Listening on port "
96  + calcitePort + " HEAVY.AI on port " + heavyDBPort);
97  handler.setServer(server);
98  server.serve();
99  // we have been told to shut down (only way to get to this piece of code
100  shutdown = true;
101 
102  } catch (Exception e) {
103  e.printStackTrace();
104  HEAVYDBLOGGER.error(" Calcite server Failed to start ");
105  shutdown = true;
106  }
107  }
108 
109  public void stopServer() {
110  server.stop();
111  shutdown = true;
112  }
113 
114  @Override
115  public void run() {
117  }
118 
119  boolean shutdown() {
120  return shutdown;
121  }
122 }
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)