From 7998c7528893f2783ec894cf433450925e524fb2 Mon Sep 17 00:00:00 2001 From: Lyn Elisa Goltz Date: Mon, 28 Nov 2022 15:01:44 +0100 Subject: [PATCH] #1157 (#8616) - updated ehcache to 3.10.8 --- deegree-core/deegree-core-coverage/pom.xml | 4 +- .../container/CachedRasterDataContainer.java | 45 +++++++-------- .../deegree-tilestore-cache/pom.xml | 4 +- .../tile/persistence/cache/CachedTile.java | 39 ++++++------- .../persistence/cache/CachingTileMatrix.java | 16 +++--- .../persistence/cache/CachingTileStore.java | 57 +++++++++++-------- .../cache/CachingTileStoreBuilder.java | 34 +++++------ pom.xml | 12 +--- 8 files changed, 100 insertions(+), 111 deletions(-) diff --git a/deegree-core/deegree-core-coverage/pom.xml b/deegree-core/deegree-core-coverage/pom.xml index 33fdaf83f4..22b55a278f 100644 --- a/deegree-core/deegree-core-coverage/pom.xml +++ b/deegree-core/deegree-core-coverage/pom.xml @@ -31,8 +31,8 @@ ${project.version} - net.sf.ehcache - ehcache-core + org.ehcache + ehcache com.sun.media diff --git a/deegree-core/deegree-core-coverage/src/main/java/org/deegree/coverage/raster/data/container/CachedRasterDataContainer.java b/deegree-core/deegree-core-coverage/src/main/java/org/deegree/coverage/raster/data/container/CachedRasterDataContainer.java index b9cc512646..54e8ce9836 100644 --- a/deegree-core/deegree-core-coverage/src/main/java/org/deegree/coverage/raster/data/container/CachedRasterDataContainer.java +++ b/deegree-core/deegree-core-coverage/src/main/java/org/deegree/coverage/raster/data/container/CachedRasterDataContainer.java @@ -35,24 +35,22 @@ ----------------------------------------------------------------------------*/ package org.deegree.coverage.raster.data.container; -import java.util.UUID; - -import net.sf.ehcache.Cache; -import net.sf.ehcache.CacheManager; -import net.sf.ehcache.Element; - import org.deegree.coverage.raster.data.RasterData; import org.deegree.coverage.raster.data.container.RasterDataContainerFactory.LoadingPolicy; import org.deegree.coverage.raster.io.RasterDataReader; +import org.ehcache.Cache; +import org.ehcache.CacheManager; +import org.ehcache.config.builders.CacheManagerBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.UUID; + /** * This class implements a cached RasterDataContainer. - * + * * @author Oliver Tonnhofer * @author last edited by: $Author$ - * * @version $Revision$, $Date$ */ public class CachedRasterDataContainer implements RasterDataContainer, RasterDataContainerProvider { @@ -63,17 +61,17 @@ public class CachedRasterDataContainer implements RasterDataContainer, RasterDat private String identifier; - private static Cache cache; + private static Cache cache; private final static String CACHENAME = "CachedRasterDataContainer"; static { try { - CacheManager manager = CacheManager.create(); - manager.addCache( CACHENAME ); // TODO: make cachename configurable // see ehcache.xml for CachedRasterDataContainer configuration - cache = manager.getCache( CACHENAME ); + CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder().build(); + cacheManager.init(); + cache = cacheManager.getCache( CACHENAME, String.class, RasterData.class ); } catch ( Throwable e ) { LOG.error( e.getLocalizedMessage(), e ); } @@ -89,9 +87,9 @@ public CachedRasterDataContainer() { /** * Creates a RasterDataContainer that loads the data on first access. - * + * * @param reader - * RasterReader for the raster source + * RasterReader for the raster source */ public CachedRasterDataContainer( RasterDataReader reader ) { setRasterDataReader( reader ); @@ -106,25 +104,22 @@ public synchronized void setRasterDataReader( RasterDataReader reader ) { @Override public synchronized RasterData getRasterData() { // synchronized to prevent multiple reader.read()-calls when - RasterData raster; if ( LOG.isDebugEnabled() ) { - LOG.debug( "accessing: " + this.toString() ); + LOG.debug( "accessing: " + this ); } - Element elem = cache.get( identifier ); - if ( elem == null ) { - raster = reader.read(); - elem = new Element( identifier, raster ); - cache.put( elem ); + if ( !cache.containsKey( identifier ) ) { + RasterData raster = reader.read(); + cache.put( identifier, raster ); if ( LOG.isDebugEnabled() ) { - LOG.debug( "cache miss: " + this.toString() + "#mem: " + cache.getMemoryStoreSize() ); + LOG.debug( "cache miss: " + this );// + "#mem: " + cache.getMemoryStoreSize() ); } + return raster; } else { - raster = (RasterData) elem.getObjectValue(); if ( LOG.isDebugEnabled() ) { - LOG.debug( "cache hit: " + this.toString() ); + LOG.debug( "cache hit: " + this ); } + return cache.get( identifier ); } - return raster; } @Override diff --git a/deegree-datastores/deegree-tilestores/deegree-tilestore-cache/pom.xml b/deegree-datastores/deegree-tilestores/deegree-tilestore-cache/pom.xml index 98dec88cf6..a3820f20c0 100644 --- a/deegree-datastores/deegree-tilestores/deegree-tilestore-cache/pom.xml +++ b/deegree-datastores/deegree-tilestores/deegree-tilestore-cache/pom.xml @@ -31,8 +31,8 @@ ${project.version} - net.sf.ehcache - ehcache-core + org.ehcache + ehcache diff --git a/deegree-datastores/deegree-tilestores/deegree-tilestore-cache/src/main/java/org/deegree/tile/persistence/cache/CachedTile.java b/deegree-datastores/deegree-tilestores/deegree-tilestore-cache/src/main/java/org/deegree/tile/persistence/cache/CachedTile.java index 1a34fcc6cd..1dbbe38785 100644 --- a/deegree-datastores/deegree-tilestores/deegree-tilestore-cache/src/main/java/org/deegree/tile/persistence/cache/CachedTile.java +++ b/deegree-datastores/deegree-tilestores/deegree-tilestore-cache/src/main/java/org/deegree/tile/persistence/cache/CachedTile.java @@ -41,32 +41,28 @@ Occam Labs UG (haftungsbeschränkt) package org.deegree.tile.persistence.cache; -import static org.slf4j.LoggerFactory.getLogger; - -import java.awt.image.BufferedImage; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; - -import javax.imageio.ImageIO; - -import net.sf.ehcache.Cache; -import net.sf.ehcache.Element; - import org.apache.commons.io.IOUtils; import org.deegree.feature.FeatureCollection; import org.deegree.geometry.Envelope; import org.deegree.tile.Tile; import org.deegree.tile.TileIOException; +import org.ehcache.Cache; import org.slf4j.Logger; +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +import static org.slf4j.LoggerFactory.getLogger; + /** * A {@link Tile} that is backed by a {@link CachingTileStore}. - * + * * @author Andreas Schmitz * @author Markus Schneider * @author last edited by: $Author: mschneider $ - * * @version $Revision: 31882 $, $Date: 2011-09-15 02:05:04 +0200 (Thu, 15 Sep 2011) $ */ public class CachedTile implements Tile { @@ -75,13 +71,13 @@ public class CachedTile implements Tile { private final Tile tile; - private final Cache cache; + private final Cache cache; private final String key; private byte[] data; - public CachedTile( Tile tile, Cache cache, String key ) { + public CachedTile( Tile tile, Cache cache, String key ) { this.tile = tile; this.cache = cache; this.key = key; @@ -89,7 +85,7 @@ public CachedTile( Tile tile, Cache cache, String key ) { @Override public BufferedImage getAsImage() - throws TileIOException { + throws TileIOException { try { return ImageIO.read( new ByteArrayInputStream( getData() ) ); } catch ( IOException e ) { @@ -111,14 +107,13 @@ public Envelope getEnvelope() { @Override public FeatureCollection getFeatures( int i, int j, int limit ) - throws UnsupportedOperationException { + throws UnsupportedOperationException { return tile.getFeatures( i, j, limit ); } private synchronized byte[] getData() { if ( data == null ) { - Element elem = cache.get( key ); - if ( elem == null ) { + if ( !cache.containsKey( key ) ) { try { InputStream is = tile.getAsStream(); if ( is == null ) { @@ -126,13 +121,13 @@ private synchronized byte[] getData() { } else { data = IOUtils.toByteArray( is ); } - cache.put( new Element( key, data ) ); + cache.put( key, data ); } catch ( IOException e ) { LOG.trace( e.getMessage(), e ); throw new TileIOException( e.getMessage(), e ); } } else { - data = (byte[]) elem.getValue(); + data = cache.get( key ); } } return data; diff --git a/deegree-datastores/deegree-tilestores/deegree-tilestore-cache/src/main/java/org/deegree/tile/persistence/cache/CachingTileMatrix.java b/deegree-datastores/deegree-tilestores/deegree-tilestore-cache/src/main/java/org/deegree/tile/persistence/cache/CachingTileMatrix.java index b13d8ab8b5..33251f48aa 100644 --- a/deegree-datastores/deegree-tilestores/deegree-tilestore-cache/src/main/java/org/deegree/tile/persistence/cache/CachingTileMatrix.java +++ b/deegree-datastores/deegree-tilestores/deegree-tilestore-cache/src/main/java/org/deegree/tile/persistence/cache/CachingTileMatrix.java @@ -41,20 +41,18 @@ Occam Labs UG (haftungsbeschränkt) package org.deegree.tile.persistence.cache; -import java.util.List; - -import net.sf.ehcache.Cache; - import org.deegree.tile.Tile; import org.deegree.tile.TileDataLevel; import org.deegree.tile.TileMatrix; +import org.ehcache.Cache; + +import java.util.List; /** * CachingTileMatrix - * + * * @author Andreas Schmitz * @author last edited by: $Author: mschneider $ - * * @version $Revision: 31882 $, $Date: 2011-09-15 02:05:04 +0200 (Thu, 15 Sep 2011) $ */ @@ -62,11 +60,11 @@ public class CachingTileMatrix implements TileDataLevel { private final TileDataLevel tileMatrix; - private final Cache cache; + private final Cache cache; private final String identifier; - public CachingTileMatrix( TileDataLevel tileMatrix, Cache cache ) { + public CachingTileMatrix( TileDataLevel tileMatrix, Cache cache ) { this.tileMatrix = tileMatrix; this.cache = cache; this.identifier = tileMatrix.getMetadata().getIdentifier(); @@ -80,7 +78,7 @@ public TileMatrix getMetadata() { @Override public Tile getTile( long x, long y ) { Tile tile = tileMatrix.getTile( x, y ); - if (tile == null) { + if ( tile == null ) { return null; } String key = identifier + "_" + x + "_" + y; diff --git a/deegree-datastores/deegree-tilestores/deegree-tilestore-cache/src/main/java/org/deegree/tile/persistence/cache/CachingTileStore.java b/deegree-datastores/deegree-tilestores/deegree-tilestore-cache/src/main/java/org/deegree/tile/persistence/cache/CachingTileStore.java index 0de4fb54d6..15e3efac40 100644 --- a/deegree-datastores/deegree-tilestores/deegree-tilestore-cache/src/main/java/org/deegree/tile/persistence/cache/CachingTileStore.java +++ b/deegree-datastores/deegree-tilestores/deegree-tilestore-cache/src/main/java/org/deegree/tile/persistence/cache/CachingTileStore.java @@ -40,16 +40,6 @@ Occam Labs UG (haftungsbeschränkt) ----------------------------------------------------------------------------*/ package org.deegree.tile.persistence.cache; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import net.sf.ehcache.Cache; -import net.sf.ehcache.CacheManager; - import org.deegree.geometry.Envelope; import org.deegree.tile.DefaultTileDataSet; import org.deegree.tile.Tile; @@ -60,13 +50,25 @@ Occam Labs UG (haftungsbeschränkt) import org.deegree.tile.persistence.TileStoreTransaction; import org.deegree.workspace.Resource; import org.deegree.workspace.ResourceMetadata; +import org.ehcache.Cache; +import org.ehcache.CacheManager; +import org.ehcache.config.Configuration; +import org.ehcache.config.builders.CacheManagerBuilder; +import org.ehcache.xml.XmlConfiguration; + +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; /** * {@link TileStore} that acts as a caching proxy to another {@link TileStore}. - * + * * @author Andreas Schmitz * @author last edited by: $Author: mschneider $ - * * @version $Revision: 31882 $, $Date: 2011-09-15 02:05:04 +0200 (Thu, 15 Sep 2011) $ */ public class CachingTileStore implements TileStore { @@ -75,27 +77,29 @@ public class CachingTileStore implements TileStore { private final CacheManager cacheManager; - private final Cache cache; + private final Cache cache; private Map tileMatrixSets; private ResourceMetadata metadata; - public CachingTileStore( TileStore tileStore, CacheManager cacheManager, String cacheName, + public CachingTileStore( TileStore tileStore, String cacheName, URL cacheConfiguration, ResourceMetadata metadata ) { this.tileStore = tileStore; - this.cacheManager = cacheManager; this.metadata = metadata; - this.cache = cacheManager.getCache( cacheName ); + Configuration xmlConfig = new XmlConfiguration( cacheConfiguration ); + this.cacheManager = CacheManagerBuilder.newCacheManager( xmlConfig ); + cacheManager.init(); + cache = this.cacheManager.getCache( cacheName, String.class, byte[].class ); } @Override public void init() { Collection ids = tileStore.getTileDataSetIds(); - tileMatrixSets = new HashMap(); + tileMatrixSets = new HashMap<>(); for ( String id : ids ) { TileDataSet cachedDataset = tileStore.getTileDataSet( id ); - List list = new ArrayList(); + List list = new ArrayList<>(); for ( TileDataLevel tm : cachedDataset.getTileDataLevels() ) { list.add( new CachingTileMatrix( tm, cache ) ); } @@ -112,7 +116,7 @@ public Collection getTileDataSetIds() { @Override public void destroy() { - cacheManager.shutdown(); + cacheManager.close(); } @Override @@ -136,16 +140,17 @@ public Tile getTile( String tileMatrixSet, String tileMatrix, int x, int y ) { /** * Removes matching objects from cache. - * + * * @param tileMatrixSet - * the id of the tile matrix set + * the id of the tile matrix set * @param envelope - * may be null, in which case all objects will be removed from the cache + * may be null, in which case all objects will be removed from the cache */ public long invalidateCache( String tileMatrixSet, Envelope envelope ) { if ( envelope == null ) { - int size = cache.getSize(); - cache.removeAll(); + //TODO:cache.getSize(); + int size = 0; + cache.clear(); return size; } long cnt = 0; @@ -155,7 +160,9 @@ public long invalidateCache( String tileMatrixSet, Envelope envelope ) { String id = tm.getMetadata().getIdentifier(); for ( long x = ts[0]; x <= ts[2]; ++x ) { for ( long y = ts[1]; y <= ts[3]; ++y ) { - if ( cache.remove( id + "_" + x + "_" + y ) ) { + String key = id + "_" + x + "_" + y; + if ( cache.containsKey( key ) ) { + cache.remove( key ); ++cnt; } } diff --git a/deegree-datastores/deegree-tilestores/deegree-tilestore-cache/src/main/java/org/deegree/tile/persistence/cache/CachingTileStoreBuilder.java b/deegree-datastores/deegree-tilestores/deegree-tilestore-cache/src/main/java/org/deegree/tile/persistence/cache/CachingTileStoreBuilder.java index f69da15a8f..94ad879516 100644 --- a/deegree-datastores/deegree-tilestores/deegree-tilestore-cache/src/main/java/org/deegree/tile/persistence/cache/CachingTileStoreBuilder.java +++ b/deegree-datastores/deegree-tilestores/deegree-tilestore-cache/src/main/java/org/deegree/tile/persistence/cache/CachingTileStoreBuilder.java @@ -27,11 +27,6 @@ ----------------------------------------------------------------------------*/ package org.deegree.tile.persistence.cache; -import java.io.File; - -import net.sf.ehcache.CacheException; -import net.sf.ehcache.CacheManager; - import org.deegree.tile.persistence.TileStore; import org.deegree.tile.persistence.TileStoreProvider; import org.deegree.workspace.ResourceBuilder; @@ -39,11 +34,14 @@ import org.deegree.workspace.ResourceMetadata; import org.deegree.workspace.Workspace; +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; + /** * This class is responsible for building caching tile stores. - * + * * @author Andreas Schmitz - * * @since 3.4 */ public class CachingTileStoreBuilder implements ResourceBuilder { @@ -64,20 +62,22 @@ public CachingTileStoreBuilder( org.deegree.tile.persistence.cache.jaxb.CachingT @Override public TileStore build() { try { - String cache = cfg.getCacheConfiguration(); - File f = new File( cache ); - if ( !f.isAbsolute() ) { - f = metadata.getLocation().resolveToFile( cache ); - } - CacheManager cmgr = new CacheManager( f.toURI().toURL() ); + URL cacheConfiguration = getCacheConfiguration(); TileStore tileStore = workspace.getResource( TileStoreProvider.class, cfg.getTileStoreId() ); - return new CachingTileStore( tileStore, cmgr, cfg.getCacheName(), metadata ); - } catch ( CacheException e ) { - // case needed, as NPE's inside exception can occur otherwise - throw new ResourceInitException( "Unable to create tile store: " + e.getMessage() ); + return new CachingTileStore( tileStore, cfg.getCacheName(), cacheConfiguration, metadata ); } catch ( Exception e ) { throw new ResourceInitException( "Unable to create tile store", e ); } } + private URL getCacheConfiguration() + throws MalformedURLException { + String cacheConfiguration = cfg.getCacheConfiguration(); + File f = new File( cacheConfiguration ); + if ( !f.isAbsolute() ) { + f = metadata.getLocation().resolveToFile( cacheConfiguration ); + } + return f.toURI().toURL(); + } + } diff --git a/pom.xml b/pom.xml index 4853360452..862d398c61 100644 --- a/pom.xml +++ b/pom.xml @@ -1047,15 +1047,9 @@ 1.0-deegreeversion - net.sf.ehcache - ehcache-core - 2.6.11 - - - org.slf4j - slf4j-api - - + org.ehcache + ehcache + 3.10.8 org.apache.derby