-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvent.java
More file actions
102 lines (90 loc) · 3.39 KB
/
Event.java
File metadata and controls
102 lines (90 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
* Base class for Events.
* Manages event IDs, assigning a unique event ID per new event created. Provides getters for event ID, insertion time,
* and arrival time.
*/
public abstract class Event {
private static int nextId = 0;
private final int id;
/**
* Insertion time into the future event list of this Event. Must be zero or greater.
*/
protected int insertionTime;
/**
* Arrival time of this Event. This is the simulation time in which the Event is removed from the future event list
* and handled. Must be zero or greater, and cannot be less than the insertion time.
*/
protected int arrivalTime;
protected Event() {
this.insertionTime = -1;
this.arrivalTime = -1;
this.id = Event.nextId++;
}
/**
* Returns the Event's ID.
* <br>
* Each Event has an unique id
*
* @return the Event's arrival time
*/
public int getId() {
return this.id;
}
/**
* Returns the insertion time of this Event.
* <br>
* Insertion time is the simulation time in which this Event is inserted into the future event list. This should
* not change once set.
*
* @return the Event's arrival time
*/
public int getInsertionTime() {
return this.insertionTime;
}
/**
* Returns the arrival time of this Event.
* <br>
* Arrival time represents the time in which an Event is removed from the future event list for it to be
* executed or handled. For example, if this Event represents a network packet, then the arrival time
* represents the time in which the network packet 'arrives' at the destination host. If the Event is a Timer,
* then the arrival time is the absolute time in which the timer expires.
* <br>
* This arrival time is what the future event list uses for sort order when inserting an Event, therefore it should
* not change.
*
* @return the Event's arrival time
*/
public int getArrivalTime() {
return this.arrivalTime;
}
/**
* Sets the insertion time and arrival time for this Event.
* <br>
* It is assumed that any information needed to compute the arrival time from the insertion time is passed into
* the Event's constructor (for example a duration). This method should be called from within the FutureEventList's
* insert method.
*
* @param currentTime the current simulation time
*/
public abstract void setInsertionTime(int currentTime);
/**
* Cancel the Event.
* <br>
* This occurs after the Event has been removed from the future event list, probably before the arrival time has
* been reached.
*/
public abstract void cancel();
/**
* Handle (or execute) the Event.
* <br>
* This occurs after the Event has been removed from the future event list, due to the arrival time being reached.
* For example, if this Event represents a network message, then calling handle() will 'process' the message at the
* destination host. If the Event is a Timer, then this will execute whatever needs to be done upon timer expiry.
*/
public abstract void handle();
@Override
public String toString() {
return "[Event " + this.getId() + " (insertion time: " + this.getInsertionTime() + ", arrival time: " +
this.getArrivalTime() + ")]";
}
}