01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: ParticipantMemoryScheduler.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.rep.participants;
09:
10: import com.uwyn.rife.rep.BlockingParticipant;
11: import com.uwyn.rife.scheduler.Scheduler;
12: import com.uwyn.rife.scheduler.exceptions.SchedulerManagerException;
13: import com.uwyn.rife.scheduler.schedulermanagers.MemoryScheduler;
14:
15: public class ParticipantMemoryScheduler extends BlockingParticipant {
16: private Scheduler mScheduler = null;
17:
18: public ParticipantMemoryScheduler() {
19: setInitializationMessage("Populating in-memory scheduler and starting the execution ...");
20: setCleanupMessage("Stopping in-memory scheduler and cleaning it up ...");
21: }
22:
23: protected void initialize() {
24: try {
25: MemoryScheduler scheduler_factory = new MemoryScheduler(
26: this .getParameter(), getResourceFinder());
27: mScheduler = scheduler_factory.getScheduler();
28: mScheduler.start();
29: } catch (SchedulerManagerException e) {
30: throw new RuntimeException(
31: "Fatal error during the initialization while populating the in-memory scheduler.",
32: e);
33: }
34: }
35:
36: protected void cleanup() {
37: if (mScheduler != null) {
38: mScheduler.interrupt();
39: }
40: }
41:
42: protected Object _getObject(Object key) {
43: return mScheduler;
44: }
45: }
|