Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FastCrossSectionLineFactory.java @ 2126:d626ae185305
Use the fast cross section lines from backend now.
flys-artifacts/trunk@3697 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 17 Jan 2012 17:05:18 +0000 |
parents | dc28ea60b53d |
children |
comparison
equal
deleted
inserted
replaced
2125:7a8f52267a5c | 2126:d626ae185305 |
---|---|
1 package de.intevation.flys.artifacts.model; | 1 package de.intevation.flys.artifacts.model; |
2 | 2 |
3 import de.intevation.flys.artifacts.cache.CacheFactory; | 3 import de.intevation.flys.artifacts.cache.CacheFactory; |
4 | 4 |
5 import de.intevation.flys.model.CrossSection; | 5 import de.intevation.flys.model.CrossSection; |
6 import de.intevation.flys.model.CrossSectionLine; | 6 |
7 import de.intevation.flys.model.FastCrossSectionLine; | |
7 | 8 |
8 import net.sf.ehcache.Cache; | 9 import net.sf.ehcache.Cache; |
9 import net.sf.ehcache.Element; | 10 import net.sf.ehcache.Element; |
10 | 11 |
11 import java.util.List; | 12 import java.util.List; |
12 | 13 |
14 import org.apache.log4j.Logger; | |
13 | 15 |
14 public class FastCrossSectionLineFactory | 16 public class FastCrossSectionLineFactory |
15 { | 17 { |
18 private static Logger log = | |
19 Logger.getLogger(FastCrossSectionLineFactory.class); | |
20 | |
16 public static final String CACHE_NAME = "fast-cross-section-lines"; | 21 public static final String CACHE_NAME = "fast-cross-section-lines"; |
17 | 22 |
18 private FastCrossSectionLineFactory() { | 23 private FastCrossSectionLineFactory() { |
19 } | 24 } |
20 | 25 |
22 CrossSection cs, | 27 CrossSection cs, |
23 double km | 28 double km |
24 ) { | 29 ) { |
25 Cache cache = CacheFactory.getCache(CACHE_NAME); | 30 Cache cache = CacheFactory.getCache(CACHE_NAME); |
26 | 31 |
32 boolean debug = log.isDebugEnabled(); | |
33 | |
27 if (cache == null) { | 34 if (cache == null) { |
28 List<CrossSectionLine> lines = cs.getLines(km, km); | 35 if (debug) { |
29 return lines.isEmpty() | 36 log.debug("No cross section chunk cache configured."); |
30 ? null | 37 } |
31 : new FastCrossSectionLine(lines.get(0)); | 38 List<FastCrossSectionLine> lines = cs.getFastLines(km, km); |
39 return lines.isEmpty() ? null : lines.get(0); | |
32 } | 40 } |
33 | 41 |
34 String cacheKey = FastCrossSectionChunk.createHashKey(cs, km); | 42 String cacheKey = FastCrossSectionChunk.createHashKey(cs, km); |
35 | 43 |
36 Element element = cache.get(cacheKey); | 44 Element element = cache.get(cacheKey); |
37 | 45 |
38 FastCrossSectionChunk fcsc; | 46 FastCrossSectionChunk fcsc; |
39 | 47 |
40 if (element != null) { | 48 if (element != null) { |
49 if (debug) { | |
50 log.debug("Found cross section chunk in cache id: " + | |
51 cs.getId() + " km: " + km); | |
52 } | |
53 | |
41 fcsc = (FastCrossSectionChunk)element.getValue(); | 54 fcsc = (FastCrossSectionChunk)element.getValue(); |
42 } | 55 } |
43 else { | 56 else { |
57 if (debug) { | |
58 log.debug("Not found cross section chunk in cache id: " + | |
59 cs.getId() + " km: " + km + " -> loading"); | |
60 } | |
44 fcsc = new FastCrossSectionChunk(cs, km); | 61 fcsc = new FastCrossSectionChunk(cs, km); |
45 element = new Element(cacheKey, fcsc); | 62 element = new Element(cacheKey, fcsc); |
46 cache.put(element); | 63 cache.put(element); |
47 } | 64 } |
48 | 65 |