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

import java.util.List;

import de.intevation.artifacts.Artifact;
import de.intevation.artifacts.ArtifactCollection;
import de.intevation.artifacts.GlobalContext;
import de.intevation.artifacts.User;

import de.intevation.artifactdatabase.BackendListener;
import de.intevation.artifactdatabase.Backend;

import org.apache.log4j.Logger;

import org.w3c.dom.Document;

/** Triggers Datacage to update db. */
public class DatacageBackendListener
implements   BackendListener
{
    private static Logger log =
        Logger.getLogger(DatacageBackendListener.class);

    protected GlobalContext context;

    public DatacageBackendListener() {
        log.debug("new DatacageBackendListener");
    }

    protected Datacage getDatacage() {
        Object listener = context.get(Datacage.DATACAGE_KEY);
        return listener instanceof Datacage
            ? (Datacage)listener
            : null;
    }

    @Override
    public void setup(GlobalContext context) {
        log.debug("setup");
        this.context = context;
        Datacage l = getDatacage();
        if (l != null) {
            l.setup(context);
        }
    }

    @Override
    public void createdArtifact(Artifact artifact, Backend backend) {
        log.debug("createdArtifact");
        Datacage l = getDatacage();
        if (l != null) {
            l.createdArtifact(artifact, backend, context);
        }
    }

    @Override
    public void storedArtifact(Artifact artifact, Backend backend) {
        log.debug("storedArtifact");
        Datacage l = getDatacage();
        if (l != null) {
            l.storedArtifact(artifact, backend, context);
        }
    }

    @Override
    public void createdUser(User user, Backend backend) {
        log.debug("createdUser");
        Datacage l = getDatacage();
        if (l != null) {
            l.createdUser(user, backend, context);
        }
    }

    @Override
    public void deletedUser(String identifier, Backend backend) {
        log.debug("deletedUser");
        Datacage l = getDatacage();
        if (l != null) {
            l.deletedUser(identifier, backend, context);
        }
    }

    @Override
    public void createdCollection(
        ArtifactCollection collection,
        Backend            backend
    ) {
        log.debug("createdCollection");
        Datacage l = getDatacage();
        if (l != null) {
            l.createdCollection(collection, backend, context);
        }
    }

    @Override
    public void deletedCollection(String identifier, Backend backend) {
        log.debug("deletedCollection");
        Datacage l = getDatacage();
        if (l != null) {
            l.deletedCollection(identifier, backend, context);
        }
    }

    @Override
    public void changedCollectionAttribute(
        String   identifier,
        Document document,
        Backend  backend
    ) {
        log.debug("changedCollectionAttribute");
        Datacage l = getDatacage();
        if (l != null) {
            l.changedCollectionAttribute(
                identifier, document, backend, context);
        }
    }

    @Override
    public void changedCollectionItemAttribute(
        String   collectionId,
        String   artifactId,
        Document document,
        Backend  backend
    ) {
        log.debug("changedCollectionItemAttribute");
        Datacage l = getDatacage();
        if (l != null) {
            l.changedCollectionItemAttribute(
                collectionId, artifactId, document, backend, context);
        }
    }

    @Override
    public void addedArtifactToCollection(
        String  artifactId,
        String  collectionId,
        Backend backend
    ) {
        log.debug("addedArtifactToCollection");
        Datacage l = getDatacage();
        if (l != null) {
            l.addedArtifactToCollection(
                artifactId, collectionId, backend, context);
        }
    }

    @Override
    public void removedArtifactFromCollection(
        String  artifactId,
        String  collectionId,
        Backend backend
    ) {
        log.debug("removedArtifactFromCollection");
        Datacage l = getDatacage();
        if (l != null) {
            l.removedArtifactFromCollection(
                artifactId, collectionId, backend, context);
        }
    }

    @Override
    public void setCollectionName(
        String collectionId,
        String name
    ) {
        log.debug("setCollectionName");
        Datacage l = getDatacage();
        if (l != null) {
            l.setCollectionName(collectionId, name, context);
        }
    }

    @Override
    public void killedCollections(List<String> identifiers, Backend backend) {
        log.debug("killedCollections");
        Datacage l = getDatacage();
        if (l != null) {
            l.killedCollections(identifiers, context);
        }
    }

    @Override
    public void killedArtifacts(List<String> identifiers, Backend backend) {
        log.debug("killedArtifacts");
        Datacage l = getDatacage();
        if (l != null) {
            l.killedArtifacts(identifiers, context);
        }
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org