public static <T extends Enum<T>> boolean hasOperationStat(Object rootNode, Class<T> statisticType, String statName) { Query q = queryBuilder().descendants() .filter(context(identifier(subclassOf(OperationStatistic.class)))) .filter(context(attributes(Matchers.allOf( hasAttribute("name", statName), hasAttribute("this", new Matcher<OperationStatistic<T>>() { @Override protected boolean matchesSafely(OperationStatistic<T> object) { return object.type().equals(statisticType); } }) )))) .build(); Set<TreeNode> result = q.execute(Collections.singleton(ContextManager.nodeFor(rootNode))); if (result.size() > 1) { throw new RuntimeException("a zero or a single stat was expected; found " + result.size()); } return !result.isEmpty(); } }
@SuppressWarnings("unchecked") private static <T extends Enum<T>> OperationStatistic<T> findStat(Cache<?, ?> cache, final String statName, final String tag) { Query q = queryBuilder().chain(self()) .descendants().filter(context(identifier(subclassOf(OperationStatistic.class)))).build(); Set<TreeNode> operationStatisticNodes = q.execute(Collections.singleton(ContextManager.nodeFor(cache))); Set<TreeNode> result = queryBuilder() .filter( context(attributes(Matchers.<Map<String, Object>>allOf( hasAttribute("name", statName), hasAttribute("tags", new Matcher<Set<String>>() { @Override protected boolean matchesSafely(Set<String> object) { return object.contains(tag); } }))))).build().execute(operationStatisticNodes); switch (result.size()) { case 0: return null; case 1: { TreeNode node = result.iterator().next(); return (OperationStatistic<T>) node.getContext().attributes().get("this"); } default: throw new RuntimeException("query for unique stat '" + statName + "' with tag '" + tag + "' failed; found " + result.size() + " instance(s)"); } }
@SuppressWarnings("unchecked") private OperationStatistic<StoreOperationOutcomes.ExpirationOutcome> getExpirationStatistic(Store<?, ?> store) { StatisticsManager statisticsManager = new StatisticsManager(); statisticsManager.root(store); TreeNode treeNode = statisticsManager.queryForSingleton(QueryBuilder.queryBuilder() .descendants() .filter(org.terracotta.context.query.Matchers.context( org.terracotta.context.query.Matchers.allOf(org.terracotta.context.query.Matchers.identifier(org.terracotta.context.query.Matchers .subclassOf(OperationStatistic.class)), org.terracotta.context.query.Matchers.attributes(org.terracotta.context.query.Matchers.hasAttribute("name", "expiration"))))) .build()); return (OperationStatistic<StoreOperationOutcomes.ExpirationOutcome>) treeNode.getContext().attributes().get("this"); }
/** * Remove instances of the specified type from the node set * * @param klazz class to be excluded * @return current set minus the given type */ EhcacheQuery exclude(Class<?> klazz) { return new EhcacheQuery(queryBuilder().chain(query).filter(context(identifier(not(subclassOf(klazz))))).build()); }
/** * Select the children of the current node set that are subtypes of the specified class * * @param klazz class to be selected * @return children of the specified type */ EhcacheQuery children(Class<?> klazz) { return new EhcacheQuery(queryBuilder().chain(query).children().filter(context(identifier(subclassOf(klazz)))).build()); }
final Set<String> tags) { Set<TreeNode> passThroughStatisticNodes = manager.query(queryBuilder().chain(contextQuery).children() .filter(context(identifier(subclassOf(ValueStatistic.class)))).build()); Set<TreeNode> result = queryBuilder() .filter(context(attributes(Matchers.<Map<String, Object>> allOf(hasAttribute("name", name),
Class<T> type, String name, final Set<String> tags) { Set<TreeNode> operationStatisticNodes = manager.query(queryBuilder().chain(contextQuery).children() .filter(context(identifier(subclassOf(OperationStatistic.class)))).build()); Set<TreeNode> result = queryBuilder() .filter(context(attributes(Matchers.<Map<String, Object>> allOf(hasAttribute("type", type), hasAttribute("name", name),
@SuppressWarnings("unchecked") private static <S extends Enum<S>> OperationStatistic<S> findOperationStat(Object rootNode, final Class<S> statisticType, final String statName) { Query q = queryBuilder().descendants() .filter(context(identifier(subclassOf(OperationStatistic.class)))) .filter(context(attributes(Matchers.allOf( hasAttribute("name", statName), hasAttribute("this", new Matcher<OperationStatistic<?>>() { @Override protected boolean matchesSafely(OperationStatistic<?> object) { return object.type().equals(statisticType); } }) )))).build(); Set<TreeNode> result = q.execute(Collections.singleton(ContextManager.nodeFor(rootNode))); if (result.size() != 1) { throw new RuntimeException("a single stat was expected; found " + result.size()); } TreeNode node = result.iterator().next(); return (OperationStatistic<S>) node.getContext().attributes().get("this"); }
public static <T extends Enum<T>> boolean hasOperationStat(Object rootNode, Class<T> statisticType, String statName) { Query q = queryBuilder().descendants() .filter(context(identifier(subclassOf(OperationStatistic.class)))) .filter(context(attributes(Matchers.allOf( hasAttribute("name", statName), hasAttribute("this", new Matcher<OperationStatistic<T>>() { @Override protected boolean matchesSafely(OperationStatistic<T> object) { return object.type().equals(statisticType); } }) )))) .build(); Set<TreeNode> result = q.execute(Collections.singleton(ContextManager.nodeFor(rootNode))); if (result.size() > 1) { throw new RuntimeException("a zero or a single stat was expected; found " + result.size()); } return !result.isEmpty(); } }
public static OperationStatistic findOperationStat(Cache<?, ?> cache1, final String statName, final String tag) { Query q = queryBuilder() .descendants().filter(context(identifier(subclassOf(OperationStatistic.class)))).build(); Set<TreeNode> operationStatisticNodes = q.execute(Collections.singleton(ContextManager.nodeFor(cache1))); Set<TreeNode> result = queryBuilder() .filter( context(attributes(Matchers.<Map<String, Object>>allOf( hasAttribute("name", statName), hasAttribute("tags", new Matcher<Set<String>>() { @Override protected boolean matchesSafely(Set<String> object) { return object.contains(tag); } }))))).build().execute(operationStatisticNodes); if (result.size() != 1) { throw new RuntimeException("single stat not found; found " + result.size()); } TreeNode node = result.iterator().next(); return (OperationStatistic) node.getContext().attributes().get("this"); }
public static ValueStatistic findValueStat(Cache<?, ?> cache1, final String statName, final String tag) { Query q = queryBuilder().chain(self()) .descendants().filter(context(identifier(subclassOf(ValueStatistic.class)))).build(); Set<TreeNode> nodes = q.execute(Collections.singleton(ContextManager.nodeFor(cache1))); Set<TreeNode> result = queryBuilder() .filter( context(attributes(Matchers.<Map<String, Object>>allOf( hasAttribute("name", statName), hasAttribute("tags", new Matcher<Set<String>>() { @Override protected boolean matchesSafely(Set<String> object) { return object.contains(tag); } }))))).build().execute(nodes); if (result.size() != 1) { throw new RuntimeException("single stat not found; found " + result.size()); } TreeNode node = result.iterator().next(); return (ValueStatistic) node.getContext().attributes().get("this"); }
/** * Remove instances of the specified type from the node set * * @param klazz class to be excluded * @return current set minus the given type */ EhcacheQuery exclude(Class<?> klazz) { return new EhcacheQuery(queryBuilder().chain(query).filter(context(identifier(not(subclassOf(klazz))))).build()); }
/** * Select the children of the current node set that are subtypes of the specified class * * @param klazz class to be selected * @return children of the specified type */ EhcacheQuery children(Class<?> klazz) { return new EhcacheQuery(queryBuilder().chain(query).children().filter(context(identifier(subclassOf(klazz)))).build()); }
/** * Select the children of the current node set that are subtypes of the specified class * * @param klazz class to be selected * @return children of the specified type */ EhcacheQuery children(Class<?> klazz) { return new EhcacheQuery(queryBuilder().chain(query).children().filter(context(identifier(subclassOf(klazz)))).build()); }
/** * Remove instances of the specified type from the node set * * @param klazz class to be excluded * @return current set minus the given type */ EhcacheQuery exclude(Class<?> klazz) { return new EhcacheQuery(queryBuilder().chain(query).filter(context(identifier(not(subclassOf(klazz))))).build()); }
final Set<String> tags) { Set<TreeNode> passThroughStatisticNodes = manager.query(queryBuilder().chain(contextQuery).children() .filter(context(identifier(subclassOf(ValueStatistic.class)))).build()); Set<TreeNode> result = queryBuilder() .filter(context(attributes(Matchers.<Map<String, Object>> allOf(hasAttribute("name", name),
final Set<String> tags) { Set<TreeNode> passThroughStatisticNodes = manager.query(queryBuilder().chain(contextQuery).children() .filter(context(identifier(subclassOf(ValueStatistic.class)))).build()); Set<TreeNode> result = queryBuilder() .filter(context(attributes(Matchers.<Map<String, Object>> allOf(hasAttribute("name", name),
hasAttribute("name", descriptor.getObserverName()), hasTags(descriptor.getTags()))))) .filter(context(identifier(subclassOf(OperationStatistic.class)))) .build().execute(Collections.singleton(treeNode));
Class<T> type, String name, final Set<String> tags) { Set<TreeNode> operationStatisticNodes = manager.query(queryBuilder().chain(contextQuery).children() .filter(context(identifier(subclassOf(OperationStatistic.class)))).build()); Set<TreeNode> result = queryBuilder() .filter(context(attributes(Matchers.<Map<String, Object>> allOf(hasAttribute("type", type), hasAttribute("name", name),
Class<T> type, String name, final Set<String> tags) { Set<TreeNode> operationStatisticNodes = manager.query(queryBuilder().chain(contextQuery).children() .filter(context(identifier(subclassOf(OperationStatistic.class)))).build()); Set<TreeNode> result = queryBuilder() .filter(context(attributes(Matchers.<Map<String, Object>> allOf(hasAttribute("type", type), hasAttribute("name", name),