changeset 1060:cc4ec127d666

Remove the elements of an outdated state from cache if its endOfLife method is called. gnv-artifacts/trunk@1143 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 01 Jun 2010 16:54:21 +0000
parents 174f6eacd595
children 13bea93a070a
files gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputStateBase.java gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshCrossOutputState.java gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesVectorOutputState.java
diffstat 7 files changed, 39 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Mon May 31 08:20:17 2010 +0000
+++ b/gnv-artifacts/ChangeLog	Tue Jun 01 16:54:21 2010 +0000
@@ -1,3 +1,20 @@
+2010-06-01  Ingo Weinzierl <ingo.weinzierl@intevation.de>
+
+	* src/main/java/de/intevation/gnv/state/StateBase.java: Remove existing
+	  elements from cache that belong to an outdated state if its enfOfLife(.)
+	  is called. It was necessary to adapt the signature of getHash(.) for this
+	  - removed the parameter uuid - because endOfLife is called without any
+	  information about the current uuid. The uuid has not been used in
+	  getHash() anyway.
+
+	* src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesVectorOutputState.java,
+	  src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java,
+	  src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java,
+	  src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshCrossOutputState.java,
+	  src/main/java/de/intevation/gnv/state/OutputStateBase.java: Adapted the
+	  signature of getHash() regarding the changes in the implementing class
+	  StateBase.
+
 2010-05-31  Tim Englich  <tim.englich@intevation.de>
 
 	* doc/conf/queries.properties: 
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputStateBase.java	Mon May 31 08:20:17 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputStateBase.java	Tue Jun 01 16:54:21 2010 +0000
@@ -209,7 +209,7 @@
             // we use a cache
             log.info("Using cache.");
             Cache cache = factory.getCache();
-            String key  = "chart_" + getHash(uuid);
+            String key  = "chart_" + getHash();
 
             net.sf.ehcache.Element value = cache.get(key);
             if (value != null) {
@@ -242,7 +242,7 @@
         log.debug("Fetch chart [" + uuid + "] from cache");
         CacheFactory cacheFactory = CacheFactory.getInstance();
         if (cacheFactory.isInitialized()) {
-            String key = "chart_" + getHash(uuid);
+            String key = "chart_" + getHash();
             net.sf.ehcache.Element object = cacheFactory.getCache().get(key);
 
             if (object != null) {
@@ -302,7 +302,7 @@
     protected void removeChartResult(String uuid) {
         log.debug("OutputStateBase.getChartResult");
         if (CacheFactory.getInstance().isInitialized()) {
-            String key = "chart_" + getHash(uuid);
+            String key = "chart_" + getHash();
             log.debug("Hash for Queryelements: " + key);
             net.sf.ehcache.Element value = CacheFactory.getInstance().getCache().get(key);
             if (value != null) {
@@ -321,7 +321,7 @@
 
         CacheFactory cacheFactory = CacheFactory.getInstance();
         if (cacheFactory.isInitialized()) {
-            String key = "chart_" + getHash(uuid);
+            String key = "chart_" + getHash();
             net.sf.ehcache.Element object = cacheFactory.getCache().get(key);
             if (object != null)
                 cacheFactory.getCache().remove(key);
@@ -335,7 +335,7 @@
         log.debug("Prufify chart [" + uuid + "]");
         CacheFactory cacheFactory = CacheFactory.getInstance();
         if (cacheFactory.isInitialized()) {
-            String key = "chart_" + getHash(uuid);
+            String key = "chart_" + getHash();
             cacheFactory.getCache().put(new net.sf.ehcache.Element(key, chart));
         }
     }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java	Mon May 31 08:20:17 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java	Tue Jun 01 16:54:21 2010 +0000
@@ -959,7 +959,7 @@
     }
 
 
-    protected String getHash(String uuid) {
+    protected String getHash() {
         return this.hash;
     }
 
@@ -969,7 +969,7 @@
         if (factory.isInitialized()) {
             // we use a cache
             Cache cache = factory.getCache();
-            String key  = getHash(uuid);
+            String key  = getHash();
 
             log.debug("Using cache - key: " + key);
 
@@ -1059,6 +1059,17 @@
 
 
     public void endOfLife(Object globalContext) {
+        log.debug("end of life of the current state.");
+
+        CacheFactory factory = CacheFactory.getInstance();
+        if (factory.isInitialized()) {
+            Cache cache = factory.getCache();
+            String key  = getHash();
+
+            if (key != null && cache.remove(key)) {
+                log.info("Removed element from cache - key: " + key);
+            }
+        }
     }
 
 
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshCrossOutputState.java	Mon May 31 08:20:17 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshCrossOutputState.java	Tue Jun 01 16:54:21 2010 +0000
@@ -426,7 +426,7 @@
     protected Object getChartResult(String uuid, CallContext callContext) {
         log.debug("HorizontalProfileMeshCrossOutputState.getChartResult");
 
-        String key = getHash(uuid);
+        String key = getHash();
         if (CacheFactory.getInstance().isInitialized()) {
             log.debug("Using cache - key: " + key);
             net.sf.ehcache.Element value = CacheFactory.getInstance().getCache().get(key);
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java	Mon May 31 08:20:17 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java	Tue Jun 01 16:54:21 2010 +0000
@@ -560,7 +560,7 @@
     throws StateException
     {
         CacheFactory cf  = CacheFactory.getInstance();
-        String       key = getHash(uuid);
+        String       key = getHash();
 
         if (cf.isInitialized()) {
             log.debug("Using cache - key: " + key);
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java	Mon May 31 08:20:17 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java	Tue Jun 01 16:54:21 2010 +0000
@@ -158,7 +158,7 @@
     @Override
     protected Object getChartResult(String uuid, CallContext callContext) {
         log.debug("VerticalCrossSectionOutputState.getChartResult");
-        String key = getHash(uuid);
+        String key = getHash();
 
         CacheFactory factory = CacheFactory.getInstance();
         if (factory.isInitialized()) {
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesVectorOutputState.java	Mon May 31 08:20:17 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesVectorOutputState.java	Tue Jun 01 16:54:21 2010 +0000
@@ -97,7 +97,7 @@
             // we use a cache
             logger.info("Using cache.");
             Cache cache = factory.getCache();
-            String key  = "chart_" + getHash(uuid);
+            String key  = "chart_" + getHash();
 
             net.sf.ehcache.Element value = cache.get(key);
             if (value != null) {

http://dive4elements.wald.intevation.org