String[] names; if (GeoServerExtensions.context == context) { names = extensionsCache.get(extensionPoint); } else { names = null;
List<Object> spiExtensions = spiCache.get(extensionPoint); if (spiExtensions == null) { spiExtensions = new ArrayList<Object>();
@Test public void testExtensions() { ApplicationContext appContext = createMock(ApplicationContext.class); GeoServerExtensions gse = new GeoServerExtensions(); gse.setApplicationContext(appContext); assertEquals(0, GeoServerExtensions.extensionsCache.size()); expect(appContext.getBeanNamesForType(ExtensionFilter.class)).andReturn(new String[0]); expect(appContext.getBeanNamesForType(GeoServerExtensionsTest.class)) .andReturn(new String[] {"testKey", "fakeKey"}); expect(appContext.getBeanNamesForType(ExtensionProvider.class)).andReturn(new String[0]); expect(appContext.getBean("testKey")).andReturn(this); // note I'm testing null is a valid value. If that's not the case, it // should be reflected in the code, but I'm writing the test after the // code so that's what it does expect(appContext.isSingleton((String) anyObject())).andReturn(true).anyTimes(); expect(appContext.getBean("fakeKey")).andReturn(null); replay(appContext); List<GeoServerExtensionsTest> extensions = GeoServerExtensions.extensions(GeoServerExtensionsTest.class); assertNotNull(extensions); assertEquals(2, extensions.size()); assertTrue(extensions.contains(this)); assertTrue(extensions.contains(null)); assertEquals(3, GeoServerExtensions.extensionsCache.size()); assertTrue(GeoServerExtensions.extensionsCache.containsKey(GeoServerExtensionsTest.class)); assertNotNull(GeoServerExtensions.extensionsCache.get(GeoServerExtensionsTest.class)); assertEquals( 2, GeoServerExtensions.extensionsCache.get(GeoServerExtensionsTest.class).length); verify(appContext); }
/** * Returns a WKT geometry from cache given its URL * * @param urlLib URL of the WKT library * @param wktName name of the WKT shape */ protected String getFromCache(String urlLib, String wktName) { Map<String, String> library = CACHE.get(urlLib); if (library != null) { return (String) library.get(wktName); } return null; }
/** * Adds the shapes contained in a WKT library to the cache; if the url already exists in the * cache, the shapes are not added * * @param urlLib URL of the WKT library as a properties file URL */ protected void addToCache(String urlLib) { Map<String, String> library = CACHE.get(urlLib); if (library == null) { library = new HashMap<String, String>(); Properties propLib = null; try { propLib = this.loadLibrary(urlLib); } catch (IOException e) { LOGGER.log(Level.FINER, e.getMessage(), e); } for (Enumeration<String> e = (Enumeration<String>) propLib.propertyNames(); e.hasMoreElements(); ) { String shpName = (String) (e.nextElement()); library.put(shpName, (String) (propLib.get(shpName))); } CACHE.put(urlLib, library); } }
/** * This method is called when the user has registered another {@link OperationDescriptor} for an * operation and requires to update the various CoverageProcessors. */ public static synchronized void updateProcessors() { Set<Hints> keySet = processorsPool.keySet(); for (Hints key : keySet) { CoverageProcessor processor = processorsPool.get(key); processor.scanForPlugins(); } }
MappedByteBuffer map(FileChannel wrapped, URL url, MapMode mode, long position, long size) throws IOException { if (mode != MapMode.READ_ONLY) { return wrapped.map(mode, position, size); } File file = URLs.urlToFile(url).getCanonicalFile(); MappingKey mk = new MappingKey(file, position, size); MappedByteBuffer buffer = buffers.get(mk); if (buffer == null) { synchronized (this) { buffer = buffers.get(mk); if (buffer == null) { buffer = wrapped.map(mode, position, size); buffers.put(mk, buffer); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "Mapping and caching " + file.getAbsolutePath()); } } } } else { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "Using cached map for " + file.getAbsolutePath()); } } return (MappedByteBuffer) buffer.duplicate(); }
/** * Returns a qualified name from an unqualified type name. Ensures a single value is found. * * @param typeName * @return * @throws IOException */ private Name getNameFromLocal(String typeName) throws IOException { Name result = NAME_CACHE.get(typeName); if (result == null) { Stream<Name> stream = delegate.getNames().stream(); Set<Name> names = stream.filter(name -> typeName.equals(name.getLocalPart())) .collect(Collectors.toSet()); if (names.isEmpty()) { throw new IOException("Could not find a type name '" + typeName + "'"); } else if (names.size() > 1) { throw new IOException("Found multiple matches for '" + typeName + "': " + names); } else { result = names.iterator().next(); NAME_CACHE.put(typeName, result); } } return result; }
synchronized (rasterManager.granulesCache) { if (rasterManager.granulesCache.containsKey(rasterFile.toURI().toString())) { granule = rasterManager.granulesCache.get(rasterFile.toURI().toString()); } else { granule = new Granule(granuleBBox, rasterFile);
Map<Integer, Shape> windbarbs = null; synchronized (CACHE) { windbarbs = CACHE.get(definition); if (windbarbs == null) { windbarbs = createWindBarbs(definition);
public NADConGridShift loadGridShift(URL latGridURL, URL longGridURL) throws FactoryException { NADCONKey key = new NADCONKey(latGridURL.toExternalForm(), longGridURL.toExternalForm()); synchronized (gridCache) { // Prevent simultaneous threads trying to load same grid NADConGridShift grid = gridCache.get(key); if (grid != null) { // Cached: return grid; // - Return } else { // Not cached: grid = loadGridShiftInternal(latGridURL, longGridURL); // - Load if (grid != null) { gridCache.put(key, grid); // - Cache return grid; // - Return } } throw new FactoryException( "NTv2 Grid " + latGridURL + ", " + longGridURL + " could not be created."); } }
@Override public void dispose() { super.dispose(); synchronized (this) { if (coverages != null && !coverages.isEmpty()) { Iterator<String> keysIt = coverages.keySet().iterator(); while (keysIt.hasNext()) { String key = keysIt.next(); CoverageSource sourceCov = coverages.get(key); sourceCov.dispose(); } coverages.clear(); } coverages = null; } if (access != null) { try { access.dispose(); } catch (Throwable t) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, t.getLocalizedMessage(), t); } } } }
/** * Creates a NTv2 Grid. * * @param name The NTv2 grid name * @return the grid * @throws FactoryException if grid cannot be created */ public GridShiftFile createNTv2Grid(URL gridLocation) throws FactoryException { if (gridLocation == null) { throw new FactoryException("The grid location must be not null"); } synchronized (ntv2GridCache) { // Prevent simultaneous threads trying to load same grid GridShiftFile grid = ntv2GridCache.get(gridLocation.toExternalForm()); if (grid != null) { // Cached: return grid; // - Return } else { // Not cached: if (gridLocation != null) { grid = loadNTv2Grid(gridLocation); // - Load if (grid != null) { ntv2GridCache.put(gridLocation.toExternalForm(), grid); // - Cache return grid; // - Return } } throw new FactoryException("NTv2 Grid " + gridLocation + " could not be created."); } } }
/** * This method is called when the user has registered another {@link OperationDescriptor} and * must remove the old operation instance from the processors. * * @param operationName Name of the operation to remove */ public static synchronized void removeOperationFromProcessors(String operationName) { List<String> operations = JAIExt.getJAINames(operationName); Set<Hints> keySet = processorsPool.keySet(); for (Hints key : keySet) { for (String opName : operations) { CoverageProcessor processor = processorsPool.get(key); try { Operation op = processor.getOperation(opName); if (op != null) { processor.removeOperation(op); } } catch (OperationNotFoundException e) { LOGGER.warning("Operation: " + opName + " not found in CoverageProcessor"); } } } }
/** * Get an SVG ColorMap generator for the specified file * * @param file * @return * @throws SAXException * @throws IOException * @throws ParserConfigurationException */ public static GradientColorMapGenerator getColorMapGenerator(final File file) throws SAXException, IOException, ParserConfigurationException { GradientColorMapGenerator generator = null; Utilities.ensureNonNull("file", file); final String identifier = file.getAbsolutePath(); synchronized (cache) { if (cache.containsKey(identifier)) { generator = cache.get(identifier); } else { // create the granule coverageDescriptor generator = parseSVG(file); cache.put(identifier, generator); } } return generator; }
XSDTypeDefinition container, MutablePicoContainer context) { BindingExecutionChain chain = (BindingExecutionChain) chains.get(component);
@Override public VariableAdapter getCoverageDescriptor(Name name) { Utilities.ensureNonNull("name", name); final String name_ = name.toString(); synchronized (coverageSourceDescriptorsCache) { if (coverageSourceDescriptorsCache.containsKey(name_)) { return coverageSourceDescriptorsCache.get(name_); } // create, cache and return VariableAdapter cd; try { String origName = ancillaryFileManager.variablesMap != null ? ancillaryFileManager.variablesMap.get(name) : null; if (origName == null) { origName = name.getLocalPart(); } // else { // throw new IllegalArgumentException("Unable to locate // descriptor for Coverage: "+name); // } cd = new VariableAdapter(this, name, (VariableDS) getVariableByName(origName)); } catch (Exception e) { throw new RuntimeException(e); } coverageSourceDescriptorsCache.put(name_, cd); return cd; } }
/** * Return a {@link CoverageSource} related to the specified coverageName * * @param coverageName * @return * @throws IOException */ private CoverageSource getGridCoverageSource(final String coverageName) throws IOException { // Preliminar check on name availability checkIsSupported(coverageName); synchronized (coverages) { if (coverages.containsKey(coverageName)) { return coverages.get(coverageName); } // create, cache and return CoverageSource source = access.access( new NameImpl(coverageName), null, AccessType.READ_ONLY, null, null); coverages.put(coverageName, source); return source; } }
protected OrderedMap children(XSDElementDeclaration parent) { OrderedMap children = (OrderedMap) element2children.get(parent);
/** * Returns a default processor instance. * * <p><strong>Note:</strong> this is a temporary method, until we have GeoAPI interface for * coverage processor and a factory finder for their implementations. */ public static synchronized CoverageProcessor getInstance(final Hints hints) { if (hints == null || hints.isEmpty()) { if (DEFAULT == null) { DEFAULT = new CacheableCoverageProcessor(); processorsPool.put(new Hints(), DEFAULT); } return DEFAULT; } if (processorsPool.containsKey(hints)) return processorsPool.get(hints); final CoverageProcessor processor = new CacheableCoverageProcessor(hints); processorsPool.put(hints, processor); return processor; }