Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/Access.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 | cbd0fafcb26b |
children |
line wrap: on
line source
package de.intevation.flys.artifacts.access; import de.intevation.artifactdatabase.data.StateData; import de.intevation.flys.artifacts.FLYSArtifact; import de.intevation.flys.artifacts.model.DateRange; import de.intevation.flys.utils.FLYSUtils; import gnu.trove.TDoubleArrayList; import gnu.trove.TLongArrayList; import java.util.ArrayList; import java.util.Date; import org.apache.log4j.Logger; public class Access { private static Logger log = Logger.getLogger(Access.class); protected FLYSArtifact artifact; public Access() { } public Access(FLYSArtifact artifact) { this.artifact = artifact; } public FLYSArtifact getArtifact() { return artifact; } public void setArtifact(FLYSArtifact artifact) { this.artifact = artifact; } /** Get a data entry as string. */ protected String getString(String key) { StateData sd = artifact.getData(key); if (sd == null) { log.warn("missing '" + key + "' value"); return null; } return (String)sd.getValue(); } /** Get a data entry as double, returns null if string not double valueoffable. */ protected Double getDouble(String key) { StateData sd = artifact.getData(key); if (sd == null) { log.warn("missing '" + key + "' value"); return null; } try { return Double.valueOf((String)sd.getValue()); } catch (NumberFormatException nfe) { log.warn(key + " '" + sd.getValue() + "' is not numeric."); } return null; } protected Long getLong(String key) { StateData sd = artifact.getData(key); if (sd == null) { log.warn("missing '" + key + "' value"); return null; } try { return Long.valueOf((String)sd.getValue()); } catch (NumberFormatException nfe) { log.warn(key + " '" + sd.getValue() + "' is not a long integer."); } return null; } protected Integer getInteger(String key) { StateData sd = artifact.getData(key); if (sd == null) { log.warn("missing '" + key + "' value"); return null; } try { return Integer.valueOf((String)sd.getValue()); } catch (NumberFormatException nfe) { log.warn(key + " '" + sd.getValue() + "' is not a integer."); } return null; } protected int [] getIntArray(String key) { StateData sd = artifact.getData(key); if (sd == null) { log.warn("missing '" + key +"' value"); return null; } return FLYSUtils.intArrayFromString((String)sd.getValue()); } protected DateRange [] getDateRange(String key) { StateData sd = artifact.getData(key); if (sd == null) { log.warn("missing '" + key + "'"); return null; } String data = (String)sd.getValue(); String[] pairs = data.split("\\s*;\\s*"); ArrayList<DateRange> aPs = new ArrayList<DateRange>(pairs.length); for (int i = 0; i < pairs.length; i++) { String[] fromTo = pairs[i].split("\\s*,\\s*"); if (fromTo.length >= 2) { try { Date from = new Date(Long.parseLong(fromTo[0])); Date to = new Date(Long.parseLong(fromTo[1])); DateRange aP = new DateRange(from, to); if (!aPs.contains(aP)) { aPs.add(aP); } } catch (NumberFormatException nfe) { log.warn(key + " contains no long values.", nfe); } } } DateRange [] result = aPs.toArray(new DateRange[aPs.size()]); if (log.isDebugEnabled()) { for (int i = 0; i < result.length; ++i) { DateRange ap = result[i]; log.debug("period " + ap.getFrom() + " - " + ap.getTo()); } } return result; } protected Boolean getBoolean(String key) { StateData sd = artifact.getData(key); if (sd == null) { log.warn("missing '" + key + "' value"); return null; } return Boolean.valueOf((String)sd.getValue()); } protected double [] getDoubleArray(String key) { StateData sd = artifact.getData(key); if (sd == null) { log.warn("missing '" + key + "'"); return null; } String [] parts = ((String)sd.getValue()).split("[\\s;]+"); TDoubleArrayList list = new TDoubleArrayList(parts.length); for (String part: parts) { try { list.add(Double.parseDouble(part)); } catch (NumberFormatException nfe) { log.warn("'" + part + "' is not numeric."); } } return list.toNativeArray(); } protected long [] getLongArray(String key) { StateData sd = artifact.getData(key); if (sd == null) { log.warn("missing '" + key + "'"); return null; } String [] parts = ((String)sd.getValue()).split("[\\s;]+"); TLongArrayList list = new TLongArrayList(parts.length); for (String part: parts) { try { list.add(Long.parseLong(part)); } catch (NumberFormatException nfe) { log.warn("'" + part + "' is not numeric."); } } return list.toNativeArray(); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :