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


Java Query类代码示例

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


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

示例1: findOperationStat

import org.terracotta.context.query.Query; //导入依赖的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.Query; //导入依赖的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.Query; //导入依赖的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: testClean

import org.terracotta.context.query.Query; //导入依赖的package包/类
@Test
public void testClean() {
  StatisticsManager.createPassThroughStatistic(this, "mystat",
      Collections.emptySet(), COUNTER, () -> 12);

  assertTrue(PassThroughStatistic.hasStatisticsFor(this));

  StatisticsManager.nodeFor(this).clean();

  assertFalse(PassThroughStatistic.hasStatisticsFor(this));

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

  Query query = queryBuilder().descendants().filter(context(attributes(hasAttribute("name", "mystat")))).build();
  Set<TreeNode> nodes = manager.query(query);
  assertThat(nodes, IsEmptyCollection.empty());
}
 
开发者ID:Terracotta-OSS,项目名称:statistics,代码行数:19,代码来源:PassThroughStatisticTest.java

示例5: findStat

import org.terracotta.context.query.Query; //导入依赖的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

示例6: findOperationStatisticOnChildren

import org.terracotta.context.query.Query; //导入依赖的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: findTiers

import org.terracotta.context.query.Query; //导入依赖的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

示例8: queryProperty

import org.terracotta.context.query.Query; //导入依赖的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

示例9: testStatisticsAssociations

import org.terracotta.context.query.Query; //导入依赖的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

示例10: main

import org.terracotta.context.query.Query; //导入依赖的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

示例11: queryForSingleton

import org.terracotta.context.query.Query; //导入依赖的package包/类
/**
 * Return the unique node selected by running this query against this
 * {@code ContextManager}'s root context.
 * <p>
 * If this query does not return a single unique result then an
 * {@code IllegalStateException} will be thrown.  More details on the query
 * execution context can be found in {@link #query(Query)}.
 *
 * @param query the query to execute
 * @return the node selected by the query
 * @throws IllegalStateException if the query does not select a unique node
 * @see #query(Query)
 * @see QueryBuilder#ensureUnique()
 */
public TreeNode queryForSingleton(Query query) throws IllegalStateException {
  return query(queryBuilder().chain(query).ensureUnique().build()).iterator().next();
}
 
开发者ID:Terracotta-OSS,项目名称:statistics,代码行数:18,代码来源:ContextManager.java


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