Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/BedQualityAccess.java @ 5779:ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
XML DOM is not thread safe. Therefore the old implementation only allowed one thread
to use the builder at a time. As the complexity of the configuration
has increased over time this has become a bottleneck of the whole application
because it took quiet some time to build a result. Furthermore the builder code path
is visited very frequent. So many concurrent requests were piled up
resulting in long waits for the users.
To mitigate this problem a round robin pool of builders is used now.
Each of the pooled builders has an independent copy of the XML template
and can be run in parallel.
The number of builders is determined by the system property
'flys.datacage.pool.size'. It defaults to 4.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Sun, 21 Apr 2013 12:48:09 +0200 |
parents | 37112235a946 |
children |
line wrap: on
line source
package de.intevation.flys.artifacts.access; import java.util.Date; import java.util.LinkedList; import java.util.List; import org.apache.log4j.Logger; import de.intevation.artifacts.CallContext; import de.intevation.flys.artifacts.FLYSArtifact; import de.intevation.flys.artifacts.model.DateRange; /** Access data of artifact used in BedQuality calculations. */ public class BedQualityAccess extends RangeAccess { private static final Logger logger = Logger .getLogger(BedQualityAccess.class); private List<String> bedDiameter; private List<String> bedloadDiameter; private List<DateRange> ranges; public BedQualityAccess(FLYSArtifact artifact, CallContext context) { super(artifact, context); } public List<DateRange> getDateRanges() { if (ranges == null) { ranges = extractRanges(getString("periods")); } return ranges; } public List<String> getBedDiameter() { String value = getString("bed_diameter"); if (bedDiameter == null && value != null) { bedDiameter = extractDiameter(value); } return bedDiameter; } public List<String> getBedloadDiameter() { String value = getString("load_diameter"); if (bedloadDiameter == null && value != null) { bedloadDiameter = extractDiameter(value); } return bedloadDiameter; } private List<DateRange> extractRanges(String dateString) { List<DateRange> list = new LinkedList<DateRange>(); String[] dates = dateString.split(";"); for (String s : dates) { String[] pair = s.split(","); try { long l1 = Long.parseLong(pair[0]); long l2 = Long.parseLong(pair[1]); Date first = new Date(l1); Date second = new Date(l2); DateRange dr = new DateRange(first, second); list.add(dr); } catch (NumberFormatException nfe) { continue; } } return list; } private List<String> extractDiameter(String value) { List<String> result = new LinkedList<String>(); String[] diameter = value.split(";"); for (String v : diameter) { logger.debug("diameter: " + v); String[] parts = v.split("\\."); result.add(parts[parts.length - 1]); logger.debug(parts[parts.length-1]); } return result; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :