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

import java.util.List;

import org.apache.log4j.Logger;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;

import de.intevation.flys.model.Building;
import de.intevation.flys.model.CrossSectionTrack;
import de.intevation.flys.model.Fixpoint;
import de.intevation.flys.model.River;
import de.intevation.flys.model.RiverAxis;
import de.intevation.flys.model.HWSLine;


public class SpatialInfo {

    private static Logger logger = Logger.getLogger(SpatialInfo.class);

    protected static String RIVERNAME = System.getProperty(
        "flys.backend.spatial.river", "Saar");

    protected Session session;


    public static void main(String[] args) {
        logger.info("Start SpatialInfo application.");

        SpatialInfo spatial = null;

        try {
            spatial = new SpatialInfo();

            River river = spatial.getRiver(RIVERNAME);
            if (river == null) {
                logger.warn("Could not find river '" + RIVERNAME + "'!");
                return;
            }

            logger.info("Spatial information of River '" + RIVERNAME + "'");
            spatial.doRiverAxisInfo(river);
            spatial.doCrossSectionTracksInfo(river);
            spatial.doBuildingsInfo(river);
            spatial.doFixpointsInfo(river);
        }
        finally {
            if (spatial != null) {
                spatial.close();
            }
        }

        logger.info("Finish SpatialInfo application.");
    }


    public SpatialInfo() {
        session = SessionFactoryProvider
            .createSessionFactory()
            .openSession();
    }


    public void close() {
        session.close();
    }


    protected River getRiver(String rivername) {
        Query query = session.createQuery(
            "from River where name =:name");
        query.setParameter("name", rivername);

        List<River> list = query.list();

        if (list == null || list.size() == 0) {
            logger.warn("No river '" + rivername + "' found!");
            return null;
        }

        return list.get(0);
    }


    protected void doRiverAxisInfo(River river) {
        try {
            List<RiverAxis> axis = RiverAxis.getRiverAxis(river.getName());
            if (axis != null && axis.size() > 0) {
                logger.debug("TODO: Compute length and boundary.");
            }
            else {
                logger.warn("River has no RiverAxis.");
            }
        }
        catch(HibernateException iae) {
            logger.warn("No vaild river axis found for " + river.getName());
            return;
        }

    }


    protected void doCrossSectionTracksInfo(River river) {
        Query query = session.createQuery(
            "from CrossSectionTrack where river =:river");
        query.setParameter("river", river);

        List<CrossSectionTrack> list = query.list();

        if (list == null || list.size() == 0) {
            logger.warn("No CrossSectionTracks for '" + river.getName() + "' found!");
            return;
        }
        else {
            logger.info("River contains " + list.size() + " CrossSectionTracks.");
        }
    }


    protected void doBuildingsInfo(River river) {
        Query query = session.createQuery(
            "from Building where river =:river");
        query.setParameter("river", river);

        List<Building> list = query.list();

        if (list == null || list.size() == 0) {
            logger.warn("No Buildings for '" + river.getName() + "' found!");
            return;
        }
        else {
            logger.info("River contains " + list.size() + " Buildings.");
        }
    }


    protected void doFixpointsInfo(River river) {
        Query query = session.createQuery(
            "from Fixpoint where river =:river");
        query.setParameter("river", river);

        List<Fixpoint> list = query.list();

        if (list == null || list.size() == 0) {
            logger.warn("No Fixpoints for '" + river.getName() + "' found!");
            return;
        }
        else {
            logger.info("River contains " + list.size() + " Fixpoints.");
        }
    }

    @Deprecated
    protected void doLinesInfo(River river) {
        doHWSLinesInfo(river);
    }

    protected void doHWSLinesInfo(River river) {
        Query query = session.createQuery(
            "from hws_lines where river =:river");
        query.setParameter("river", river);

        List<HWSLine> list = query.list();

        if (list == null || list.size() == 0) {
            logger.warn("No Lines for '" + river.getName() + "' found!");
            return;
        }
        else {
            logger.info("River contains " + list.size() + " Lines.");
        }
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org