Search in sources :

Example 1 with HttpServer

use of org.apache.bookkeeper.http.HttpServer in project bookkeeper by apache.

the class AutoRecoveryMain method main.

public static void main(String[] args) {
    ServerConfiguration conf = null;
    try {
        conf = parseArgs(args);
    } catch (IllegalArgumentException iae) {
        LOG.error("Error parsing command line arguments : ", iae);
        System.err.println(iae.getMessage());
        printUsage();
        System.exit(ExitCode.INVALID_CONF);
    }
    try {
        final AutoRecoveryMain autoRecoveryMain = new AutoRecoveryMain(conf);
        autoRecoveryMain.start();
        HttpServerLoader.loadHttpServer(conf);
        final HttpServer httpServer = HttpServerLoader.get();
        if (conf.isHttpServerEnabled() && httpServer != null) {
            BKHttpServiceProvider serviceProvider = new BKHttpServiceProvider.Builder().setAutoRecovery(autoRecoveryMain).setServerConfiguration(conf).build();
            httpServer.initialize(serviceProvider);
            httpServer.startServer(conf.getHttpServerPort());
        }
        Runtime.getRuntime().addShutdownHook(new Thread() {

            @Override
            public void run() {
                autoRecoveryMain.shutdown();
                if (httpServer != null && httpServer.isRunning()) {
                    httpServer.stopServer();
                }
                LOG.info("Shutdown AutoRecoveryMain successfully");
            }
        });
        LOG.info("Register shutdown hook successfully");
        autoRecoveryMain.join();
        System.exit(autoRecoveryMain.getExitCode());
    } catch (Exception e) {
        LOG.error("Exception running AutoRecoveryMain : ", e);
        System.exit(ExitCode.SERVER_EXCEPTION);
    }
}
Also used : ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) HttpServer(org.apache.bookkeeper.http.HttpServer) CompatibilityException(org.apache.bookkeeper.replication.ReplicationException.CompatibilityException) KeeperException(org.apache.zookeeper.KeeperException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ParseException(org.apache.commons.cli.ParseException) UnavailableException(org.apache.bookkeeper.replication.ReplicationException.UnavailableException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) BKHttpServiceProvider(org.apache.bookkeeper.server.http.BKHttpServiceProvider) BookieCriticalThread(org.apache.bookkeeper.bookie.BookieCriticalThread)

Aggregations

IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 BookieCriticalThread (org.apache.bookkeeper.bookie.BookieCriticalThread)1 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)1 HttpServer (org.apache.bookkeeper.http.HttpServer)1 CompatibilityException (org.apache.bookkeeper.replication.ReplicationException.CompatibilityException)1 UnavailableException (org.apache.bookkeeper.replication.ReplicationException.UnavailableException)1 BKHttpServiceProvider (org.apache.bookkeeper.server.http.BKHttpServiceProvider)1 ParseException (org.apache.commons.cli.ParseException)1 ConfigurationException (org.apache.commons.configuration.ConfigurationException)1 KeeperException (org.apache.zookeeper.KeeperException)1