1
2
3
4
5
6
7
8
9
10
11
12
13 package org.gscg;
14
15 import java.rmi.RemoteException;
16
17 import nl.tudelft.simulation.dsol.ModelInterface;
18 import nl.tudelft.simulation.dsol.experiment.Experiment;
19 import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
20 import nl.tudelft.simulation.event.EventInterface;
21 import nl.tudelft.simulation.event.EventListenerInterface;
22
23 /***
24 * The TestModel <br>
25 * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
26 * Delft, the Netherlands. All rights reserved.
27 *
28 * See for project information <a href="http://www.simulation.tudelft.nl/">
29 * www.simulation.tudelft.nl </a>.
30 *
31 * The source code and binary code of this software is proprietary information
32 * of Delft University of Technology.
33 *
34 * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
35 * Jacobs </a>, <a
36 * href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
37 * Verbraeck </a>
38 * @version $Revision: 1.1 $ $Date: 2005/06/16 12:34:03 $
39 * @since 1.0.0
40 */
41 public class TestModel implements ModelInterface, EventListenerInterface
42 {
43 /*** the serial version uid */
44 private static final long serialVersionUID = 11L;
45
46 /*** experiment refers to the experiment which is fired to the simulator */
47 private Experiment experiment = null;
48
49 /*** the startTime */
50 private long startTime = 0L;
51
52 /***
53 * constructs a new TestModel
54 *
55 * @param experiment refers to the experiment
56 */
57 public TestModel(final Experiment experiment)
58 {
59 super();
60 this.experiment = experiment;
61 }
62
63 /***
64 * @see nl.tudelft.simulation.dsol.ModelInterface
65 * #constructModel(SimulatorInterface)
66 */
67 public void constructModel(final SimulatorInterface simulator)
68 throws RemoteException
69 {
70 simulator
71 .addListener(this, SimulatorInterface.END_OF_REPLICATION_EVENT);
72 simulator.addListener(this, SimulatorInterface.START_REPLICATION_EVENT);
73 simulator.addListener(this, SimulatorInterface.START_EVENT);
74 simulator.addListener(this, SimulatorInterface.STOP_EVENT);
75 simulator.addListener(this, SimulatorInterface.STEP_EVENT);
76 simulator.addListener(this, SimulatorInterface.TIME_CHANGED_EVENT);
77 this.experiment.addListener(this, Experiment.END_OF_EXPERIMENT_EVENT);
78 }
79
80 /***
81 * @see nl.tudelft.simulation.event.EventListenerInterface
82 * #notify(EventInterface)
83 */
84 public void notify(final EventInterface event)
85 {
86 if (event.getType().equals(SimulatorInterface.START_EVENT))
87 {
88 this.startTime = System.currentTimeMillis();
89 System.out.println("started @ " + this.startTime);
90 }
91 if (event.getType().equals(SimulatorInterface.STOP_EVENT))
92 {
93 long runLength = System.currentTimeMillis() - this.startTime;
94 try
95 {
96 System.out.println("runlength="
97 + runLength
98 + " time="
99 + ((SimulatorInterface) event.getSource())
100 .getSimulatorTime());
101 } catch (RemoteException e)
102 {
103 e.printStackTrace();
104 }
105 }
106 }
107 }