本文整理汇总了Java中org.terracotta.context.query.Matcher类的典型用法代码示例。如果您正苦于以下问题:Java Matcher类的具体用法?Java Matcher怎么用?Java Matcher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Matcher类属于org.terracotta.context.query包,在下文中一共展示了Matcher类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findOperationStat
import org.terracotta.context.query.Matcher; //导入依赖的package包/类
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");
}
示例2: findValueStat
import org.terracotta.context.query.Matcher; //导入依赖的package包/类
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");
}
示例3: findOperationStat
import org.terracotta.context.query.Matcher; //导入依赖的package包/类
@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");
}
示例4: findStat
import org.terracotta.context.query.Matcher; //导入依赖的package包/类
@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);
if (result.size() != 1) {
throw new RuntimeException("query for unique stat '" + statName + "' with tag '" + tag + "' failed; found " + result.size() + " instance(s)");
}
TreeNode node = result.iterator().next();
return (OperationStatistic<T>) node.getContext().attributes().get("this");
}
示例5: hasTags
import org.terracotta.context.query.Matcher; //导入依赖的package包/类
private Matcher<Map<String, Object>> hasTags(final Collection<String> tags) {
return hasAttribute("tags", new Matcher<Collection<String>>() {
@Override
protected boolean matchesSafely(Collection<String> object) {
return object.containsAll(tags);
}
});
}
示例6: hasTag
import org.terracotta.context.query.Matcher; //导入依赖的package包/类
static Matcher<Map<String, Object>> hasTag(final String tag) {
return hasAttribute("tags", new Matcher<Set<String>>() {
@Override
protected boolean matchesSafely(Set<String> object) {
return object.contains(tag);
}
});
}
示例7: hasProperty
import org.terracotta.context.query.Matcher; //导入依赖的package包/类
static Matcher<Map<String, Object>> hasProperty(final String key, final String value) {
return hasAttribute("properties", new Matcher<Map<String, Object>>() {
@Override
protected boolean matchesSafely(Map<String, Object> properties) {
Object val = properties.get(key);
return val != null && value.equals(val);
}
});
}
示例8: testStatisticsAssociations
import org.terracotta.context.query.Matcher; //导入依赖的package包/类
@Test
public void testStatisticsAssociations() throws Exception {
OffHeapDiskStore.Provider provider = new OffHeapDiskStore.Provider();
ServiceLocator serviceLocator = dependencySet().with(mock(SerializationProvider.class))
.with(new DefaultTimeSourceService(null)).with(mock(DiskResourceService.class)).build();
provider.start(serviceLocator);
OffHeapDiskStore<Long, String> store = provider.createStore(getStoreConfig(), mock(PersistableResourceService.PersistenceSpaceIdentifier.class));
@SuppressWarnings("unchecked")
Query storeQuery = queryBuilder()
.children()
.filter(context(attributes(Matchers.<Map<String, Object>>allOf(
hasAttribute("tags", new Matcher<Set<String>>() {
@Override
protected boolean matchesSafely(Set<String> object) {
return object.containsAll(singleton("Disk"));
}
})))))
.build();
Set<TreeNode> nodes = singleton(ContextManager.nodeFor(store));
Set<TreeNode> storeResult = storeQuery.execute(nodes);
assertThat(storeResult, not(empty()));
provider.releaseStore(store);
storeResult = storeQuery.execute(nodes);
assertThat(storeResult, empty());
}