+ "\n\tservlet=<classname>@path");
System.out.println("Command line options will override normal configuration.");
System.exit(0);
}
ChukwaConfiguration conf = new ChukwaConfiguration();
try {
Configuration collectorConf = new Configuration(false);
collectorConf.addResource(new Path(conf.getChukwaConf() + "/chukwa-common.xml"));
collectorConf.addResource(new Path(conf.getChukwaConf() + "/chukwa-collector-conf.xml"));
Checker.checkConf(new OptDictionary(new File(new File(conf.getChukwaHome(), "share/chukwa/lib"), "collector.dict")),
HSlurper.fromHConf(collectorConf));
} catch(Exception e) {e.printStackTrace();}
int portNum = conf.getInt("chukwaCollector.http.port", 9999);
THREADS = conf.getInt("chukwaCollector.http.threads", THREADS);
// pick a writer.
ChukwaWriter w = null;
Map<String, HttpServlet> servletsToAdd = new TreeMap<String, HttpServlet>();
ServletCollector servletCollector = new ServletCollector(conf);
for(String arg: args) {
if(arg.startsWith("writer=")) { //custom writer class
String writerCmd = arg.substring("writer=".length());
if (writerCmd.equals("pretend") || writerCmd.equals("pretend-quietly")) {
boolean verbose = !writerCmd.equals("pretend-quietly");
w = new ConsoleWriter(verbose);
w.init(conf);
servletCollector.setWriter(w);
} else
conf.set("chukwaCollector.writerClass", writerCmd);
} else if(arg.startsWith("servlet=")) { //adding custom servlet
String servletCmd = arg.substring("servlet=".length());
String[] halves = servletCmd.split("@");
try {
Class<?> servletClass = Class.forName(halves[0]);
HttpServlet srvlet = (HttpServlet) servletClass.newInstance();
if(!halves[1].startsWith("/"))
halves[1] = "/" + halves[1];
servletsToAdd.put(halves[1], srvlet);
} catch(Exception e) {
e.printStackTrace();
}
} else if(arg.startsWith("portno=")) {
portNum = Integer.parseInt(arg.substring("portno=".length()));
} else { //unknown arg
System.out.println("WARNING: unknown command line arg " + arg);
System.out.println("Invoke collector with command line arg 'help' for usage");
}
}
// Set up jetty connector
SelectChannelConnector jettyConnector = new SelectChannelConnector();
jettyConnector.setLowResourcesConnections(THREADS - 10);
jettyConnector.setLowResourceMaxIdleTime(1500);
jettyConnector.setPort(portNum);
// Set up jetty server proper, using connector
jettyServer = new Server(portNum);
jettyServer.setConnectors(new Connector[] { jettyConnector });
org.mortbay.thread.BoundedThreadPool pool = new org.mortbay.thread.BoundedThreadPool();
pool.setMaxThreads(THREADS);
jettyServer.setThreadPool(pool);
// Add the collector servlet to server
Context root = new Context(jettyServer, "/", Context.SESSIONS);
root.addServlet(new ServletHolder(servletCollector), "/*");
if(conf.getBoolean(HttpConnector.ASYNC_ACKS_OPT, false))
root.addServlet(new ServletHolder(new CommitCheckServlet(conf)), "/"+CommitCheckServlet.DEFAULT_PATH);
if(conf.getBoolean(LogDisplayServlet.ENABLED_OPT, false))
root.addServlet(new ServletHolder(new LogDisplayServlet(conf)), "/"+LogDisplayServlet.DEFAULT_PATH);
root.setAllowNullPathInfo(false);