Refine search
/** * Print a Registry dump to the logger * @param logger the logger to dump on */ public void print(Logger logger) { logger.info("Modules Registry information : " + modules.size() + " modules"); for (Module module : modules.values()) { logger.info(module.getModuleDefinition().getName()); } }
private void addProvider(Module module) { if (logger.isLoggable(Level.FINE)) logger.fine(" Adding the Provider - verified the module"); ClassLoader mcl = module.getClassLoader(); //get manifest entries and process ModuleDefinition md = module.getModuleDefinition(); Manifest mf = null; if (md != null) { mf = md.getManifest(); } if (mf != null) { processManifest(mf, mcl); } handleFutureStatsProviders(); }
static private boolean traverseAndFind(Module toTraverse, ModuleImpl toFind, Vector<Module> traversed) { traversed.add(toTraverse); for (ModuleDependency md : toTraverse.getModuleDefinition().getDependencies()) { ModulesRegistry registry = toTraverse.getRegistry(); for (Module mod : registry.getModules()) { if (mod.getName().equals(md.getName())) { if (mod!=null) { if (mod.getName().equals(toFind.getName())) { return true; } if (traverseAndFind(mod, toFind, traversed)) { return true; } } } } } traversed.remove(toTraverse); return false; } }
private void discoverProbeProviders() { // Iterate thru existing modules if (logger.isLoggable(Level.FINE)) logger.log(Level.FINE, "Discovering the ProbeProviders"); for (Module m : registry.getModules()) { if ((m.getState() == ModuleState.READY) || (m.getState() == ModuleState.RESOLVED)) { if (logger.isLoggable(Level.FINE)) logger.fine(" In (discoverProbeProviders) ModuleState - " + m.getState() + " : " + m.getName()); verifyModule(m); } } }
/** * Find and return a loaded Module that has the package name in its list * of exported interfaces. * * @param packageName the requested implementation package name. * @return the <code>Module</code> instance implementing the package * name or null if not found. * @throws ResolveError if the module dependencies cannot be resolved */ public Module makeModuleFor(String packageName) throws ResolveError { if(parent!=null) { Module m = parent.makeModuleFor(packageName); if(m!=null) return m; } for (Module module : modules.values()) { String[] exportedPkgs = module.getModuleDefinition().getPublicInterfaces(); for (String exportedPkg : exportedPkgs) { if (exportedPkg.equals(packageName)) { module.resolve(); return module; } } } return null; }
assert newModule.getRegistry()==this; newModule.getModuleDefinition()); if (modules.get(id) != null) return; modules.put(id, newModule); for( ModuleMetadata.Entry spi : newModule.getMetadata().getEntries() ) { for( String name : spi.providerNames ) providers.put(name,newModule);
/** * Creates and return a new private module implementation giving a name and * version constraints. A private module is like any other module except * it is not registered to be shared by other potential module users. * * @param moduleName the module name * @param version the desired version * @return the new private module or null if cannot be found * @throws com.sun.enterprise.module.ResolveError if the module dependencies cannot be resolved */ /*package*/ ModuleImpl newPrivateModuleFor(String moduleName, String version) { if(parent!=null) { ModuleImpl m = ModulesRegistryImpl.class.cast(parent).newPrivateModuleFor(moduleName,version); if(m!=null) return m; } ModuleId id = AbstractFactory.getInstance().createModuleId(moduleName, version); Module module = modules.get(id); if (module!=null) { ModuleImpl privateModule = (ModuleImpl)newModule(module.getModuleDefinition()); privateModule.resolve(); return privateModule; } return (ModuleImpl)loadFromRepository(moduleName, version); }
assert module.getRegistry() == this; modules.remove(AbstractFactory.getInstance().createModuleId( module.getModuleDefinition()));
public synchronized void shutdown() { for (Module m : modules.values()) { // Only stop modules that were started after ModulesRegistry // came into existence. if (OSGiModuleImpl.class.cast(m).isTransientlyActive()) { m.stop(); } } // Save the cache before clearing modules try { if (cacheInvalidated) { saveCache(); } } catch (IOException e) { Logger.logger.log(Level.WARNING, "Cannot save metadata to cache", e); } modules.clear(); for (Repository repo : repositories.values()) { try { repo.shutdown(); } catch(Exception e) { java.util.logging.Logger.getAnonymousLogger().log(Level.SEVERE, "Error while closing repository " + repo, e); // swallows } } // don't try to stop the system bundle, as we may be embedded inside // something like Eclipse. }
/** * Saves the inhabitants metadata to the cache in a file called inhabitants * @throws IOException if the file cannot be saved successfully */ private void saveCache() throws IOException { String cacheLocation = getProperty(HK2_CACHE_DIR); if (cacheLocation == null) { return; } File io = new File(cacheLocation, INHABITANTS_CACHE); if(logger.isLoggable(Level.FINE)) { logger.logp(Level.INFO, "OSGiModulesRegistryImpl", "saveCache", "HK2 cache file = {0}", new Object[]{io}); } if (io.exists()) io.delete(); io.createNewFile(); Map<URI, ModuleDefinition> data = new HashMap<URI, ModuleDefinition>(); for (Module m : modules.values()) { data.put(m.getModuleDefinition().getLocations()[0], m.getModuleDefinition()); } ObjectOutputStream os = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(io), getBufferSize())); os.writeObject(data); os.close(); }
public synchronized void shutdown() { for (Module m : modules.values()) { // Only stop modules that were started after ModulesRegistry // came into existence. if (OSGiModuleImpl.class.cast(m).isTransientlyActive()) { m.stop(); } } // Save the cache before clearing modules try { cache.saveCache(); } catch (IOException e) { Logger.logger.log(Level.WARNING, "Cannot save metadata to cache", e); } bctx.removeBundleListener(this); super.shutdown(); }
Collection<Module> modules1 = modulesRegistry.getModules(); Iterator it= modules1.iterator(); String classpath1 = classesDir.getAbsolutePath(); while(it.hasNext()){ Module m = (Module) it.next(); String name = m.getName(); if (name.equals("com.sun.xml.ws") || name.equals("com.sun.xml.bind") ){ ModuleDefinition modDef= m.getModuleDefinition(); java.net.URI[] location = modDef.getLocations(); classpath1+=(File.pathSeparator + new File(location[0]).getAbsolutePath()) ;
Module m = null; if (jerseyIncludeClass != null) { m = registry.find(jerseyIncludeClass); uris = m.getModuleDefinition().getLocations(); } else { ClassLoader classLoader = getClass().getClassLoader();
@Override public synchronized void remove(Module module) { // It is overridden to make it synchronized as it is called from // BundleListener. super.remove(module); // Update cache. final URI location = module.getModuleDefinition().getLocations()[0]; cachedData.remove(location); cacheInvalidated = true; }
private static synchronized String getModulesClasspath(Habitat habitat) { synchronized (ASClassLoaderUtil.class) { if (modulesClassPath == null) { final StringBuilder tmpString = new StringBuilder(); ModulesRegistry mr = habitat.getComponent(ModulesRegistry.class); if (mr != null) { for (Module module : mr.getModules()) { for (URI uri : module.getModuleDefinition().getLocations()) { tmpString.append(uri.getPath()); tmpString.append(File.pathSeparator); } } } //set shared classpath for module so that it doesn't need to be //recomputed for every other invocation modulesClassPath = tmpString.toString(); } } return modulesClassPath; }
final List<Module> delegateModules = new ArrayList<Module>(); for (ModuleDefinition md : mds) { Module m = makeModuleFor(md.getName(), md.getVersion()); delegateModules.add(m); delegateCLs.add(m.getClassLoader());
if (importedBundles!=null) { for( String token : new Tokenizer(importedBundles,",")) { Collection<Module> modules = modulesRegistry.getModules(token); if (modules.size() ==1) { defs.add(modules.iterator().next().getModuleDefinition()); } else { throw new ResolveError("Not able to locate a unique module by name " + token); for (String token : new Tokenizer(requestedWiring, ",")) { for (Object impl : habitat.getAllServices(BuilderHelper.createContractFilter(token))) { Module wiredBundle = modulesRegistry.find(impl.getClass()); if (wiredBundle!=null) { defs.add(wiredBundle.getModuleDefinition()); return parent; } else { return modulesRegistry.getModulesClassLoader(parent, defs);
for (Module m : mr.getModules()) { if (!select(m)) continue; // We don't look in unresolved modules if (m == APIModule) continue; // we have already looked up resources in apiModuleLoader enumerations.add(m.getClassLoader().getResources(name)); for (Module m : mr.getModules()) { if (!select(m)) continue; // We don't look in modules that don't meet punch in criteria if (m == APIModule) continue; // we have already looked up resources in apiModuleLoader punchedInURLs.addAll(m.getMetadata().getDescriptors(serviceName));
localStrings.getLocalString("status", "Status"), localStrings.getLocalString("started", "Started")); Module connectorModule = modulesRegistry.find(engineInfo.getSniffer().getClass()); container.addProperty(localStrings.getLocalString("connector", "Connector"), connectorModule.getModuleDefinition().getName() + ":" + connectorModule.getModuleDefinition().getVersion()); container.addProperty(localStrings.getLocalString("implementation", "Implementation"), engineInfo.getContainer().getClass().toString());
public Enumeration<URL> getResources(String name) throws IOException { initialize(name); if(name.startsWith(META_INF_SERVICES)) { // punch in. find the service loader from any module String serviceName = name.substring(META_INF_SERVICES.length()); Vector<URL> urls = new Vector<URL>(); ModulesRegistry reg = module.getRegistry(); for( Module m : reg.getModules() ) urls.addAll(m.getMetadata().getDescriptors(serviceName)); return urls.elements(); } else { // normal look up return super.getResources(name); } }