Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/wsplgen/Scheduler.java @ 2792:fe987587ebc9
Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
file:///home/clients/bsh/bsh-generischer-viewer/Material/SVN/flys-artifacts/trunk
........
r4539 | teichmann | 2012-05-27 20:02:13 +0200 (So, 27 Mai 2012) | 1 line
FixA: Added forgotten csv/report facets/generators to conf.
........
r4540 | teichmann | 2012-05-27 20:11:31 +0200 (So, 27 Mai 2012) | 1 line
FixA: Fixed class cast bug in report facet.
........
r4543 | teichmann | 2012-05-28 20:35:01 +0200 (Mo, 28 Mai 2012) | 1 line
FixA: Added facet to return delta w/t as CSV
........
r4545 | teichmann | 2012-05-28 22:59:27 +0200 (Mo, 28 Mai 2012) | 1 line
FixA: Made Delta W/t calculation finally work
........
r4546 | teichmann | 2012-05-28 23:34:24 +0200 (Mo, 28 Mai 2012) | 1 line
FixA: corrected fitting (Q->W instead W->Q).
........
flys-artifacts/tags/2.7@4547 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 29 May 2012 04:58:29 +0000 |
parents | 368040e5c400 |
children | 453d2d0c4258 |
line wrap: on
line source
package de.intevation.flys.wsplgen; import java.util.HashMap; import java.util.Map; import java.util.concurrent.Future; import java.util.concurrent.ScheduledThreadPoolExecutor; import org.apache.log4j.Logger; import de.intevation.artifacts.CallContext; import de.intevation.flys.artifacts.model.WSPLGENJob; /** * The Scheduler is used to retrieve new WSPLGENJob. The incoming jobs are added * to a ScheduledThreadPoolExecutor. This thread pool has a number of worker * threads that processes the WSPLGENJobs. The number of worker threads can be * set using a System property <i>wsplgen.max.threads</i> ; its default value is * 1. * * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class Scheduler { private class FutureJob { public Future future; public WSPLGENJob job; public FutureJob(Future future, WSPLGENJob job) { this.future = future; this.job = job; } } public static final int MAX_WSPLGEN_PROCESSES = Integer.getInteger("wsplgen.max.threads", 1); protected ScheduledThreadPoolExecutor pool; protected Map<String, FutureJob> jobs; private static Scheduler INSTANCE; private static final Logger logger = Logger.getLogger(Scheduler.class); private Scheduler() { jobs = new HashMap<String, FutureJob>(); pool = new ScheduledThreadPoolExecutor(MAX_WSPLGEN_PROCESSES); } public static Scheduler getInstance() { if (INSTANCE == null) { logger.info("Create new WSPLGEN Scheduler..."); INSTANCE = new Scheduler(); } return INSTANCE; } public void addJob(final WSPLGENJob job) { synchronized (jobs) { WSPLGENFuture f = new WSPLGENFuture(new WSPLGENCallable(this, job)); pool.execute(f); jobs.put(job.getArtifact().identifier(), new FutureJob(f, job)); logger.info("New WSPLGEN job successfully added."); } } /** * Cancels a running (or queued) job. * * @param jobId The id of the job (which is the identifier of an Artifact). */ public void cancelJob(String jobId) { logger.debug("Search job in queue: " + jobId); synchronized (jobs) { FutureJob fj = jobs.get(jobId); if (fj != null) { logger.info("Try to cancel job: " + jobId); fj.future.cancel(true); removeJob(jobId); fj.job.getCallContext().afterBackground( CallContext.STORE); logger.info("Canceled job: " + jobId); } } } protected void removeJob(String id) { synchronized (jobs) { jobs.remove(id); } } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :