Changeset 223


Ignore:
Timestamp:
2008-05-14 13:40:08 (5 years ago)
Author:
bruno
Message:

While testing some problems related to the reloading classloader, I've splitted of the construction of the classloaders from the construction of the modules. Think this is useful to keep.

Location:
trunk/core/kauri-runtime/src/main/java/org/kauriproject/runtime
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/kauri-runtime/src/main/java/org/kauriproject/runtime/KauriRuntime.java

    r199 r223  
    3535import org.apache.commons.logging.LogFactory; 
    3636import org.apache.commons.jci.ReloadingClassLoader; 
     37import org.apache.commons.jci.monitor.FilesystemAlterationMonitor; 
     38import org.apache.commons.jci.monitor.FilesystemAlterationObserver; 
    3739 
    3840import java.util.*; 
    3941import java.net.MalformedURLException; 
     42import java.lang.reflect.Field; 
    4043 
    4144/** 
     
    111114        List<ClasspathEntry> sharedClasspath = ClassLoaderConfigurer.configureClassPaths(moduleConfigs, config.getEnableArtifactSharing()); 
    112115 
    113         // Construct the classloader 
     116        // Construct the shared classloader 
    114117        infolog.debug("Creating shared classloader"); 
    115118 
    116119        rootClassLoaderHandle = ClassLoaderBuilder.build(sharedClasspath, this.getClass().getClassLoader(), config.getRepository()); 
    117120        rootClassLoader = rootClassLoaderHandle.getClassLoader(); 
     121 
     122        // Construct the classloaders of the various modules 
     123        List<ClassLoaderHandle> moduleClassLoaders = new ArrayList<ClassLoaderHandle>(); 
     124        for (ModuleConfig cfg : moduleConfigs) { 
     125            ClassLoaderHandle classLoaderHandle = cfg.getClassLoadingConfig().getClassLoader(getClassLoader()); 
     126            moduleClassLoaders.add(classLoaderHandle); 
     127 
     128            ClassLoader classLoader = classLoaderHandle.getClassLoader(); 
     129            if (classLoader instanceof ReloadingClassLoader) { 
     130                // modules should also listen and reload when something in the shared classloader changes 
     131                rootClassLoaderHandle.addReloadNotificationListener((ReloadingClassLoader)classLoader); 
     132            } 
     133        } 
    118134 
    119135        // Create the modules 
    120136        infolog.info("Starting the modules."); 
    121137        modules = new ArrayList<Module>(config.getModules().size()); 
    122         for (ModuleConfig moduleConfig : moduleConfigs) { 
    123             Module module = ModuleBuilder.build(moduleConfig, this, config.getConfigProperties()); 
     138        for (int i = 0; i < moduleConfigs.size(); i++) { 
     139            ModuleConfig moduleConfig = moduleConfigs.get(i); 
     140            Module module = ModuleBuilder.build(moduleConfig, moduleClassLoaders.get(i), this, config.getConfigProperties()); 
    124141            modules.add(module); 
    125142            modulesById.put(module.getDefinition().getId(), module); 
    126             if (module.getClassLoaderHandle().getClassLoader() instanceof ReloadingClassLoader) { 
    127                 // modules should also listen and reload when something in the shared classloader changes 
    128                 rootClassLoaderHandle.addReloadNotificationListener((ReloadingClassLoader)module.getClassLoaderHandle().getClassLoader()); 
    129             } 
    130143        } 
    131144 
  • trunk/core/kauri-runtime/src/main/java/org/kauriproject/runtime/module/build/ModuleBuilder.java

    r205 r223  
    4141    } 
    4242 
    43     public static Module build(ModuleConfig cfg, KauriRuntime runtime, Properties springConfigProperties) throws ArtifactNotFoundException, MalformedURLException { 
    44         return new ModuleBuilder().buildInt(cfg, runtime, springConfigProperties); 
     43    public static Module build(ModuleConfig cfg, ClassLoaderHandle classLoaderHandle, KauriRuntime runtime, Properties springConfigProperties) throws ArtifactNotFoundException, MalformedURLException { 
     44        return new ModuleBuilder().buildInt(cfg, classLoaderHandle, runtime, springConfigProperties); 
    4545    } 
    4646 
    47     private Module buildInt(ModuleConfig cfg, KauriRuntime runtime, Properties springConfigProperties) throws ArtifactNotFoundException, MalformedURLException { 
     47    private Module buildInt(ModuleConfig cfg, ClassLoaderHandle classLoaderHandle, KauriRuntime runtime, Properties springConfigProperties) throws ArtifactNotFoundException, MalformedURLException { 
    4848        infolog.info("Starting module " + cfg.getId() + " - " + cfg.getLocation()); 
    4949        ClassLoader previousContextClassLoader = Thread.currentThread().getContextClassLoader(); 
    5050        RestserviceFacet restserviceFacet = new RestserviceFacet(runtime.getRestserviceManager()); 
    5151        try { 
    52             ClassLoaderHandle classLoaderHandle = cfg.getClassLoadingConfig().getClassLoader(runtime.getClassLoader()); 
    5352            ClassLoader classLoader = classLoaderHandle.getClassLoader(); 
    54  
    5553            Thread.currentThread().setContextClassLoader(classLoader); 
    5654 
Note: See TracChangeset for help on using the changeset viewer.