diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java @ 697:b972eba2ed8a facets-slt

Removed ComputeCallback because this was thought too complicated. Fixed issue with facets not be re-generated if same state is entered again. flys-artifacts/branches/facets-slt@2143 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 17 Jun 2011 10:40:54 +0000
parents 708b270dfd30
children dae37cbe4ae2
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Fri Jun 17 09:19:43 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Fri Jun 17 10:40:54 2011 +0000
@@ -46,13 +46,12 @@
 
 import de.intevation.flys.artifacts.cache.CacheFactory;
 
-import de.intevation.flys.artifacts.model.ComputeCallback;
-import de.intevation.flys.artifacts.model.ComputeCallback.ComputeType;
 import de.intevation.flys.artifacts.model.DischargeTables;
 import de.intevation.flys.artifacts.model.RiverFactory;
 import de.intevation.flys.artifacts.model.Segment;
 
 import de.intevation.flys.artifacts.states.DefaultState;
+import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
 import de.intevation.flys.artifacts.states.LocationDistanceSelect;
 
 
@@ -1092,62 +1091,62 @@
 
         logger.debug("Create ComputeCallback for state: " + current.getID());
 
-        ComputeCallback callback = current.createComputeCallback(hash(), this);
-
-        if (callback == null) {
-            logger.info("There is no data which needs to be computed.");
-            return null;
-        }
-
-        return compute(context, hash, callback, type);
+        return compute(context, hash, current, type);
     }
 
 
     public Object compute(
-        CallContext     context,
-        String          key,
-        ComputeCallback callback,
-        ComputeType     type)
-    {
-        String stateId = getCurrentStateId();
-        List<Facet> fs = facets.get(stateId);
-        if (fs == null) {
-            fs = new ArrayList<Facet>();
-            facets.put(stateId, fs);
-        }
+        CallContext   context,
+        String        key,
+        DefaultState  state,
+        ComputeType   type
+    ) {
+        String stateID = state.getID();
 
-        Cache cache = CacheFactory.getCache(COMPUTING_CACHE);
-        if (cache == null) {
+        List<Facet> fs = new ArrayList<Facet>();
+
+        try {
+            Cache cache = CacheFactory.getCache(COMPUTING_CACHE);
+
+            Object old = null;
+
+            if (cache != null) {
+                net.sf.ehcache.Element element = cache.get(key);
+                if (element != null) {
+                    logger.debug("Got computation result from cache.");
+                    old = element.getValue();
+                }
+            }
+
+            Object res;
             switch (type) {
                 case FEED:
-                    return callback.computeFeed(context, fs);
+                    res = state.computeFeed(this, key, context, fs, old);
+                    break;
+                case ADVANCE:
+                    res = state.computeFeed(this, key, context, fs, old);
+                    break;
+                default:
+                    res = null;
+            }
 
-                case ADVANCE:
-                    return callback.computeAdvance(context, fs);
+            if (cache != null && old != res && res != null) {
+                logger.debug("Store computation result to cache.");
+                net.sf.ehcache.Element element =
+                    new net.sf.ehcache.Element(key, res);
+                cache.put(element);
+            }
+
+            return res;
+        }
+        finally {
+            if (fs.isEmpty()) {
+                facets.remove(stateID);
+            }
+            else {
+                facets.put(stateID, fs);
             }
         }
-
-        net.sf.ehcache.Element element = cache.get(key);
-        if (element != null) {
-            logger.debug("Got computation values from cache.");
-            return element.getValue();
-        }
-
-        Object result = null;
-        switch (type) {
-            case FEED:
-                result = callback.computeFeed(context, fs);
-                break;
-
-            case ADVANCE:
-                result = callback.computeAdvance(context, fs);
-        }
-
-        if (result != null) {
-            cache.put(new net.sf.ehcache.Element(key, result));
-        }
-
-        return result;
     }
 
 

http://dive4elements.wald.intevation.org