当前位置: 首页>>代码示例>>Java>>正文


Java Matchers类代码示例

本文整理汇总了Java中org.terracotta.context.query.Matchers的典型用法代码示例。如果您正苦于以下问题:Java Matchers类的具体用法?Java Matchers怎么用?Java Matchers使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Matchers类属于org.terracotta.context.query包,在下文中一共展示了Matchers类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findOperationStat

import org.terracotta.context.query.Matchers; //导入依赖的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");
}
 
开发者ID:ehcache,项目名称:ehcache3-samples,代码行数:23,代码来源:Ehcache3Stats.java

示例2: findValueStat

import org.terracotta.context.query.Matchers; //导入依赖的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");
}
 
开发者ID:ehcache,项目名称:ehcache3-samples,代码行数:23,代码来源:Ehcache3Stats.java

示例3: findOperationStat

import org.terracotta.context.query.Matchers; //导入依赖的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");
}
 
开发者ID:Terracotta-OSS,项目名称:statistics,代码行数:25,代码来源:MappedOperationStatistic.java

示例4: findStat

import org.terracotta.context.query.Matchers; //导入依赖的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");
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:24,代码来源:StoreStatisticsTest.java

示例5: findStatisticOnDescendants

import org.terracotta.context.query.Matchers; //导入依赖的package包/类
/**
 * Search for a statistic on the descendant of the context that matches the tag and statistic name.
 *
 * @param context the context of the query
 * @param discriminator a filter on the discriminator property
 * @param tag the tag we are looking for
 * @param statName statistic name
 * @param <T> type of the statistic that will be returned
 * @return the wanted statistic or null if no such statistic is found
 * @throws RuntimeException when more than one matching statistic is found
 */
