annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/FastCrossSectionLineFactory.java @ 5863:4897a58c8746

River artifacts: Added new copyright headers.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sun, 28 Apr 2013 14:40:59 +0200
parents 5aa05a7a34b7
children af13ceeba52a
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
6 * documentation coming with Dive4Elements River for details.
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2126
diff changeset
9 package org.dive4elements.river.artifacts.model;
2119
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2126
diff changeset
11 import org.dive4elements.river.artifacts.cache.CacheFactory;
2119
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2126
diff changeset
13 import org.dive4elements.river.model.CrossSection;
2126
d626ae185305 Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2119
diff changeset
14
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2126
diff changeset
15 import org.dive4elements.river.model.FastCrossSectionLine;
2119
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 import net.sf.ehcache.Cache;
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 import net.sf.ehcache.Element;
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 import java.util.List;
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21
2126
d626ae185305 Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2119
diff changeset
22 import org.apache.log4j.Logger;
2119
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 public class FastCrossSectionLineFactory
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 {
2126
d626ae185305 Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2119
diff changeset
26 private static Logger log =
d626ae185305 Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2119
diff changeset
27 Logger.getLogger(FastCrossSectionLineFactory.class);
d626ae185305 Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2119
diff changeset
28
2119
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 public static final String CACHE_NAME = "fast-cross-section-lines";
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 private FastCrossSectionLineFactory() {
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 }
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 public static FastCrossSectionLine getCrossSectionLine(
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 CrossSection cs,
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 double km
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 ) {
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 Cache cache = CacheFactory.getCache(CACHE_NAME);
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39
2126
d626ae185305 Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2119
diff changeset
40 boolean debug = log.isDebugEnabled();
d626ae185305 Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2119
diff changeset
41
2119
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 if (cache == null) {
2126
d626ae185305 Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2119
diff changeset
43 if (debug) {
d626ae185305 Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2119
diff changeset
44 log.debug("No cross section chunk cache configured.");
d626ae185305 Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2119
diff changeset
45 }
d626ae185305 Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2119
diff changeset
46 List<FastCrossSectionLine> lines = cs.getFastLines(km, km);
d626ae185305 Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2119
diff changeset
47 return lines.isEmpty() ? null : lines.get(0);
2119
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 }
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 String cacheKey = FastCrossSectionChunk.createHashKey(cs, km);
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 Element element = cache.get(cacheKey);
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 FastCrossSectionChunk fcsc;
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 if (element != null) {
2126
d626ae185305 Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2119
diff changeset
57 if (debug) {
d626ae185305 Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2119
diff changeset
58 log.debug("Found cross section chunk in cache id: " +
d626ae185305 Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2119
diff changeset
59 cs.getId() + " km: " + km);
d626ae185305 Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2119
diff changeset
60 }
d626ae185305 Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2119
diff changeset
61
2119
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 fcsc = (FastCrossSectionChunk)element.getValue();
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 }
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 else {
2126
d626ae185305 Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2119
diff changeset
65 if (debug) {
d626ae185305 Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2119
diff changeset
66 log.debug("Not found cross section chunk in cache id: " +
d626ae185305 Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2119
diff changeset
67 cs.getId() + " km: " + km + " -> loading");
d626ae185305 Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2119
diff changeset
68 }
2119
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69 fcsc = new FastCrossSectionChunk(cs, km);
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70 element = new Element(cacheKey, fcsc);
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71 cache.put(element);
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72 }
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74 return fcsc.getCrossSectionLine(km);
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 }
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76 }
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org