OmniSciDB  04ee39c94c
CalciteParserFactory.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 
20 
21 import org.apache.commons.pool.PoolableObjectFactory;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24 
25 import java.util.Map;
26 
31 class CalciteParserFactory implements PoolableObjectFactory {
32  final static Logger MAPDLOGGER = LoggerFactory.getLogger(CalciteParserFactory.class);
33 
34  private final String dataDir;
35  private final Map<String, ExtensionFunction> extSigs;
36  private final int mapdPort;
38 
39  public CalciteParserFactory(String dataDir,
40  final Map<String, ExtensionFunction> extSigs,
41  int mapdPort,
43  this.dataDir = dataDir;
44  this.extSigs = extSigs;
45  this.mapdPort = mapdPort;
46  this.socket_transport_properties = skT;
47  }
48 
49  @Override
50  public Object makeObject() throws Exception {
51  MapDParser obj =
52  new MapDParser(dataDir, extSigs, mapdPort, socket_transport_properties);
53  return obj;
54  }
55 
56  @Override
57  public void destroyObject(Object obj) throws Exception {
58  // no need to do anything
59  }
60 
61  @Override
62  public boolean validateObject(Object obj) {
63  MapDParser mdp = (MapDParser) obj;
64  if (mdp.getCallCount() < 1000) {
65  return true;
66  } else {
67  MAPDLOGGER.debug(" invalidating object due to max use count");
68  return false;
69  }
70  }
71 
72  @Override
73  public void activateObject(Object obj) throws Exception {
74  // don't need to do anything
75  }
76 
77  @Override
78  public void passivateObject(Object obj) throws Exception {
79  // nothing to currently do here
80  }
81 }
CalciteParserFactory(String dataDir, final Map< String, ExtensionFunction > extSigs, int mapdPort, SockTransportProperties skT)
final Map< String, ExtensionFunction > extSigs
final SockTransportProperties socket_transport_properties