view flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticMorphWidthArtifact.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 4a1bd43e7aa6
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.artifactdatabase.state.DefaultOutput;
import de.intevation.artifactdatabase.state.Facet;
import de.intevation.artifactdatabase.state.FacetActivity;
import de.intevation.artifacts.ArtifactFactory;
import de.intevation.artifacts.Artifact;
import de.intevation.artifacts.CallMeta;
import de.intevation.artifacts.common.utils.XMLUtils;
import de.intevation.flys.artifacts.model.minfo.MorphologicWidthFacet;
import de.intevation.flys.artifacts.resources.Resources;
import de.intevation.flys.artifacts.states.StaticState;

public class StaticMorphWidthArtifact
extends      AbstractStaticStateArtifact
{
    /** The logger for this class. */
    private static Logger logger =
        Logger.getLogger(StaticMorphWidthArtifact.class);

    private static final String NAME = "morph-width";
    private static final String STATIC_FACET_NAME = "morph-width";

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

    public static final String STATIC_STATE_NAME =
        "state.morph-width.static";

    /**
     * Trivial Constructor.
     */
    public StaticMorphWidthArtifact() {
    }

    @Override
    public String getName() {
        return NAME;
    }

    /**
     * Gets called from factory, to set things up.
     */
    @Override
    public void setup(
        String          identifier,
        ArtifactFactory factory,
        Object          context,
        CallMeta        callMeta,
        Document        data)
    {
        logger.debug("setup");

        if (logger.isDebugEnabled()) {
            logger.debug(XMLUtils.toString(data));
        }

        String code = getDatacageIDValue(data);

        if (code != null) {
                Facet facet = new MorphologicWidthFacet(
                        STATIC_FACET_NAME,
                        Resources.getMsg(
                            callMeta,
                            "facet.morphologic.width",
                            "morphologische Breite"));
                addStringData("width_id", code);
                ArrayList<Facet> facets = new ArrayList<Facet>(1);
                facets.add(facet);

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

    @Override
    protected void initStaticState() {

        logger.debug("initStaticState " + getName() + " " + identifier());

        StaticState state = new StaticState(STATIC_STATE_NAME);
        DefaultOutput output = new DefaultOutput(
                "general",
                "general",
                "image/png",
                "chart");

        List<Facet> facets = getFacets(STATIC_STATE_NAME);
        output.addFacets(facets);
        state.addOutput(output);

        setStaticState(state);
    }

    @Override
    protected void initialize(Artifact artifact, Object context, CallMeta meta) {
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org