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