Package org.impalaframework.module.bootstrap

Examples of org.impalaframework.module.bootstrap.ModuleManagementFactory


  public void moduleContentsModified(ModuleChangeEvent event) {
    Set<String> modified = getModifiedModules(event);

    if (!modified.isEmpty()) {
      ModuleManagementFactory factory = (ModuleManagementFactory) servletContext
          .getAttribute(WebConstants.IMPALA_FACTORY_ATTRIBUTE);

      for (String moduleName : modified) {

        logger.info("Processing modified module " + moduleName);

        ModuleOperation operation = factory.getModuleOperationRegistry().getOperation(ModuleOperationConstants.ReloadNamedModuleOperation);
        ModuleOperationInput moduleOperationInput = new ModuleOperationInput(null, null, moduleName);
        operation.execute(moduleOperationInput);
      }
    }
  }
View Full Code Here


  @Override
  protected WebApplicationContext createWebApplicationContext(ServletContext servletContext, ApplicationContext parent)
      throws BeansException {

    ModuleManagementFactory factory = createBootStrapFactory(servletContext);

    // load the parent context, which is web-independent
    ModuleDefinitionSource moduleDefinitionSource = getModuleDefinitionSource(servletContext, factory);
   
    ModuleOperationInput input = new ModuleOperationInput(moduleDefinitionSource, null, null);
    ModuleOperation operation = factory.getModuleOperationRegistry().getOperation(ModuleOperationConstants.UpdateRootModuleOperation);   
    operation.execute(input);

    // add items to servlet context
    servletContext.setAttribute(WebConstants.MODULE_DEFINITION_SOURCE_ATTRIBUTE, moduleDefinitionSource);
    servletContext.setAttribute(WebConstants.IMPALA_FACTORY_ATTRIBUTE, factory);

    ConfigurableApplicationContext context = factory.getModuleStateHolder().getRootModuleContext();

    if (context == null) {
      throw new InvalidStateException("Root application context is null");
    }
   
View Full Code Here

  @Override
  public void closeWebApplicationContext(ServletContext servletContext) {

    // the superclass closes the modules
    ModuleManagementFactory factory = (ModuleManagementFactory) servletContext
        .getAttribute(WebConstants.IMPALA_FACTORY_ATTRIBUTE);

    if (factory != null) {

      servletContext.log("Closing modules and root application context hierarchy");

      ModuleOperation operation = factory.getModuleOperationRegistry().getOperation(ModuleOperationConstants.CloseRootModuleOperation);
      boolean success = operation.execute(null).isSuccess();

      if (!success) {
        // this is the fallback in case the rootDefinition is null
        super.closeWebApplicationContext(servletContext);
      }

      // now close the bootstrap factory
      factory.close();
    }
  }
View Full Code Here

    }
  }

  protected WebApplicationContext createWebApplicationContext() throws BeansException {

    ModuleManagementFactory factory = (ModuleManagementFactory) getServletContext().getAttribute(
        WebConstants.IMPALA_FACTORY_ATTRIBUTE);

    if (factory == null) {
      throw new RuntimeException(ModuleManagementFactory.class.getSimpleName()
          + " not set. Have you set up your Impala context loader properly? "
          + "You need to set up a Spring context loader which will set up the parameter '"
          + WebConstants.IMPALA_FACTORY_ATTRIBUTE + "'");
    }

    String moduleName = getServletName();
    if (!initialized) {

      ModuleStateHolder moduleStateHolder = factory.getModuleStateHolder();
      RootModuleDefinition rootDefinition = moduleStateHolder.cloneRootModuleDefinition();
      ModuleDefinition newDefinition = newModuleDefinition(moduleName, rootDefinition);

      ModuleOperation operation = factory.getModuleOperationRegistry().getOperation(
          ModuleOperationConstants.AddModuleOperation);
      operation.execute(new ModuleOperationInput(null, newDefinition, null));
    }

    ApplicationContext context = factory.getModuleStateHolder().getModuleContexts().get(moduleName);

    if (!initialized) {

      if (factory.containsBean("scheduledModuleChangeMonitor")) {
        logger.info("Registering " + getServletName() + " for module modifications");
        ModuleChangeMonitor moduleChangeMonitor = (ModuleChangeMonitor) factory
            .getBean("scheduledModuleChangeMonitor");
        moduleChangeMonitor.addModificationListener(this);
      }
      this.initialized = true;
    }
View Full Code Here

  @Override
  protected WebApplicationContext createWebApplicationContext() throws BeansException {

    // the superclass closes the modules
    ModuleManagementFactory factory = (ModuleManagementFactory) getServletContext().getAttribute(
        WebConstants.IMPALA_FACTORY_ATTRIBUTE);

    if (factory == null) {
      throw new ConfigurationException("Unable to load " + ExternalModuleServlet.class.getName()
          + " as no attribute '" + WebConstants.IMPALA_FACTORY_ATTRIBUTE
          + "' has been set up. Have you set up your Impala ContextLoader correctly?");
    }

    String servletName = getServletName();
    ModuleStateHolder moduleStateHolder = factory.getModuleStateHolder();
   
    if (!initialized) {
     
      ModuleStateChangeNotifier moduleStateChangeNotifier = factory.getModuleStateChangeNotifier();
      moduleStateChangeNotifier.addListener(new ModuleStateChangeListener() {

        public void moduleStateChanged(ModuleStateHolder moduleStateHolder, ModuleStateChange change) {
          try {
            initServletBean();
View Full Code Here

  @ManagedOperation(description = "Uses the current ModuleDefintitionSource to perform a full reload of the module hierarchy")
  public void reloadModules() {
   
    Assert.notNull(servletContext);

    ModuleManagementFactory factory = (ModuleManagementFactory) servletContext
        .getAttribute(WebConstants.IMPALA_FACTORY_ATTRIBUTE);
    if (factory == null) {
      throw new ConfigurationException(
          "No instance of "
              + ModuleManagementFactory.class.getName()
              + " found. Your context loader needs to be configured to create an instance of this class and attach it to the ServletContext using the attribue WebConstants.IMPALA_FACTORY_ATTRIBUTE");
    }

    ModuleDefinitionSource source = (ModuleDefinitionSource) servletContext
        .getAttribute(WebConstants.MODULE_DEFINITION_SOURCE_ATTRIBUTE);
    if (source == null) {
      throw new ConfigurationException(
          "No instance of "
              + ModuleDefinitionSource.class.getName()
              + " found. Your context loader needs to be configured to create an instance of this class and attach it to the ServletContext using the attribue WebConstants.MODULE_DEFINITION_SOURCE_ATTRIBUTE");

    }

    ModuleOperationInput moduleOperationInput = new ModuleOperationInput(source, null, null);
   
    ModuleOperation operation = factory.getModuleOperationRegistry().getOperation(ModuleOperationConstants.ReloadRootModuleOperation);
    operation.execute(moduleOperationInput);
  }
View Full Code Here

TOP

Related Classes of org.impalaframework.module.bootstrap.ModuleManagementFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.