-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathControlDesk.java
201 lines (165 loc) · 4.38 KB
/
ControlDesk.java
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/* ControlDesk.java
*
* Version:
* $Id$
*
* Revisions:
* $Log: ControlDesk.java,v $
* Revision 1.13 2003/02/02 23:26:32 ???
* ControlDesk now runs its own thread and polls for free lanes to assign queue members to
*
* Revision 1.12 2003/02/02 20:46:13 ???
* Added " 's Party" to party names.
*
* Revision 1.11 2003/02/02 20:43:25 ???
* misc cleanup
*
* Revision 1.10 2003/02/02 17:49:10 ???
* Fixed problem in getPartyQueue that was returning the first element as every element.
*
* Revision 1.9 2003/02/02 17:39:48 ???
* Added accessor for lanes.
*
* Revision 1.8 2003/02/02 16:53:59 ???
* Updated comments to match javadoc format.
*
* Revision 1.7 2003/02/02 16:29:52 ???
* Added ControlDeskEvent and ControlDeskObserver. Updated Queue to allow access to Vector so that contents could be viewed without destroying. Implemented observer model for most of ControlDesk.
*
* Revision 1.6 2003/02/02 06:09:39 ???
* Updated many classes to support the ControlDeskView.
*
* Revision 1.5 2003/01/26 23:16:10 ???
* Improved thread handeling in lane/controldesk
*
*
*/
/**
* Class that represents control desk
*
*/
import java.util.*;
class ControlDesk extends Thread {
private static final int SLEEPMS = 250;
private BowlerRegistrationManager registrationManager;
private PartyQueueManager partyQueueManager;
private LaneManager laneManager;
private ScoreManager scoreManager;
/** The collection of subscribers */
private Vector<ControlDeskObserver> subscribers;
/**
* Constructor for the ControlDesk class
*
* @param numLanes the numbler of lanes to be represented
*
*/
public ControlDesk(int numLanes) {
registrationManager = new BowlerRegistrationManager(this);
partyQueueManager = new PartyQueueManager(this);
laneManager = new LaneManager(this, numLanes);
scoreManager = new ScoreManager(this);
subscribers = new Vector<>();
this.start();
}
/**
* Main loop for ControlDesk's thread
*
*/
public void run() {
while (true) {
assignLane();
try {
sleep(SLEEPMS);
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
}
/**
* Retrieves a matching Bowler from the bowler database.
*
* @param nickName The NickName of the Bowler
*
* @return a Bowler object.
*
*/
public Bowler registerPatron(String nickName) {
return registrationManager.registerPatron(nickName);
}
/**
* Iterate through the available lanes and assign the paties in the wait queue if lanes are available.
*
*/
public void assignLane() {
laneManager.assignLane();
}
/**
*/
public void viewScores(Lane ln) {
// TODO: attach a LaneScoreView object to that lane
scoreManager.viewScores(ln);
}
/**
* Creates a party from a Vector of nickNAmes and adds them to the wait queue.
*
* @param partyNicks A Vector of NickNames
*
*/
public void addPartyQueue(Vector<String> partyNicks) {
partyQueueManager.addPartyQueue(partyNicks);
}
/**
* Returns a Vector of party names to be displayed in the GUI representation of the wait queue.
*
* @return a Vecotr of Strings
*
*/
public Vector<String> getPartyQueue() {
return partyQueueManager.getPartyQueue();
}
/**
* Accessor for the number of lanes represented by the ControlDesk
*
* @return an int containing the number of lanes represented
*
*/
public int getNumLanes() {
return laneManager.getNumLanes();
}
/**
* Allows objects to subscribe as observers
*
* @param adding the ControlDeskObserver that will be subscribed
*
*/
public void subscribe(ControlDeskObserver adding) {
subscribers.add(adding);
}
/**
* Broadcast an event to subscribing objects.
*
* @param event the ControlDeskEvent to broadcast
*
*/
public void publish(PartyQueueEvent event) {
Iterator<ControlDeskObserver> eventIterator = subscribers.iterator();
while (eventIterator.hasNext()) {
eventIterator
.next()
.receiveControlDeskEvent(
event);
}
}
/**
* Accessor method for lanes
*
* @return a HashSet of Lanes
*
*/
public HashSet<Lane> getLanes() {
return laneManager.getLanes();
}
public Queue getWaitQueue(){
return partyQueueManager.getWaitQueue();
}
}