1 | package desmoj.core.simulator; |
2 | |
3 | /** |
4 | * Provides the basic frame for user defined events. Derive from this class to |
5 | * design special real time external events for a model. To use real time |
6 | * external events, always create a new object of this class. |
7 | * |
8 | * @version DESMO-J, Ver. 2.3.3 copyright (c) 2011 |
9 | * @author Felix Klueckmann |
10 | * |
11 | * Licensed under the Apache License, Version 2.0 (the "License"); you |
12 | * may not use this file except in compliance with the License. You may |
13 | * obtain a copy of the License at |
14 | * http://www.apache.org/licenses/LICENSE-2.0 |
15 | * |
16 | * Unless required by applicable law or agreed to in writing, software |
17 | * distributed under the License is distributed on an "AS IS" BASIS, |
18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
19 | * implied. See the License for the specific language governing |
20 | * permissions and limitations under the License. |
21 | * |
22 | */ |
23 | |
24 | public class RealTimeEventWrapper { |
25 | |
26 | /** |
27 | * A nanosecond timestamp that will be associated to the encapsulated ExternalEvent. |
28 | * |
29 | */ |
30 | private long _nanos; |
31 | |
32 | /** |
33 | * The ExternalEvent encapsulated by this RealTimEventWrapper |
34 | * |
35 | */ |
36 | private ExternalEvent _myExternalEvent; |
37 | |
38 | /** |
39 | * Creates an real time wrapper for an external event. This constructor will |
40 | * set the nanosecond timestamp to the current value of System.nanoTime(). |
41 | * |
42 | */ |
43 | public RealTimeEventWrapper(ExternalEvent externalEvent) { |
44 | this._myExternalEvent = externalEvent; |
45 | this.setNanos(System.nanoTime()); |
46 | } |
47 | |
48 | /** |
49 | * Creates an real time wrapper for an external event. |
50 | * |
51 | */ |
52 | public RealTimeEventWrapper(ExternalEvent externalEvent, long nanoTimeStamp) { |
53 | this._myExternalEvent = externalEvent; |
54 | this._nanos = nanoTimeStamp; |
55 | } |
56 | |
57 | /** |
58 | * Returns the encapsulated ExternalEvent |
59 | * |
60 | */ |
61 | ExternalEvent getExternalEvent() { |
62 | return _myExternalEvent; |
63 | } |
64 | |
65 | /** |
66 | * Schedules the external event to happen at the simulation time equivalent |
67 | * to the nanosecond timestamp of this RealTimeEventWrapper. |
68 | * |
69 | */ |
70 | public void realTimeSchedule() { |
71 | _myExternalEvent.getModel().getExperiment().getScheduler() |
72 | .realTimeSchedule(this); |
73 | |
74 | } |
75 | |
76 | /** |
77 | * Sets the nanosecond timestamp of this RealTimeEventWrapper. Use |
78 | * method System.nanoTime() to get a time stamp. |
79 | */ |
80 | public void setNanos(long nanos) { |
81 | this._nanos = nanos; |
82 | } |
83 | |
84 | /** |
85 | * Returns the nanosecond timestamp associated with the encapsulated ExternalEvent. * |
86 | */ |
87 | public long getNanos() { |
88 | return _nanos; |
89 | } |
90 | |
91 | } |