All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.mantisrx.api.Bootstrap Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2018 Netflix, Inc.
 *
 *      Licensed under the Apache License, Version 2.0 (the "License");
 *      you may not use this file except in compliance with the License.
 *      You may obtain a copy of the License at
 *
 *          http://www.apache.org/licenses/LICENSE-2.0
 *
 *      Unless required by applicable law or agreed to in writing, software
 *      distributed under the License is distributed on an "AS IS" BASIS,
 *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *      See the License for the specific language governing permissions and
 *      limitations under the License.
 */

package io.mantisrx.api;

import com.google.inject.Injector;
import com.netflix.config.ConfigurationManager;
import com.netflix.governator.InjectorBuilder;
import com.netflix.zuul.netty.server.BaseServerStartup;
import com.netflix.zuul.netty.server.Server;

/**
 * Bootstrap
 *
 * Author: Arthur Gonigberg
 * Date: November 20, 2017
 */
public class Bootstrap {

    public static void main(String[] args) {
        String propertiesFile = null;
        if (args.length >= 2 && "-p".equals(args[0])) {
            propertiesFile = args[1];
            if (propertiesFile.endsWith(".properties")) {
                propertiesFile = propertiesFile.substring(0, propertiesFile.length() - 11);
            }
        }
        new Bootstrap().start(propertiesFile);
    }

    public void start(String configName) {
        System.out.println("Mantis API: starting up.");
        long startTime = System.currentTimeMillis();
        int exitCode = 0;

        Server server = null;

        try {
            ConfigurationManager.loadCascadedPropertiesFromResources(configName);
            Injector injector = InjectorBuilder.fromModule(new MantisAPIModule()).createInjector();
            BaseServerStartup serverStartup = injector.getInstance(BaseServerStartup.class);
            server = serverStartup.server();

            long startupDuration = System.currentTimeMillis() - startTime;
            System.out.println("Mantis API: finished startup. Duration = " + startupDuration + " ms");

            server.start();
            server.awaitTermination();
        }
        catch (Throwable t) {
            t.printStackTrace();
            System.err.println("###############");
            System.err.println("Mantis API: initialization failed. Forcing shutdown now.");
            System.err.println("###############");
            exitCode = 1;
        }
        finally {
            // server shutdown
            if (server != null) server.stop();

            System.exit(exitCode);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy