Newer
Older
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
package refit.replica.order;
import refit.config.REFITLogger;
import refit.message.REFITAckReply;
import refit.message.REFITInstruction;
import refit.message.REFITInstruction.REFITConfigurationNotification;
import refit.message.REFITMessage;
import refit.replica.REFITBaseReplica;
import refit.replica.REFITObserver;
import refit.replica.REFITStage;
import refit.scheduler.REFITSchedulerTaskType;
public class REFITMenciusSplitter extends REFITStage {
public final REFITObserver<REFITConfigurationNotification>[] viewChangeSenders;
public final REFITObserver<REFITAckReply>[] ackSenders;
@SuppressWarnings("unchecked")
public REFITMenciusSplitter(REFITBaseReplica replica) {
super(REFITSchedulerTaskType.ORDER_STAGE, replica);
viewChangeSenders = (REFITObserver<REFITConfigurationNotification>[]) new REFITObserver[REFITOrderGroups.COUNT];
ackSenders = (REFITObserver<REFITAckReply>[]) new REFITObserver[REFITOrderGroups.COUNT];
for (int i = 0; i < viewChangeSenders.length; i++) viewChangeSenders[i] = new REFITObserver<>();
for (int i = 0; i < ackSenders.length; i++) ackSenders[i] = new REFITObserver<>();
}
@Override
protected void handleMessage(REFITMessage message) {
switch (message.type) {
case ACK_REPLY:
REFITAckReply ack = (REFITAckReply) message;
if (ack.groupID >= 0) {
ackSenders[ack.groupID].broadcast(ack);
} else {
for (int i = 0; i < ackSenders.length; i++) {
ackSenders[i].broadcast(ack);
}
}
break;
case INSTRUCTION:
handleInstruction((REFITInstruction) message);
break;
default:
REFITLogger.logError(this, "drop message of unexpected type " + message.type);
}
}
private void handleInstruction(REFITInstruction message) {
switch (message.instructionType) {
case CONFIGURATION_NOTIFICATION:
REFITConfigurationNotification config = (REFITConfigurationNotification) message;
viewChangeSenders[config.groupID].broadcast(config);
break;
default:
REFITLogger.logError(this, "drop instruction of unexpected type " + message.instructionType);
}
}
}