public class ConfigurationModuleFactory { public static Module 03_default() { final Module module = new ModuleImpl(); module.setComponent(02Interface.class, new 02()); return module; } public static Module 02_default() { final Module module = new ModuleImpl(); module.setComponent(01Interface.class, new 01()); return module; } }
/** * Trigger manual refresh mechanism, the module will check all its * URLs and generate change events if any of them has changed. This * will allow the owning registry to force a module upgrade at next * module request. */ public void refresh() { URI[] urls = moduleDef.getLocations(); boolean notify = false; for (URI lib : urls) { File f = new File(lib); if (f.exists() && lastModifieds.containsKey(f.getAbsolutePath())) { if (lastModifieds.get(f.getAbsolutePath()) !=f.lastModified()) { //Utils.getDefaultLogger().info("Changed : " + this); notify = true; break; } } } if(notify) { fireChangeEvent(); } }
public void removeImport(ModuleImpl module) { // TODO: this doesn't hide removed module from // other modules that depend on this module. // but the notion of adding dependencies at runtime is broken anyway. if (dependencies.contains(module)) { dependencies.remove(module); getPrivateClassLoader().removeDelegate(module.getClassLoader()); } }
public void dumpState(PrintStream writer) { writer.println("Module " + getName() + " Dump"); writer.println("State " + getState()); for (Module imported : getImports()) { writer.println("Depends on " + imported.getName()); } if (publicCL!=null) { ClassLoaderFacade cloader = publicCL.get(); cloader.dumpState(writer); } }
/** * called by the facade class loader when it is garbage collected. * this is a good time to see if this module should be unloaded. */ @Override public void stop() { // we should only detach if the sticky flag is not set if (!module.isSticky()) { LogHelper.getDefaultLogger().info("ModuleClassLoader stopped " + module.getModuleDefinition().getName()); super.stop(); module.stop(); } }
throw new ResolveError("Module " + getName() + " is in ERROR state"); if (state.compareTo(ModuleState.RESOLVED)>=0) return; throw new ResolveError("Cyclic dependency with " + getName()); Class<ImportPolicy> importPolicyClass = (Class<ImportPolicy>) getPrivateClassLoader().loadClass(moduleDef.getImportPolicyClassName()); ImportPolicy importPolicy = importPolicyClass.newInstance(); importPolicy.prepare(this); m.resolve(); q.addAll(m.dependencies); getPrivateClassLoader().addDelegate(m.getClassLoader());
public Iterable<Class> getProvidersClass(String name) { List<Class> r = serviceClasses.get(name); if(r!=null) return r; // the worst case scenario in the race situation is we end up creating the same list twice, // which is not a big deal. for( String provider : getMetadata().getEntry(name).providerNames) { if(r==null) r = new ArrayList<Class>(); try { r.add(getPrivateClassLoader().loadClass(provider)); } catch (ClassNotFoundException e) { LogHelper.getDefaultLogger().log(Level.SEVERE, "Failed to load "+provider+" from "+getName(),e); } } if(r==null) r = Collections.emptyList(); serviceClasses.put(name, r); return r; }
protected Class<?> findClass(String name) throws ClassNotFoundException { try { return super.findClass(name); } catch (ClassNotFoundException e) { // punch in. find the provider class, no matter where we are. ModuleImpl m = module.getRegistry().getProvidingModule(name); if(m!=null) return m.getPrivateClassLoader().loadClass(name); throw e; } }
resolve(); Class<LifecyclePolicy> lifecyclePolicyClass = (Class<LifecyclePolicy>) getPrivateClassLoader().loadClass(moduleDef.getLifecyclePolicyClassName()); lifecyclePolicy = lifecyclePolicyClass.newInstance(); } catch(ClassNotFoundException e) {
/** * Short-cut for {@code getModuleDefinition().getName()}. */ public String getName() { if (getModuleDefinition()!=null) { return getModuleDefinition().getName(); } return "unknown module"; }
public static void identifyCyclicDependency(ModuleImpl m, Logger logger) { StringBuffer tree = new StringBuffer(); tree.append(m.getName()); Vector<Module> traversed = new Vector<Module>(); boolean success = traverseAndFind(m, m, traversed); if (success) { traversed.remove(0); for (Module mod : traversed) { tree.append("-->" + mod.getName()); } tree.append("-->" + m.getName()); logger.log(Level.SEVERE, "Cyclic dependency : " + tree.toString()); } }
public ClassLoaderFacade run() { return new ClassLoaderFacade(getPrivateClassLoader()); } });
/** * Returns true if this module has any provider for the given service class. */ public boolean hasProvider(Class serviceClass) { String name = serviceClass.getName(); List<Class> v = serviceClasses.get(name); if(v!=null && !v.isEmpty()) return true; return getMetadata().getEntry(name).hasProvider(); }
/** * Create and add a new module to this module's list of * imports. * @param dependency new module's definition */ public Module addImport(ModuleDependency dependency) { ModuleImpl newModule; if (dependency.isShared()) { newModule = (ModuleImpl)registry.makeModuleFor(dependency.getName(), dependency.getVersion()); } else { newModule = registry.newPrivateModuleFor(dependency.getName(), dependency.getVersion()); } addImport(newModule); return newModule; }
throw new ResolveError("Module " + getName() + " is in ERROR state"); if (state.compareTo(ModuleState.RESOLVED)>=0) return; throw new ResolveError("Cyclic dependency with " + getName()); Class<ImportPolicy> importPolicyClass = (Class<ImportPolicy>) getPrivateClassLoader().loadClass(moduleDef.getImportPolicyClassName()); ImportPolicy importPolicy = importPolicyClass.newInstance(); importPolicy.prepare(this); m.resolve(); q.addAll(m.dependencies); getPrivateClassLoader().addDelegate(m.getClassLoader());
public void dumpState(PrintStream writer) { writer.println("Module " + getName() + " Dump"); writer.println("State " + getState()); for (Module imported : getImports()) { writer.println("Depends on " + imported.getName()); } if (publicCL!=null) { ClassLoaderFacade cloader = publicCL.get(); cloader.dumpState(writer); } }
/** * called by the facade class loader when it is garbage collected. * this is a good time to see if this module should be unloaded. */ @Override public void stop() { // we should only detach if the sticky flag is not set if (!module.isSticky()) { LogHelper.getDefaultLogger().info("ModuleClassLoader stopped " + module.getModuleDefinition().getName()); super.stop(); module.stop(); } }
public Iterable<Class> getProvidersClass(String name) { List<Class> r = serviceClasses.get(name); if(r!=null) return r; // the worst case scenario in the race situation is we end up creating the same list twice, // which is not a big deal. for( String provider : getMetadata().getEntry(name).providerNames) { if(r==null) r = new ArrayList<Class>(); try { r.add(getPrivateClassLoader().loadClass(provider)); } catch (ClassNotFoundException e) { LogHelper.getDefaultLogger().log(Level.SEVERE, "Failed to load "+provider+" from "+getName(),e); } } if(r==null) r = Collections.emptyList(); serviceClasses.put(name, r); return r; }