-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServer.java
117 lines (91 loc) · 3.04 KB
/
Server.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
public abstract class Server {
protected int curr_time = 0;
protected int time_busy = 0;
protected int time_idle = 0;
protected int time_maintainence = 0;
protected int number_served = 0;
protected User current_user_being_served = null;
protected int remaining_service_time = 0;
protected boolean isRunning = false;
protected boolean isBusy = false;
protected boolean isMaintenance = false;
protected String name;
protected long hourly_wage;
protected PatientQueue my_queue;
public Server(String name, long hourly_wage, int max_number_of_users) {
this.name = name;
this.hourly_wage = hourly_wage;
this.my_queue = new PatientQueue(max_number_of_users);
}
public int getNumber_served() {
return number_served;
}
public void setNumber_served(int number_served) {
this.number_served = number_served;
}
public long getHourly_wage() {
return hourly_wage;
}
public void setHourly_wage(long hourly_wage) {
this.hourly_wage = hourly_wage;
}
public User getCurrent_user_being_served() {
return current_user_being_served;
}
public void setCurrent_user_being_served(User current_user_being_served) {
this.current_user_being_served = current_user_being_served;
}
public int getCurr_time() {
return curr_time;
}
public void setcurr_time(int curr_time) {
this.curr_time = curr_time;
}
public PatientQueue getMy_queue() {
return my_queue;
}
public void setMy_queue(PatientQueue my_queue) {
this.my_queue = my_queue;
}
public boolean isRunning() {
return isRunning;
}
public void setIsRunning(boolean isRunning) {
this.isRunning = isRunning;
}
// ---------------------------------------------------------------------------------
public abstract boolean serve_user();
public abstract boolean isUnderMaintenance();
public void tick() {
/**
* This is the timing synchronization feature of the servers. Since 3 servers are
* running in parallel, this method assures that each server steps forward at the same time.
*/
curr_time++;
if (isMaintenance) {
time_maintainence++;
}
else if (isBusy) {
time_busy++;
}
else {
time_idle++;
}
if (isBusy) {
remaining_service_time--;
}
if (!isBusy || remaining_service_time < 0) {
isBusy = serve_user();
}
}
public String toString() {
String msg = "";
msg += String.format("Name: %s\n", name);
msg += String.format(" Wage: %s\n", hourly_wage);
msg += String.format(" Cust. Served: %s\n", number_served);
msg += String.format(" Time Busy: %s\n", time_busy);
msg += String.format(" Time Idle: %s\n", time_idle);
msg += String.format(" Maintainence Time: %s\n", time_maintainence);
return msg;
}
}