public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ContextRefreshedEvent) { extensionsCache.clear(); singletonBeanCache.clear(); } }
@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); }
@Test public void testSetApplicationContext() { ApplicationContext appContext1 = createMock(ApplicationContext.class); ApplicationContext appContext2 = createMock(ApplicationContext.class); GeoServerExtensions gse = new GeoServerExtensions(); gse.setApplicationContext(appContext1); GeoServerExtensions.extensionsCache.put( GeoServerExtensionsTest.class, new String[] {"fake"}); assertSame(appContext1, GeoServerExtensions.context); gse.setApplicationContext(appContext2); assertSame(appContext2, GeoServerExtensions.context); assertEquals(0, GeoServerExtensions.extensionsCache.size()); }
/** * 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; }
final PaletteCacheEntry entry = (PaletteCacheEntry) paletteCache.get(name); if (entry != null) { if (entry.isStale()) { paletteCache.remove(name); } else { return entry.icm; paletteCache.put(name, new PaletteCacheEntry(resource, icm)); return icm; if (cm instanceof IndexColorModel) { final IndexColorModel icm = (IndexColorModel) cm; paletteCache.put(name, new PaletteCacheEntry(resource, icm)); return icm;
@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); } } } }
/** * 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(); } }
/** * 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; }
void clean() { List<MappingKey> keys = new ArrayList<MappingKey>(buffers.keySet()); for (MappingKey key : keys) { MappedByteBuffer buffer = buffers.remove(key); NIOUtilities.clean(buffer, true); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "Removed mapping for " + key.file.getAbsolutePath()); } } }
/** * Puts the specified tile array in the cache, and returns the tile the * request was looking for * * @param key * @param request * @param tiles * @return */ public synchronized void storeTiles(MetaTileKey key, RenderedImage[] tiles) { tileCache.put(key, new CacheElement(tiles)); }
/** * Constructs an instance using the specified priority level. * * @param priority The priority for this factory, as a number between {@link * AbstractFactory#MINIMUM_PRIORITY MINIMUM_PRIORITY} and {@link * AbstractFactory#MAXIMUM_PRIORITY MAXIMUM_PRIORITY} inclusive. */ public NTv2GridShiftFactory(final int priority) { super(priority); ntv2GridCache = new SoftValueHashMap<String, GridShiftFile>(GRID_CACHE_HARD_REFERENCES); }
@Override public V remove(Object key) { V object = super.remove(key); if (object != null) { dispose((K) key, object); } return object; }
/** * 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; }
.get(name); if (entry != null) { if (entry.isStale()) { paletteCache.remove(name); } else { return entry.eicm; final InverseColorMapOp eicm = new InverseColorMapOp( icm); paletteCache.put(name, new PaletteCacheEntry(file, eicm)); return eicm; final InverseColorMapOp eicm = new InverseColorMapOp( icm); paletteCache.put(name, new PaletteCacheEntry(file, eicm)); return eicm;
@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); } } } }
/** * 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"); } } } }
@Test public void testSetApplicationContext() { ApplicationContext appContext1 = createMock(ApplicationContext.class); ApplicationContext appContext2 = createMock(ApplicationContext.class); GeoServerExtensions gse = new GeoServerExtensions(); gse.setApplicationContext(appContext1); GeoServerExtensions.extensionsCache.put( GeoServerExtensionsTest.class, new String[] {"fake"}); assertSame(appContext1, GeoServerExtensions.context); gse.setApplicationContext(appContext2); assertSame(appContext2, GeoServerExtensions.context); assertEquals(0, GeoServerExtensions.extensionsCache.size()); }
/** * Gathers a tile from the cache, if available * * @param key * @param request * @return */ public synchronized RenderedImage getTile(MetaTileKey key, GetMapRequest request) { CacheElement ce = (CacheElement) tileCache.get(key); if (ce == null) { return null; } return getTile(key, request, ce.tiles); }