OmniSciDB  04ee39c94c
CalciteServerWrapper.java
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, 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 import com.mapd.thrift.calciteserver.CalciteServer.Processor;
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 
34 public class CalciteServerWrapper implements Runnable {
35  private final static Logger MAPDLOGGER =
36  LoggerFactory.getLogger(CalciteServerWrapper.class);
38  private final Processor processor;
39  private TServer server;
40  private int mapDPort = 6274;
41  private String dataDir = ("data/");
42  private int calcitePort = 6279;
43  private boolean shutdown = false;
45 
47  handler = new CalciteServerHandler(mapDPort, dataDir, null, null, "");
48  processor = new com.mapd.thrift.calciteserver.CalciteServer.Processor(handler);
49  }
50 
51  public CalciteServerWrapper(int calcitePort,
52  int mapDPort,
53  String dataDir,
54  String extensionFunctionsAstFile,
55  SockTransportProperties client_skT,
56  SockTransportProperties server_skT) {
57  handler = new CalciteServerHandler(
58  mapDPort, dataDir, extensionFunctionsAstFile, client_skT, "");
59  processor = new com.mapd.thrift.calciteserver.CalciteServer.Processor(handler);
60  this.calcitePort = calcitePort;
61  this.mapDPort = mapDPort;
62  this.server_skT_ = server_skT;
63  }
64 
65  public CalciteServerWrapper(int calcitePort,
66  int mapDPort,
67  String dataDir,
68  String extensionFunctionsAstFile,
69  SockTransportProperties client_skT,
70  SockTransportProperties server_skT,
71  String userDefinedFunctionsFile) {
72  handler = new CalciteServerHandler(mapDPort,
73  dataDir,
74  extensionFunctionsAstFile,
75  client_skT,
76  userDefinedFunctionsFile);
77  processor = new com.mapd.thrift.calciteserver.CalciteServer.Processor(handler);
78  this.calcitePort = calcitePort;
79  this.mapDPort = mapDPort;
80  this.server_skT_ = server_skT;
81  try {
82  } catch (Exception e) {
83  e.printStackTrace();
84  }
85  }
86 
87  private void startServer(
88  com.mapd.thrift.calciteserver.CalciteServer.Processor processor) {
89  try {
90  TServerTransport serverTransport = server_skT_.openServerTransport(calcitePort);
91  server = new TThreadPoolServer(
92  new TThreadPoolServer.Args(serverTransport).processor(processor));
93 
94  MAPDLOGGER.debug("Starting a threaded pool server... Listening on port "
95  + calcitePort + " MapD on port " + mapDPort);
96  handler.setServer(server);
97  server.serve();
98  // we have been told to shut down (only way to get to this piece of code
99  shutdown = true;
100 
101  } catch (Exception e) {
102  e.printStackTrace();
103  MAPDLOGGER.error(" Calcite server Failed to start ");
104  shutdown = true;
105  }
106  }
107 
108  public void stopServer() {
109  server.stop();
110  shutdown = true;
111  }
112 
113  @Override
114  public void run() {
115  startServer(processor);
116  }
117 
118  boolean shutdown() {
119  return shutdown;
120  }
121 }
void startServer(com.mapd.thrift.calciteserver.CalciteServer.Processor processor)
CalciteServerWrapper(int calcitePort, int mapDPort, String dataDir, String extensionFunctionsAstFile, SockTransportProperties client_skT, SockTransportProperties server_skT)
CalciteServerWrapper(int calcitePort, int mapDPort, String dataDir, String extensionFunctionsAstFile, SockTransportProperties client_skT, SockTransportProperties server_skT, String userDefinedFunctionsFile)