/
ParallelDispatcher.java
55 lines (51 loc) · 1.24 KB
/
ParallelDispatcher.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
public class ParallelDispatcher implements Runnable {
private PacketQueue[] queues;
private PacketGenerator source;
private PaddedPrimitiveNonVolatile<Boolean> finished;
public int totalPackets;
private PacketQueue[] configs;
public ParallelDispatcher(PacketQueue[] queues,PacketQueue[] configs, PacketGenerator source,
PaddedPrimitiveNonVolatile<Boolean> finished) {
this.configs = configs;
this.queues = queues;
this.source = source;
this.finished = finished;
this.totalPackets = 0;
}
public void run() {
Packet p;
while (!finished.value) {
for (int i = 0; i < queues.length; i++) {
p = source.getPacket();
switch (p.type) {
case ConfigPacket:
while (p != null) {
for (int j = 0; j < configs.length; j++) {
try {
configs[(j + i) % (configs.length)].enq(p);
totalPackets += 1;
p = null;
break;
} catch (FullException e) {
}
}
}
break;
case DataPacket:
while (p != null) {
for (int j = 0; j < queues.length; j++) {
try {
queues[(j + i) % (queues.length)].enq(p);
totalPackets += 1;
p = null;
break;
} catch (FullException e) {
}
}
}
break;
}
}
}
}
}