Search in sources :

Example 6 with ConstraintItem

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;
}
Also used : Message(org.apache.helix.model.Message) ArrayList(java.util.ArrayList) ConstraintItem(org.apache.helix.model.ConstraintItem) ConstraintAttribute(org.apache.helix.model.ClusterConstraints.ConstraintAttribute)

Aggregations

ConstraintItem (org.apache.helix.model.ConstraintItem)6 HelixDataAccessor (org.apache.helix.HelixDataAccessor)4 ZNRecord (org.apache.helix.ZNRecord)4 Message (org.apache.helix.model.Message)4 Test (org.testng.annotations.Test)4 ArrayList (java.util.ArrayList)3 HelixManager (org.apache.helix.HelixManager)3 PropertyKey (org.apache.helix.PropertyKey)3 StringWriter (java.io.StringWriter)2 Date (java.util.Date)2 TreeMap (java.util.TreeMap)2 Criteria (org.apache.helix.Criteria)2 Builder (org.apache.helix.PropertyKey.Builder)2 PropertyPathBuilder (org.apache.helix.PropertyPathBuilder)2 ClusterConstraints (org.apache.helix.model.ClusterConstraints)2 ConstraintAttribute (org.apache.helix.model.ClusterConstraints.ConstraintAttribute)2 ConstraintItemBuilder (org.apache.helix.model.builder.ConstraintItemBuilder)2 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 SerializationConfig (org.codehaus.jackson.map.SerializationConfig)2 HelixAdmin (org.apache.helix.HelixAdmin)1