@Override
public void messageReceived(final FudgeContext fudgeContext, final FudgeMsgEnvelope msgEnvelope) {
final FudgeMsg msg = msgEnvelope.getMessage();
final int modificationCount = msg.getInt(DataFunctionBlacklistResource.MODIFICATION_COUNT_FIELD);
FudgeField field = msg.getByName(DataFunctionBlacklistResource.RULES_ADDED_FIELD);
final FudgeDeserializer fdc = new FudgeDeserializer(fudgeContext);
if (field != null) {
final List<FudgeField> rulesMsg = msg.getFieldValue(FudgeMsg.class, field).getAllFields();
if (rulesMsg.size() == 1) {
ruleAdded(modificationCount, fdc.fieldValueToObject(FunctionBlacklistRule.class, rulesMsg.get(0)), getProvider().getBackgroundTasks());
} else {
final List<FunctionBlacklistRule> rules = new ArrayList<FunctionBlacklistRule>(rulesMsg.size());
for (FudgeField ruleField : rulesMsg) {
rules.add(fdc.fieldValueToObject(FunctionBlacklistRule.class, ruleField));
}
rulesAdded(modificationCount, rules, getProvider().getBackgroundTasks());
}
}
field = msg.getByName(DataFunctionBlacklistResource.RULES_REMOVED_FIELD);
if (field != null) {
final List<FudgeField> rulesMsg = msg.getFieldValue(FudgeMsg.class, field).getAllFields();
if (rulesMsg.size() == 1) {
ruleRemoved(modificationCount, fdc.fieldValueToObject(FunctionBlacklistRule.class, rulesMsg.get(0)), getProvider().getBackgroundTasks());
} else {
final List<FunctionBlacklistRule> rules = new ArrayList<FunctionBlacklistRule>(rulesMsg.size());
for (FudgeField ruleField : rulesMsg) {
rules.add(fdc.fieldValueToObject(FunctionBlacklistRule.class, ruleField));
}
rulesRemoved(modificationCount, rules, getProvider().getBackgroundTasks());
}
}
}