源码如下:
TServerTransport serverTransport = new TServerSocket(cli.port);
// set all properties specified on the command line
for (Map.Entry<Object, Object> item : hiveconf.entrySet()) {
conf.set((String) item.getKey(), (String) item.getValue());
}
ThriftHiveProcessorFactory hfactory = new ThriftHiveProcessorFactory(null, conf);
TThreadPoolServer.Args sargs = new TThreadPoolServer.Args(serverTransport).processorFactory(hfactory)
.transportFactory(new TTransportFactory()).protocolFactory(new TBinaryProtocol.Factory())
.minWorkerThreads(cli.minWorkerThreads).maxWorkerThreads(cli.maxWorkerThreads);
TServer server = new TThreadPoolServer(sargs);
String msg = "Starting hive server on port " + cli.port + " with " + cli.minWorkerThreads
+ " min worker threads and " + cli.maxWorkerThreads + " max worker threads";
HiveServerHandler.LOG.info(msg);
if (cli.isVerbose()) {
System.err.println(msg);
}
server.serve();
如下:
TThreadPoolServer---这个其实就是普通的BIO类型的线程池,如果连接过多,就会一直等待,直到有可用的线程。
===那么业务逻辑在哪,看了下,
ThriftHiveProcessorFactory hfactory = new ThriftHiveProcessorFactory(null, conf);
进去看代码
public static class ThriftHiveProcessorFactory extends TProcessorFactory {
private final HiveConf conf;
public ThriftHiveProcessorFactory(TProcessor processor, HiveConf conf) {
super(processor);
this.conf = conf;
}
@Override
public TProcessor getProcessor(TTransport trans) {
try {
Iface handler = new HiveServerHandler(new HiveConf(conf));
return new ThriftHive.Processor(handler);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
这样的话,我们就解决了连接如何处理的问题!