Java Reference
In-Depth Information
1 /**
2
figure 13.5
The Event class used
for call bank
simulation
* The event class.
* Implements the Comparable interface
3
* to arrange events by time of occurrence.
4
* (nested in CallSim)
5
*/
6
private static class Event implements Comparable<Event>
7
{
8
static final int DIAL_IN = 1;
9
static final int HANG_UP = 2;
10
11
12 public Event( )
13 {
14 this( 0, 0, DIAL_IN );
15
}
16
17
public Event( int name, int tm, int type )
{
18
who = name;
19
time = tm;
20
what = type;
21
}
22
23
24
public int compareTo( Event rhs )
{
25
return time - rhs.time;
26
}
27
28
29
int who; // the number of the user
int time; // when the event will occur
30
int what; // DIAL_IN or HANG_UP
31
}
32
that Event 's internal members can be accessed by CallSim methods. The Event
class is nested inside the CallSim class.
The call bank simulation class skeleton, CallSim , is shown in Figure 13.6. It
consists of a lot of data members, a constructor, and two methods. The data
members include a random number object r shown at line 27. At line 28 the
eventSet is maintained as a priority queue of Event objects. The remaining
data members are availableOperators , which is initially the number of opera-
tors in the simulation but changes as users connect and hang up, and avgCallLen
and freqOfCalls , which are parameters of the simulation. Recall that a dial-in
attempt will be made every freqOfCalls ticks. The constructor, declared at
line 15 and implemented in Figure 13.7, initializes these members and places
the first arrival in the eventSet priority queue.
Search WWH ::




Custom Search