-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRobotSystemMT.java
More file actions
52 lines (37 loc) · 1.2 KB
/
RobotSystemMT.java
File metadata and controls
52 lines (37 loc) · 1.2 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
/*
RobotSystemMT.java
*/
/* robot subsystem that uses separate threads to process
each incoming event
*/
//package first;
public class RobotSystemMT extends RobotSystem
implements Runnable,RobotEventListener
{
public RobotSystemMT(int anInt, RobotController c)
{
super(anInt,c);
}
public void eventReceived(RobotEvent e)
{
final RobotEvent eF = e;
Runnable privateEventReceived = new Runnable() {
public void run() {
System.out.println("RobotSystemMT "+myNumber+" recvd event "+eF+
" on thread "+Thread.currentThread().getId());
}
}; /* private threaded event receiver */
// create thread and run it for each event we receive
new Thread(privateEventReceived).start();
} /* eventReceived */
public void run()
{
System.out.println("RobotSystemMT "+myNumber+" starting thread "+
Thread.currentThread().getId());
// register to receive events
aController.addEventListener(this);
while (true) {
try { Thread.sleep(500); } catch (InterruptedException iE) { }
}
}
} /* RobotSystemMT */