-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMovementProducer.java
More file actions
42 lines (35 loc) · 989 Bytes
/
MovementProducer.java
File metadata and controls
42 lines (35 loc) · 989 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
40
41
/*
* Copyright 2018 ADVA Optical Networking SE. All rights reserved.
*
* Owner: tomaszd
*
* $Id: $
*/
import java.util.Random;
import java.util.concurrent.BlockingQueue;
public class MovementProducer implements Runnable {
protected BlockingQueue<Move> queue;
protected String []movements = {"N", "NE", "E", "SE", "S", "SW", "W", "NW", "STOP"};
public MovementProducer(BlockingQueue<Move> queue){
this.queue = queue;
}
@Override
public void run() {
Random random = new Random();
for(int i=0; i < 100; i++){
Move move = new Move(movements[random.nextInt(movements.length)]);
try {
System.out.println("Move \""+ move.getMove()+ "\" added to queue");
queue.put(move);
Thread.sleep((long) (Math.random() * 100));
} catch (InterruptedException e){
e.printStackTrace();
}
}
try {
queue.put(new Move("Q"));
} catch (InterruptedException e){
e.printStackTrace();
}
}
}