コード例 #1
0
  public final void stop() {
    logger.info("Terminating Environment");

    doBeforeStop(context);

    bootstrapService.fireBootdownStart();

    serviceRegistryContext.unRegister(BootstrapService.class);
    serviceRegistryContext.unRegister(WiringService.class);

    this.wiringService.close();
    serviceRegistryContext.clear();

    doAfterStop(context);

    bootstrapService.fireBootdownEnd();
    logger.info("Environment terminated");
  }
コード例 #2
0
  /** Start the environment */
  protected final void start() {

    StopWatch watch = StopWatch.start();

    // Phase 1 - default services

    // set Logging Service
    this.loggingService = this.resolveLoggingService();

    // Register Logging Service
    serviceRegistryContext.register(LoggingService.class, loggingService);

    // set default logger
    this.logger = new LogServiceDelegatorLogger(this.getClass().getName(), loggingService);

    LoggingConfigurator temporaryConfigurator = this.getStartUpLoggingConfigurator();

    ConfigurableLogListener listener =
        new ConfigurableLogListener(new LoggingConfiguration(null), temporaryConfigurator);
    this.loggingService.addLogListener(listener);

    serviceRegistryContext.register(LocalizationService.class, resolveLocalizationService());

    logger.info("Begin MiddleHeaven bootstrap");

    // set the environment resolver
    this.bootstrapEnvironmentResolver = this.bootstrapEnvironmentResolver();

    // Determine Bootstrap Service
    bootstrapService = new SimpleBootstrapService(this);

    // Register Bootstrap Service
    serviceRegistryContext.register(BootstrapService.class, bootstrapService);
    serviceRegistryContext.register(WiringService.class, wiringService);

    final Collection<Service> services = new LinkedHashSet<Service>();

    context = new DefaultBootstrapContext(this, services);
    // Resolve Container
    // Phase 2 - enviroment

    this.environment = bootstrapEnvironmentResolver.resolveEnvironment(context);

    logger.info("Using environment: {0}", environment.getName());

    // Resolve FileSystem
    FileContext fileSystem = environment.getFileContext();

    serviceRegistryContext.register(
        FileContextService.class, new FileSystemFileContextService(fileSystem));

    wiringService.addConfiguration(new FileContextBindConfiguration(fileSystem));

    // configure permanent logging
    this.loggingService.removeAllListeners();
    listener =
        new ConfigurableLogListener(
            new LoggingConfiguration(fileSystem.getAppLogRepository()),
            this.getPermanentLoggingConfigurator());
    this.loggingService.addLogListener(listener);

    doBeforeStart(context);

    // apply profiles to wiring service
    logger.trace("Configuring active environment profiles");

    String profiles = propertyManagers.getProperty("middleheaven.profiles.active", String.class);

    if (profiles != null) {
      wiringService
          .getActiveProfiles()
          .add(Splitter.on(',').trim().split(profiles).into(new LinkedList<String>()));
    }

    logger.debug("Register environment services");

    // activate services that can be overridden by the container or final
    // environment

    logger.debug("Scanning for extentions");

    List<BootstrapContainerExtention> extentions = new ArrayList<BootstrapContainerExtention>();

    readExtentions(extentions);

    // configurate container with chain of extentions
    BootstrapChain chain = new BootstrapChain(logger, extentions);

    logger.debug("Configuring context");

    logger.debug("Inicialize service discovery");

    environment.preConfigurate(context);

    // config any specific environment activators
    preConfig(context);

    // start bootstrap
    // any participant that wishes to add activators can do so now.
    bootstrapService.fireBootupStart();

    // configure using extentions
    chain.doChain(context);

    // call configuration
    posConfig(context);

    // at this point all needed activators are collected.

    // scan and activate all services
    activate(services, serviceRegistryContext);

    // Phase 3 - inicilize modules
    // ApplicationModulesResolver modulesResolver =
    // environment.getApplicationModulesResolver();

    // modulesResolver.resolveApplicationModules();

    // TODO usar applicationScanner
    StandardApplicationServiceActivator act = new StandardApplicationServiceActivator();

    act.activate(serviceRegistryContext);

    StandardApplicationScannerServiceActivator scannerServiceActivator =
        new StandardApplicationScannerServiceActivator();

    scannerServiceActivator.activate(serviceRegistryContext);

    serviceRegistryContext.getService(ApplicationScanningService.class).scan();

    //
    wiringService.refresh();

    doAfterStart(context);

    environment.posConfigurate(context);

    // inform the end of the bootstrap
    bootstrapService.fireBootupEnd();

    logger.info("MiddleHeaven bootstraped in {0} ms. ", watch.mark().milliseconds());

    logger.info("Starting environment");

    // start the environment. the ui is available.
    environment.start();
  }