public static SyncTraceTagRuleListCommand getTraceTagCommand() { TraceTagRuleList ttrl = new TraceTagRuleList(); ttrl.addRule(new NapdexTraceTagRule(1, "butter", 344555)); return new SyncTraceTagRuleListCommand(ttrl); }
public TraceTagRuleList(TraceTagRuleList copy) { this.rules = new LinkedList<TraceTagRule>(copy.getRules()); sort(rules, DescendingPrecedenceComparator.INSTANCE); }
public long findResponseTimeThreshold(Resource resource) { return getRuleList().findResponseTimeThreshold(resource); } }
public synchronized void addRule(TraceTagRule rule) { TraceTagRule exsistingRule = findRuleForPrecedence(rule.getPrecedence()); if (exsistingRule != null) { removeRule(exsistingRule); } this.rules.add(rule); // inefficient to sort all the time, but not a big deal -- shouldn't // be called often or have that many rules. sort(rules, DescendingPrecedenceComparator.INSTANCE); }
public synchronized boolean promote(TraceTagRule rule) { int index = rules.indexOf(rule); if (index == -1 || index == 0) { return false; } swapPrecedence(rule, rules.get(index - 1)); return true; }
public Set<TraceTag> findTags(TraceTagRuleContext context) { return getRuleList().findTags(context); }
public synchronized long findResponseTimeThreshold(Resource resource) { if (!(resource instanceof EndPointAwareResource)) { throw new IllegalArgumentException("Only EndPoint resources have a defined threshold"); } EndPointAwareResource endpoint = (EndPointAwareResource) resource; NapdexTraceTagRule napdexRule = findResponseTimeRule(endpoint.getEndPointName()); return napdexRule.getThreshold(); }
public synchronized boolean demote(TraceTagRule rule) { sort(rules, DescendingPrecedenceComparator.INSTANCE); int index = rules.indexOf(rule); if (index == -1 || index >= rules.size() - 1) { return false; } TraceTagRule swap = rules.get(index + 1); if (swap.getPrecedence() == 0) { return false; } swapPrecedence(rule, swap); return true; }
public TraceTagRuleList getRuleList() { TraceTagRuleList ruleList = new TraceTagRuleList(); for (PersistedTraceTagRule rule : dao.getRuleList().getRules()) { ruleList.addRule(new NapdexTraceTagRule(rule.getPrecedence(), rule.getPattern(), rule.getThreshold())); } return ruleList; }
@Transactional(readOnly=false) public void syncRuleList(TraceTagRuleList rules) { lockMan.lockUntilTransactionHasCompleted(LOCK_LIST_NAME, LOCK_LIST_NAME); List<PersistedTraceTagRule> newRules = new ArrayList<PersistedTraceTagRule>(); PersistedTraceTagRuleList ruleList = dao.getRuleList(); for (TraceTagRule rule : rules.getRules()) { NapdexTraceTagRule napRule = (NapdexTraceTagRule)rule; newRules.add(new PersistedTraceTagRule(ruleList, napRule.getPrecedence(), napRule.getPattern(), napRule.getThreshold())); } dao.syncRules(ruleList, newRules); if (changedCallback != null) { changedCallback.onTraceTagRuleListChanged(rules); } }
/** * Partition a list of resources based on their ResourceKey matching * a given rule. * * The rules will be traversed in descending priority, and the first rule * which matches the key of the resource will be associated with that * resource (and all other resources who match). */ public synchronized TraceTagRulePartitions partition(Collection<Resource> resources) { Set<Resource> leftToPartition = new HashSet<Resource>(resources); TraceTagRulePartitions res = new TraceTagRulePartitions(); for (TraceTagRule rule : getRules()) { if (rule instanceof EndPointAwareTraceTagRule) { ResourceKeyMatcher matcher = ((EndPointAwareTraceTagRule)rule).getRequiredEndPoint(); res.createPartition(rule); for (Iterator<Resource> i=leftToPartition.iterator(); i.hasNext(); ) { Resource resource = i.next(); if (matcher.matches(resource.getKey())) { res.addResource(rule, resource); i.remove(); } } } } res.addUnmatchedResources(leftToPartition); return res; }