1
2
3
4
5
6
7
8
9
10 package nl.tudelft.simulation.dsol.tutorial.section45;
11
12 import java.rmi.RemoteException;
13
14 import nl.tudelft.simulation.dsol.SimRuntimeException;
15 import nl.tudelft.simulation.dsol.formalisms.Resource;
16 import nl.tudelft.simulation.dsol.formalisms.ResourceRequestorInterface;
17 import nl.tudelft.simulation.dsol.formalisms.process.Process;
18 import nl.tudelft.simulation.dsol.simulators.DEVSSimulator;
19
20 /***
21 * A Boat <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 href="http://www.simulation.tudelft.nl">
25 * 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 1.0 Jan 19, 2004 <br>
30 * @author <a href="http://www.simulation.tudelft.nl/people/jacobs.html">Peter
31 * Jacobs </a>
32 */
33 public class Boat extends Process implements ResourceRequestorInterface
34 {
35 /*** the port to enter */
36 private Port port = null;
37
38 /*** boat number */
39 private static int number = 1;
40
41 /*** the description of the boat */
42 private String description = "Boat(";
43
44 /***
45 * constructs a new Boat
46 *
47 * @param simulator the simulator to schedule on
48 * @param port the port to sail to
49 */
50 public Boat(final DEVSSimulator simulator, final Port port)
51 {
52 super(simulator);
53 this.port = port;
54 this.description = this.description + (Boat.number++) + ") ";
55 }
56
57 /***
58 * @see nl.tudelft.simulation.dsol.formalisms.process.Process#process()
59 */
60 public void process() throws SimRuntimeException, RemoteException
61 {
62 double startTime = this.simulator.getSimulatorTime();
63
64
65 this.port.getJetties().requestCapacity(1.0, this);
66 this.suspend();
67
68
69 this.port.getTugs().requestCapacity(2.0, this);
70 this.suspend();
71
72
73 this.hold(2.0);
74
75
76 this.port.getTugs().releaseCapacity(2.0);
77
78
79 this.hold(14);
80
81
82 this.port.getTugs().requestCapacity(1.0, this);
83 this.suspend();
84
85
86 this.hold(2.0);
87
88
89 this.port.getTugs().releaseCapacity(1.0);
90 this.port.getJetties().releaseCapacity(1.0);
91 System.out.println(this.toString() + "arrived at time=" + startTime
92 + " and left at time=" + this.simulator.getSimulatorTime()
93 + ". ProcessTime = "
94 + (super.simulator.getSimulatorTime() - startTime));
95 }
96
97 /***
98 * @see nl.tudelft.simulation.dsol.formalisms.ResourceRequestorInterface
99 * #receiveRequestedResource(double,
100 * nl.tudelft.simulation.dsol.formalisms.Resource)
101 */
102 public void receiveRequestedResource(final double requestedCapacity,
103 final Resource resource)
104 {
105 this.resume();
106 }
107
108 /***
109 * @see java.lang.Object#toString()
110 */
111 public String toString()
112 {
113 return this.description;
114 }
115 }