static <T> Optional<T> findStatisticOnDescendants(Object context, String discriminator, String tag, String statName) {

  @SuppressWarnings("unchecked")
  Set<TreeNode> statResult = queryBuilder()
    .descendants()
    .filter(context(attributes(Matchers.allOf(
      hasAttribute("name", statName),
      hasProperty("discriminator", discriminator),
      hasTag(tag)))))
    .build().execute(Collections.singleton(ContextManager.nodeFor(context)));

  if (statResult.size() > 1) {
    throw new RuntimeException("One stat expected for " + statName + " but found " + statResult.size());
  }

  if (statResult.size() == 1) {
    @SuppressWarnings("unchecked")
    T result = (T) statResult.iterator().next().getContext().attributes().get("this");
    return Optional.ofNullable(result);
  }

  // No such stat in this context
  return Optional.empty();
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:36,代码来源:StatsUtils.java

示例6: findOperationStatisticOnChildren

import org.terracotta.context.query.Matchers; //导入依赖的package包/类
/**
 * Find an operation statistic attached (as a children) to this context that matches the statistic name and type
 *
 * @param context the context of the query
 * @param type type of the operation statistic
 * @param statName statistic name
 * @param <T> type of the operation statistic content
 * @return the operation statistic searched for
 * @throws RuntimeException if 0 or more than 1 result is found
 */
static <T extends Enum<T>> OperationStatistic<T> findOperationStatisticOnChildren(Object context, Class<T> type, String statName) {
  @SuppressWarnings("unchecked")
  Query query = queryBuilder()
    .children()
    .filter(context(attributes(Matchers.allOf(hasAttribute("name", statName), hasAttribute("type", type)))))
    .build();

  Set<TreeNode> result = query.execute(Collections.singleton(ContextManager.nodeFor(context)));
  if (result.size() > 1) {
    throw new RuntimeException("result must be unique");
  }
  if (result.isEmpty()) {
    throw new RuntimeException("result must not be null");
  }
  @SuppressWarnings("unchecked")
  OperationStatistic<T> statistic = (OperationStatistic<T>) result.iterator().next().getContext().attributes().get("this");
  return statistic;
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:29,代码来源:StatsUtils.java

示例7: registerStatistic

import org.terracotta.context.query.Matchers; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T extends Serializable> boolean registerStatistic(String statNameSuffix, ValueStatisticDescriptor descriptor) {
  // ignore registering through descriptors if we do not have a context object to find in the tree
  if (contextObject == null) {
    return false;
  }
  TreeNode treeNode = ContextManager.nodeFor(contextObject);
  if (treeNode == null) {
    return false;
  }

  Set<TreeNode> result = queryBuilder()
      .descendants()
      .filter(context(attributes(Matchers.allOf(
          hasAttribute("name", descriptor.getObserverName()),
          hasTags(descriptor.getTags())))))
      .filter(context(identifier(subclassOf(ValueStatistic.class))))
      .build().execute(Collections.singleton(treeNode));

  if (!result.isEmpty()) {
    for (TreeNode node : result) {
      String discriminator = null;

      Map<String, Object> properties = (Map<String, Object>) node.getContext().attributes().get("properties");
      if (properties != null && properties.containsKey("discriminator")) {
        discriminator = properties.get("discriminator").toString();
      }

      String fullStatName = (discriminator == null ? "" : (discriminator + ":")) + statNameSuffix;
      ValueStatistic<T> statistic = (ValueStatistic<T>) node.getContext().attributes().get("this");

      registerStatistic(fullStatName, statistic);
    }
    return true;
  } else {
    return false;
  }
}
 
开发者ID:Terracotta-OSS,项目名称:statistics,代码行数:39,代码来源:StatisticRegistry.java

示例8: findTiers

import org.terracotta.context.query.Matchers; //导入依赖的package包/类
/**
 * Find the list of tiers of a cache. We assume a lot of things here.
 * <ul>
 *   <li>The "eviction" statistic is available on the tier</li>
 *   <li>That the tiers have only one tag attribute</li>
 *   <li>That this tag contains the tier name</li>
 *   <li>That the only descendants having an "eviction" statistic are the tiers</li>
 * </ul>
 *
 * @param cache the context for looking for tiers
 * @return an array of tier names
 * @throws RuntimeException if not tiers are found or if tiers have multiple tags
 */
static String[] findTiers(Cache<?, ?> cache) {
  // Here I'm randomly taking the eviction observer because it exists on all tiers
  @SuppressWarnings("unchecked")
  Query statQuery = queryBuilder()
    .descendants()
    .filter(context(attributes(Matchers.allOf(hasAttribute("name", "eviction"), hasAttribute("type", StoreOperationOutcomes.EvictionOutcome.class)))))
    .build();

  Set<TreeNode> statResult = statQuery.execute(Collections.singleton(ContextManager.nodeFor(cache)));

  if (statResult.isEmpty()) {
    throw new RuntimeException("Failed to find tiers using the eviction observer, valid result Set sizes must 1 or more");
  }

  String[] tiers = new String[statResult.size()];

  int i = 0;
  for (TreeNode treeNode : statResult) {
    Set tags = (Set) treeNode.getContext().attributes().get("tags");
    if (tags.size() != 1) {
      throw new RuntimeException("We expect tiers to have only one tag");
    }

    String storeType = tags.iterator().next().toString();
    tiers[i++] = storeType;
  }
  return tiers;
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:42,代码来源:StatsUtils.java

示例9: queryProperty

import org.terracotta.context.query.Matchers; //导入依赖的package包/类
private Set<TreeNode> queryProperty(String tag) {
  @SuppressWarnings("unchecked")
  Query statQuery = queryBuilder()
    .descendants()
    .filter(context(attributes(Matchers.<Map<String, Object>>allOf(
      hasAttribute("name", "get"),
      hasTag(tag)
    ))))
    .build();

  return statQuery.execute(Collections.singleton(ContextManager.nodeFor(cache)));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:13,代码来源:StatsUtilsTest.java

示例10: testStatisticsAssociations

import org.terracotta.context.query.Matchers; //导入依赖的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());
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:33,代码来源:OffHeapDiskStoreProviderTest.java

示例11: main

import org.terracotta.context.query.Matchers; //导入依赖的package包/类
public static void main(String[] args) {
  CacheManager manager = new CacheManager("manager-one");
  Cache<String, String> cache = new Cache<>("cache-one");

  manager.addCache(cache);

  StatisticsManager stats = new StatisticsManager();
  stats.root(manager);

  @SuppressWarnings("unchecked")
  Query query = queryBuilder().descendants().filter(context(Matchers.allOf(identifier(subclassOf(OperationStatistic.class)), attributes(hasAttribute("name", "get"))))).build();
  System.out.println(query);
  TreeNode getStatisticNode = stats.queryForSingleton(query);

  @SuppressWarnings("unchecked")
  OperationStatistic<GetResult> getStatistic = (OperationStatistic<GetResult>) getStatisticNode.getContext().attributes().get("this");
  LatencySampling<GetResult> hitLatency = new LatencySampling<>(of(GetResult.HIT), 1.0f);
  MinMaxAverage hitLatencyStats = new MinMaxAverage();
  hitLatency.addDerivedStatistic(hitLatencyStats);
  getStatistic.addDerivedStatistic(hitLatency);

  cache.get("foo");
  System.err.println("HITS        : " + getStatistic.count(GetResult.HIT));
  System.err.println("MISSES      : " + getStatistic.count(GetResult.MISS));
  System.err.println("HIT LATENCY : " + hitLatencyStats.mean());

  cache.put("foo", "bar");
  cache.get("foo");
  System.err.println("HITS        : " + getStatistic.count(GetResult.HIT));
  System.err.println("MISSES      : " + getStatistic.count(GetResult.MISS));
  System.err.println("HIT LATENCY : " + hitLatencyStats.mean());

  hitLatency.addDerivedStatistic((time, parameters) -> System.out.println("Event Latency : " + parameters[0]));

  cache.get("foo");
  System.err.println("HITS        : " + getStatistic.count(GetResult.HIT));
  System.err.println("MISSES      : " + getStatistic.count(GetResult.MISS));
  System.err.println("HIT LATENCY : " + hitLatencyStats.mean());

  getStatistic.removeDerivedStatistic(hitLatency);

  cache.get("foo");
  System.err.println("HITS        : " + getStatistic.count(GetResult.HIT));
  System.err.println("MISSES      : " + getStatistic.count(GetResult.MISS));
  System.err.println("HIT LATENCY : " + hitLatencyStats.mean());
}
 
开发者ID:Terracotta-OSS,项目名称:statistics,代码行数:47,代码来源:Strawman.java


注:本文中的org.terracotta.context.query.Matchers类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。