Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade of ehcache to version 3.10.8 #1441

Merged
merged 6 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions deegree-core/deegree-core-coverage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
<dependency>
<groupId>com.sun.media</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,25 @@
----------------------------------------------------------------------------*/
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.CacheConfigurationBuilder;
import org.ehcache.config.builders.CacheManagerBuilder;
import org.ehcache.config.builders.ResourcePoolsBuilder;
import org.ehcache.config.units.MemoryUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.UUID;

/**
* This class implements a cached RasterDataContainer.
*
*
* @author <a href="mailto:tonnhofer@lat-lon.de">Oliver Tonnhofer</a>
* @author last edited by: $Author$
*
* @version $Revision$, $Date$
*/
public class CachedRasterDataContainer implements RasterDataContainer, RasterDataContainerProvider {
Expand All @@ -63,17 +64,25 @@ public class CachedRasterDataContainer implements RasterDataContainer, RasterDat

private String identifier;

private static Cache cache;
private static Cache<String, RasterData> cache;

private final static String CACHENAME = "CachedRasterDataContainer";

private static final StatisticsRetrieval statsRetrievalService = new StatisticsRetrieval();

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().using(
statsRetrievalService ).build();
cacheManager.init();
cache = cacheManager.createCache( CACHENAME, CacheConfigurationBuilder.newCacheConfigurationBuilder(
String.class,
RasterData.class,
ResourcePoolsBuilder.newResourcePoolsBuilder().offheap(
1,
MemoryUnit.GB ) ) );
} catch ( Throwable e ) {
LOG.error( e.getLocalizedMessage(), e );
}
Expand All @@ -89,9 +98,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 );
Expand All @@ -106,25 +115,24 @@ 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() );
long occupiedByteSize = statsRetrievalService.getStatisticsService().getCacheStatistics(
CACHENAME ).getTierStatistics().get( "OffHeap" ).getOccupiedByteSize();
LOG.debug( "cache miss: " + this + " #mem: " + occupiedByteSize );
}
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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//$HeadURL$
/*----------------------------------------------------------------------------
This file is part of deegree, http://deegree.org/
Copyright (C) 2001-2022 by:
Department of Geography, University of Bonn
and
lat/lon GmbH

This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option)
any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Contact information:

lat/lon GmbH
Aennchenstr. 19, 53177 Bonn
Germany
http://lat-lon.de/

Department of Geography, University of Bonn
Prof. Dr. Klaus Greve
Postfach 1147, 53001 Bonn
Germany
http://www.geographie.uni-bonn.de/deegree/

e-mail: info@deegree.org
----------------------------------------------------------------------------*/
package org.deegree.coverage.raster.data.container;

import org.ehcache.core.spi.service.StatisticsService;
import org.ehcache.spi.service.Service;
import org.ehcache.spi.service.ServiceProvider;

import static java.util.Objects.requireNonNull;

public class StatisticsRetrieval implements Service {

private StatisticsService statisticsService;

@Override
public void start( ServiceProvider<Service> serviceProvider ) {
this.statisticsService = serviceProvider.getService( StatisticsService.class );
}

@Override
public void stop() {
this.statisticsService = null;
}

public StatisticsService getStatisticsService() {
return requireNonNull( statisticsService );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
</dependencies>
</project>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="mailto:schmitz@occamlabs.de">Andreas Schmitz</a>
* @author <a href="mailto:schneider@occamlabs.de">Markus Schneider</a>
* @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 {
Expand All @@ -75,21 +71,21 @@ public class CachedTile implements Tile {

private final Tile tile;

private final Cache cache;
private final Cache<String, byte[]> cache;

private final String key;

private byte[] data;

public CachedTile( Tile tile, Cache cache, String key ) {
public CachedTile( Tile tile, Cache<String, byte[]> cache, String key ) {
this.tile = tile;
this.cache = cache;
this.key = key;
}

@Override
public BufferedImage getAsImage()
throws TileIOException {
throws TileIOException {
try {
return ImageIO.read( new ByteArrayInputStream( getData() ) );
} catch ( IOException e ) {
Expand All @@ -111,28 +107,27 @@ 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 ) {
data = new byte[] {};
} 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,30 @@ 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;

/**
* <code>CachingTileMatrix</code>
*
*
* @author <a href="mailto:schmitz@occamlabs.de">Andreas Schmitz</a>
* @author last edited by: $Author: mschneider $
*
* @version $Revision: 31882 $, $Date: 2011-09-15 02:05:04 +0200 (Thu, 15 Sep 2011) $
*/

public class CachingTileMatrix implements TileDataLevel {

private final TileDataLevel tileMatrix;

private final Cache cache;
private final Cache<String, byte[]> cache;

private final String identifier;

public CachingTileMatrix( TileDataLevel tileMatrix, Cache cache ) {
public CachingTileMatrix( TileDataLevel tileMatrix, Cache<String, byte[]> cache ) {
this.tileMatrix = tileMatrix;
this.cache = cache;
this.identifier = tileMatrix.getMetadata().getIdentifier();
Expand All @@ -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;
Expand Down
Loading