-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoboBase.java
More file actions
39 lines (30 loc) · 915 Bytes
/
RoboBase.java
File metadata and controls
39 lines (30 loc) · 915 Bytes
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
package com.fellowrobots;
import java.util.Dictionary;
import java.util.Hashtable;
public class RoboBase {
private static RoboBase instance = null;
public static synchronized RoboBase getInstance() {
if (instance == null) instance = new RoboBase();
return instance;
}
private Dictionary<String, Robot> robots; // name -> robot
private RoboBase() {
robots = new Hashtable<String, Robot>();
}
public synchronized boolean login(String robot_name, RobotServerHandler handler) {
if (isOnline(robot_name)) {
return false;
}
robots.put(robot_name, new Robot(robot_name, handler));
return true;
}
public synchronized void logout(String robot_name) {
robots.remove(robot_name);
}
public synchronized boolean isOnline(String robot_name) {
return robots.get(robot_name) != null;
}
public synchronized Robot getRobot(String robot_name) {
return robots.get(robot_name);
}
}