use of org.apache.helix.model.ConstraintItem in project helix by apache.
the class MessageThrottleStage method throttle.
private List<Message> throttle(Map<String, Integer> throttleMap, ClusterConstraints constraint, List<Message> messages, final boolean needThrottle) {
List<Message> throttleOutputMsgs = new ArrayList<Message>();
for (Message message : messages) {
Map<ConstraintAttribute, String> msgAttr = ClusterConstraints.toConstraintAttributes(message);
Set<ConstraintItem> matches = constraint.match(msgAttr);
matches = selectConstraints(matches, msgAttr);
boolean msgThrottled = false;
for (ConstraintItem item : matches) {
String key = item.filter(msgAttr).toString();
if (!throttleMap.containsKey(key)) {
throttleMap.put(key, valueOf(item.getConstraintValue()));
}
int value = throttleMap.get(key);
throttleMap.put(key, --value);
if (needThrottle && value < 0) {
msgThrottled = true;
if (LOG.isDebugEnabled()) {
// TODO: printout constraint item that throttles the message
LOG.debug("message: " + message + " is throttled by constraint: " + item);
}
}
}
if (!msgThrottled) {
throttleOutputMsgs.add(message);
}
}
return throttleOutputMsgs;
}
Aggregations