comparison 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
comparison
equal deleted inserted replaced
696:708b270dfd30 697:b972eba2ed8a
44 44
45 import de.intevation.flys.artifacts.context.FLYSContext; 45 import de.intevation.flys.artifacts.context.FLYSContext;
46 46
47 import de.intevation.flys.artifacts.cache.CacheFactory; 47 import de.intevation.flys.artifacts.cache.CacheFactory;
48 48
49 import de.intevation.flys.artifacts.model.ComputeCallback;
50 import de.intevation.flys.artifacts.model.ComputeCallback.ComputeType;
51 import de.intevation.flys.artifacts.model.DischargeTables; 49 import de.intevation.flys.artifacts.model.DischargeTables;
52 import de.intevation.flys.artifacts.model.RiverFactory; 50 import de.intevation.flys.artifacts.model.RiverFactory;
53 import de.intevation.flys.artifacts.model.Segment; 51 import de.intevation.flys.artifacts.model.Segment;
54 52
55 import de.intevation.flys.artifacts.states.DefaultState; 53 import de.intevation.flys.artifacts.states.DefaultState;
54 import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
56 import de.intevation.flys.artifacts.states.LocationDistanceSelect; 55 import de.intevation.flys.artifacts.states.LocationDistanceSelect;
57 56
58 57
59 /** 58 /**
60 * The defaul FLYS artifact. 59 * The defaul FLYS artifact.
1090 public Object compute(CallContext context, String hash, ComputeType type) { 1089 public Object compute(CallContext context, String hash, ComputeType type) {
1091 DefaultState current = (DefaultState) getCurrentState(context); 1090 DefaultState current = (DefaultState) getCurrentState(context);
1092 1091
1093 logger.debug("Create ComputeCallback for state: " + current.getID()); 1092 logger.debug("Create ComputeCallback for state: " + current.getID());
1094 1093
1095 ComputeCallback callback = current.createComputeCallback(hash(), this); 1094 return compute(context, hash, current, type);
1096
1097 if (callback == null) {
1098 logger.info("There is no data which needs to be computed.");
1099 return null;
1100 }
1101
1102 return compute(context, hash, callback, type);
1103 } 1095 }
1104 1096
1105 1097
1106 public Object compute( 1098 public Object compute(
1107 CallContext context, 1099 CallContext context,
1108 String key, 1100 String key,
1109 ComputeCallback callback, 1101 DefaultState state,
1110 ComputeType type) 1102 ComputeType type
1111 { 1103 ) {
1112 String stateId = getCurrentStateId(); 1104 String stateID = state.getID();
1113 List<Facet> fs = facets.get(stateId); 1105
1114 if (fs == null) { 1106 List<Facet> fs = new ArrayList<Facet>();
1115 fs = new ArrayList<Facet>(); 1107
1116 facets.put(stateId, fs); 1108 try {
1117 } 1109 Cache cache = CacheFactory.getCache(COMPUTING_CACHE);
1118 1110
1119 Cache cache = CacheFactory.getCache(COMPUTING_CACHE); 1111 Object old = null;
1120 if (cache == null) { 1112
1113 if (cache != null) {
1114 net.sf.ehcache.Element element = cache.get(key);
1115 if (element != null) {
1116 logger.debug("Got computation result from cache.");
1117 old = element.getValue();
1118 }
1119 }
1120
1121 Object res;
1121 switch (type) { 1122 switch (type) {
1122 case FEED: 1123 case FEED:
1123 return callback.computeFeed(context, fs); 1124 res = state.computeFeed(this, key, context, fs, old);
1124 1125 break;
1125 case ADVANCE: 1126 case ADVANCE:
1126 return callback.computeAdvance(context, fs); 1127 res = state.computeFeed(this, key, context, fs, old);
1127 } 1128 break;
1128 } 1129 default:
1129 1130 res = null;
1130 net.sf.ehcache.Element element = cache.get(key); 1131 }
1131 if (element != null) { 1132
1132 logger.debug("Got computation values from cache."); 1133 if (cache != null && old != res && res != null) {
1133 return element.getValue(); 1134 logger.debug("Store computation result to cache.");
1134 } 1135 net.sf.ehcache.Element element =
1135 1136 new net.sf.ehcache.Element(key, res);
1136 Object result = null; 1137 cache.put(element);
1137 switch (type) { 1138 }
1138 case FEED: 1139
1139 result = callback.computeFeed(context, fs); 1140 return res;
1140 break; 1141 }
1141 1142 finally {
1142 case ADVANCE: 1143 if (fs.isEmpty()) {
1143 result = callback.computeAdvance(context, fs); 1144 facets.remove(stateID);
1144 } 1145 }
1145 1146 else {
1146 if (result != null) { 1147 facets.put(stateID, fs);
1147 cache.put(new net.sf.ehcache.Element(key, result)); 1148 }
1148 } 1149 }
1149
1150 return result;
1151 } 1150 }
1152 1151
1153 1152
1154 /** 1153 /**
1155 * Method to dump the artifacts state/data. 1154 * Method to dump the artifacts state/data.

http://dive4elements.wald.intevation.org