view flys-artifacts/src/main/java/de/intevation/flys/artifacts/HYKArtifact.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 a2735a4bf75e
children
line wrap: on
line source
package de.intevation.flys.artifacts;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import org.w3c.dom.Document;

import de.intevation.artifacts.Artifact;
import de.intevation.artifacts.ArtifactFactory;
import de.intevation.artifacts.CallMeta;


import de.intevation.flys.artifacts.states.DefaultState;

import de.intevation.artifactdatabase.state.Facet;
import de.intevation.artifactdatabase.state.FacetActivity;


/**
 * Artifact to get hydr zones (HYKs).
 */
public class HYKArtifact extends StaticFLYSArtifact {

    /** Name of Artifact. */
    public static final String HYK_ARTIFACT_NAME = "hyk";

    /** Name of data item keeping the hyk id to load formations from. */
    public static final String HYK_ID = "hyk_artifact.data.id";

    /** Name of data item keeping the km of cs master. */
    public static final String HYK_KM = "hyk_artifact.data.km";

    /** Own logger. */
    private static final Logger logger =
        Logger.getLogger(HYKArtifact.class);

    static {
        // TODO: Move to configuration.
        FacetActivity.Registry.getInstance()
            .register(HYK_ARTIFACT_NAME, FacetActivity.INACTIVE);
    }

    /** Return given name. */
    @Override
    public String getName() {
        return HYK_ARTIFACT_NAME;
    }


    /** Store ids, do super.setup. */
    @Override
    public void setup(
        String          identifier,
        ArtifactFactory factory,
        Object          context,
        CallMeta        callMeta,
        Document        data)
    {
        logger.info("HYKArtifact.setup");

        String ids = getDatacageIDValue(data);

        logger.info("HYKArtifact.setup: id is " + ids);

        addStringData(HYK_ID, ids);

        super.setup(identifier, factory, context, callMeta, data);
    }


    /** Set km as Data. */
    public void setKm(double km) {
        addStringData(HYK_KM, Double.toString(km));
    }


    /** Get km from state data. */
    public double getKm() {
        Double km = getDataAsDouble(HYK_KM);
        if (km == null) {
            // XXX returning 0 is to be compatible to older versions that had an
            // own method getDataAsDouble that returned 0 if parsing the
            // parameter failed.
            return 0;
        }
        else {
            return km;
        }
    }


    /** Get hyk-id from state data. */
    public int getHykId() {
        return getDataAsInteger(HYK_ID);
    }


    /** Do not copy data from daddyfact. */
    @Override
    protected void initialize(
        Artifact artifact,
        Object   context,
        CallMeta callMeta)
    {
        logger.debug("HYKArtifact.initialize");
        importData((FLYSArtifact)artifact, "river");

        List<Facet> fs = new ArrayList<Facet>();

        DefaultState state = (DefaultState) getCurrentState(context);
        state.computeInit(this, hash(), context, callMeta, fs);
        if (!fs.isEmpty()) {
            logger.debug("Facets to add in HYKArtifact.initialize .");
            addFacets(getCurrentStateId(), fs);
        }
        else {
            logger.debug("No facets to add in HYKArtifact.initialize ("
                + state.getID() + ").");
        }
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org