* Start up the Thrift2 server.
*
* @param args
*/
public static void main(String[] args) throws Exception {
TServer server = null;
Options options = getOptions();
try {
CommandLine cmd = parseArguments(options, args);
/**
* This is to please both bin/hbase and bin/hbase-daemon. hbase-daemon provides "start" and "stop" arguments hbase
* should print the help if no argument is provided
*/
List<?> argList = cmd.getArgList();
if (cmd.hasOption("help") || !argList.contains("start") || argList.contains("stop")) {
printUsage();
System.exit(1);
}
// Get port to bind to
int listenPort = 0;
try {
listenPort = Integer.parseInt(cmd.getOptionValue("port", DEFAULT_LISTEN_PORT));
} catch (NumberFormatException e) {
throw new RuntimeException("Could not parse the value provided for the port option", e);
}
boolean nonblocking = cmd.hasOption("nonblocking");
boolean hsha = cmd.hasOption("hsha");
Configuration conf = HBaseConfiguration.create();
ThriftMetrics metrics = new ThriftMetrics(
listenPort, conf, THBaseService.Iface.class);
String implType = "threadpool";
if (nonblocking) {
implType = "nonblocking";
} else if (hsha) {
implType = "hsha";
}
conf.set("hbase.regionserver.thrift.server.type", implType);
conf.setInt("hbase.regionserver.thrift.port", listenPort);
// Construct correct ProtocolFactory
boolean compact = cmd.hasOption("compact");
TProtocolFactory protocolFactory = getTProtocolFactory(compact);
THBaseService.Iface handler =
ThriftHBaseServiceHandler.newInstance(conf, metrics);
THBaseService.Processor processor = new THBaseService.Processor(handler);
conf.setBoolean("hbase.regionserver.thrift.compact", compact);
boolean framed = cmd.hasOption("framed") || nonblocking || hsha;
TTransportFactory transportFactory = getTTransportFactory(framed);
conf.setBoolean("hbase.regionserver.thrift.framed", framed);
// TODO: Remove once HBASE-2155 is resolved
if (cmd.hasOption("bind") && (nonblocking || hsha)) {
log.error("The Nonblocking and HsHaServer servers don't support IP address binding at the moment." +
" See https://issues.apache.org/jira/browse/HBASE-2155 for details.");
printUsage();
System.exit(1);
}
// check for user-defined info server port setting, if so override the conf
try {
if (cmd.hasOption("infoport")) {
String val = cmd.getOptionValue("infoport");
conf.setInt("hbase.thrift.info.port", Integer.valueOf(val));
log.debug("Web UI port set to " + val);
}
} catch (NumberFormatException e) {
log.error("Could not parse the value provided for the infoport option", e);
printUsage();
System.exit(1);
}
// Put up info server.
int port = conf.getInt("hbase.thrift.info.port", 9095);
if (port >= 0) {
conf.setLong("startcode", System.currentTimeMillis());
String a = conf.get("hbase.thrift.info.bindAddress", "0.0.0.0");
InfoServer infoServer = new InfoServer("thrift", a, port, false, conf);
infoServer.setAttribute("hbase.conf", conf);
infoServer.start();
}
InetSocketAddress inetSocketAddress = bindToPort(cmd.getOptionValue("bind"), listenPort);
if (nonblocking) {
server = getTNonBlockingServer(protocolFactory, processor, transportFactory, inetSocketAddress);
} else if (hsha) {
server = getTHsHaServer(protocolFactory, processor, transportFactory, inetSocketAddress, metrics);
} else {
server = getTThreadPoolServer(protocolFactory, processor, transportFactory, inetSocketAddress);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
printUsage();
System.exit(1);
}
server.serve();
}