PageRenderTime 37ms CodeModel.GetById 31ms app.highlight 5ms RepoModel.GetById 0ms app.codeStats 0ms

/gentoo-console-bootstrap/src/main/java/com/dowdandassociates/gentoo/console/bootstrap/Main.java

https://bitbucket.org/edowd/gentoo_bootstrap_java
Java | 103 lines | 53 code | 18 blank | 32 comment | 3 complexity | 7e60c9aa34f4068ee9ddb7f091dacfb4 MD5 | raw file
  1/*
  2 *
  3 * Main.java
  4 *
  5 *-----------------------------------------------------------------------------
  6 * Copyright 2013 Dowd and Associates
  7 *
  8 * Licensed under the Apache License, Version 2.0 (the "License");
  9 * you may not use this file except in compliance with the License.
 10 * You may obtain a copy of the License at
 11 *
 12 *     http://www.apache.org/licenses/LICENSE-2.0
 13 *
 14 * Unless required by applicable law or agreed to in writing, software
 15 * distributed under the License is distributed on an "AS IS" BASIS,
 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 17 * See the License for the specific language governing permissions and
 18 * limitations under the License.
 19 *-----------------------------------------------------------------------------
 20 *
 21 */
 22
 23package com.dowdandassociates.gentoo.console.bootstrap;
 24
 25import java.util.Properties;
 26
 27import com.google.inject.Guice;
 28import com.google.inject.Injector;
 29
 30import com.netflix.blitz4j.LoggingConfiguration;
 31import com.netflix.config.DynamicPropertyFactory;
 32import com.netflix.config.DynamicStringProperty;
 33import com.netflix.governator.guice.LifecycleInjector;
 34import com.netflix.governator.lifecycle.LifecycleManager;
 35
 36import org.slf4j.Logger;
 37import org.slf4j.LoggerFactory;
 38
 39import com.dowdandassociates.gentoo.bootstrap.HvmBootstrapModule;
 40import com.dowdandassociates.gentoo.bootstrap.Hvm1BootstrapModule;
 41import com.dowdandassociates.gentoo.bootstrap.ParavirtualBootstrapModule;
 42import com.dowdandassociates.gentoo.bootstrap.Bootstrapper;
 43
 44public class Main
 45{
 46    private static Logger log = LoggerFactory.getLogger(Main.class);
 47
 48    public static void main(String[] args)
 49    {
 50/*
 51        Properties props = new Properties();
 52        props.setProperty("log4j.rootCategory", "DEBUG,stdout");
 53        props.setProperty("log4j.appender.stdout", "org.apache.log4j.ConsoleAppender");
 54        props.setProperty("log4j.appender.stdout.layout", "com.netflix.logging.log4jAdapter.NFPatternLayout");
 55        props.setProperty("log4j.appender.stdout.layout.ConversionPattern", "%d %-5p %C:%L [%t] [%M] %m%n");
 56        props.setProperty("log4j.logger.asyncAppenders", "DEBUG,stdout");
 57        LoggingConfiguration.getInstance().configure(props);
 58*/
 59        DynamicStringProperty virtualizationType = DynamicPropertyFactory.getInstance().getStringProperty("com.dowdandassociates.gentoo.bootstrap.Image.virtualizationType", "hvm");
 60
 61        LoggingConfiguration.getInstance().configure();
 62
 63        try
 64        {
 65//            Injector injector = Guice.createInjector(new Amd64MinimalBootstrapModule());
 66        
 67//            Injector injector = LifecycleInjector.builder().withBootstrapModule(new GentooBootstrapModule()).createInjector();
 68
 69            Injector injector;
 70            if ("hvm".equals(virtualizationType.get()))
 71            {
 72                injector = LifecycleInjector.builder().withBootstrapModule(new HvmBootstrapModule()).createInjector();
 73            }
 74            else if ("hvm1".equals(virtualizationType.get()))
 75            {
 76                injector = LifecycleInjector.builder().withBootstrapModule(new Hvm1BootstrapModule()).createInjector();
 77            }
 78            else
 79            {
 80                injector = LifecycleInjector.builder().withBootstrapModule(new ParavirtualBootstrapModule()).createInjector();
 81            }
 82
 83            LifecycleManager manager = injector.getInstance(LifecycleManager.class);
 84
 85            manager.start();
 86
 87            Bootstrapper bootstrapper = injector.getInstance(Bootstrapper.class);
 88
 89            bootstrapper.execute();
 90
 91            manager.close();
 92        }
 93        catch (Throwable t)
 94        {
 95            log.error(t.getMessage(), t);
 96        }
 97        finally
 98        {
 99            LoggingConfiguration.getInstance().stop();
100        }
101    }
102}
103