/** Creates a new instance of Module */ /* package */ ModuleImpl(ModulesRegistryImpl registry, ModuleDefinition info) { assert registry!=null && info!=null; this.registry = registry; moduleDef = info; for (URI lib : info.getLocations()) { File f = new File(lib); if (f.exists()) { lastModifieds.put(f.getAbsolutePath(), f.lastModified()); } } state = ModuleState.NEW; }
/** Creates a new instance of Module */ /* package */ ModuleImpl(ModulesRegistryImpl registry, ModuleDefinition info) { assert registry!=null && info!=null; this.registry = registry; moduleDef = info; for (URI lib : info.getLocations()) { File f = new File(lib); if (f.exists()) { lastModifieds.put(f.getAbsolutePath(), f.lastModified()); } } state = ModuleState.NEW; }
@Override public URL[] getURLs() { List<URL> result = new ArrayList<URL>(); if (parent instanceof URLClassLoader) { URL[] parentURLs = URLClassLoader.class.cast(parent).getURLs(); result.addAll(Arrays.asList(parentURLs)); } for (Module m : delegateModules) { ModuleDefinition md = m.getModuleDefinition(); URI[] uris = md.getLocations(); URL[] urls = new URL[uris.length]; for (int i = 0; i < uris.length; ++i) { try { urls[i] = uris[i].toURL(); } catch (MalformedURLException e) { logger.warning("Exception " + e + " while converting " + uris[i] + " to URL"); } } result.addAll(Arrays.asList(urls)); } return result.toArray(new URL[0]); }
@Override public URL[] getURLs() { List<URL> result = new ArrayList<URL>(); if (parent instanceof URLClassLoader) { URL[] parentURLs = URLClassLoader.class.cast(parent).getURLs(); result.addAll(Arrays.asList(parentURLs)); } for (Module m : delegateModules) { ModuleDefinition md = m.getModuleDefinition(); URI[] uris = md.getLocations(); URL[] urls = new URL[uris.length]; for (int i = 0; i < uris.length; ++i) { try { urls[i] = uris[i].toURL(); } catch (MalformedURLException e) { logger.warning("Exception " + e + " while converting " + uris[i] + " to URL"); } } result.addAll(Arrays.asList(urls)); } return result.toArray(new URL[0]); }
/** * 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(); } }
/** * 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(); } }
protected Module newModule(ModuleDefinition moduleDef) { String location = moduleDef.getLocations()[0].toString(); try { if (logger.isLoggable(Level.FINE)) { logger.logp(Level.FINE, "OSGiModulesRegistryImpl", "newModule", "location = {0}", location); } File l = new File(moduleDef.getLocations()[0]); if (l.isDirectory()) { location = "reference:" + location; } Bundle bundle = bctx.installBundle(location); // wrap Bundle by a Module object return new OSGiModuleImpl(this, bundle, moduleDef); } catch (BundleException e) { logger.logp(Level.WARNING, "OSGiModulesRegistryImpl", "newModule", "Exception {0} while adding location = {1}", new Object[]{e, location}); // throw new RuntimeException(e); // continue } return null; }
protected Module newModule(ModuleDefinition moduleDef) { String location = moduleDef.getLocations()[0].toString(); try { if (logger.isLoggable(Level.FINE)) { logger.logp(Level.FINE, "OSGiModulesRegistryImpl", "newModule", "location = {0}", location); } File l = new File(moduleDef.getLocations()[0]); if (l.isDirectory()) { location = "reference:" + location; } Bundle bundle = bctx.installBundle(location); // wrap Bundle by a Module object return new OSGiModuleImpl(this, bundle, moduleDef); } catch (BundleException e) { logger.logp(Level.WARNING, "OSGiModulesRegistryImpl", "newModule", "Exception {0} while adding location = {1}", new Object[]{e, location}); // throw new RuntimeException(e); // continue } return null; }
@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; }
/** * Saves the inhabitants metadata to the cache in a file called inhabitants * @throws java.io.IOException if the file cannot be saved successfully */ public synchronized void saveCache() throws IOException { if (!cacheInvalidated) { return; } String cacheLocation = getProperty(Constants.HK2_CACHE_DIR); if (cacheLocation == null) { return; } File io = new File(cacheLocation, Constants.INHABITANTS_CACHE); if(logger.isLoggable(Level.FINE)) { logger.logp(Level.INFO, getClass().getSimpleName(), "saveCache", "HK2 cache file = {0}", new Object[]{io}); } if (io.exists()) io.delete(); io.createNewFile(); Map<URI, ModuleDefinition> data = new HashMap<URI, ModuleDefinition>(); for (ModuleDefinition m : cachedData.values()) { data.put(m.getLocations()[0], m); } ObjectOutputStream os = new ObjectOutputStream(new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(io)), getBufferSize())); os.writeObject(data); os.close(); cacheInvalidated =false; }
synchronized(this) { if(privateCL==null) { URI[] locations = moduleDef.getLocations(); URL[] urlLocations = new URL[locations.length]; for (int i=0;i<locations.length;i++) {
synchronized(this) { if(privateCL==null) { URI[] locations = moduleDef.getLocations(); URL[] urlLocations = new URL[locations.length]; for (int i=0;i<locations.length;i++) {
/** * 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 void refresh() { URI location = md.getLocations()[0]; File f = new File(location); if (f.lastModified() > bundle.getLastModified()) { try { bundle.update(); registry.getPackageAdmin().refreshPackages(new Bundle[]{bundle}); } catch (BundleException e) { throw new RuntimeException(e); } } }
public void refresh() { URI location = md.getLocations()[0]; File f = new File(location); if (f.lastModified() > bundle.getLastModified()) { try { bundle.update(); registry.getPackageAdmin().refreshPackages(new Bundle[]{bundle}); } catch (BundleException e) { throw new RuntimeException(e); } } }
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; }
uris = m.getModuleDefinition().getLocations(); } else { ClassLoader classLoader = getClass().getClassLoader();
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]; cache.remove(location); }
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()) ;