org.terracotta.context.query.Query.execute()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(85)

本文整理了Java中org.terracotta.context.query.Query.execute方法的一些代码示例,展示了Query.execute的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.execute方法的具体详情如下:
包路径:org.terracotta.context.query.Query
类名称:Query
方法名:execute

Query.execute介绍

[英]Transforms the input node set in to an output node set.
[中]将输入节点集转换为输出节点集。

代码示例

代码示例来源:origin: ehcache/ehcache3

/**
 * 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 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
 */
public static <T> Optional<T> findStatisticOnDescendants(Object context, String tag, String statName) {
 @SuppressWarnings("unchecked")
 Set<TreeNode> statResult = queryBuilder()
  .descendants()
  .filter(context(attributes(Matchers.allOf(
   hasAttribute("name", statName),
   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();
}

代码示例来源:origin: ehcache/ehcache3

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

代码示例来源:origin: ehcache/ehcache3

/**
 * 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
 */
public 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;
}

代码示例来源:origin: ehcache/ehcache3

hasProperty("discriminator", discriminator),
 hasTag(tag)))))
.build().execute(Collections.singleton(ContextManager.nodeFor(context)));

代码示例来源:origin: ehcache/ehcache3

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();
 }
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
   * {@inheritDoc}
   */
  @Override
  public Set<TreeNode> execute(Set<TreeNode> input) {
    return query.execute(input);
  }
}

代码示例来源:origin: net.sf.ehcache/ehcache

@Override
public final Set<TreeNode> execute(Set<TreeNode> input) {
 return current.execute(previous.execute(input));
}

代码示例来源:origin: ehcache/ehcache3

@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)");
 }
}

代码示例来源:origin: net.sf.ehcache/ehcache

@Override
public Set<TreeNode> execute(Set<TreeNode> input) {
 Set<TreeNode> descendants = new HashSet<TreeNode>();
 for (Set<TreeNode> children = Children.INSTANCE.execute(input); !children.isEmpty(); children = Children.INSTANCE.execute(children)) {
  if (!descendants.addAll(children)) {
   break;
  }
 }
 return descendants;
}

代码示例来源:origin: ehcache/ehcache3

@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.allOf(
   hasAttribute("tags", new Matcher<Set<String>>() {
    @Override
    protected boolean matchesSafely(Set<String> object) {
     return object.contains("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());
 }

代码示例来源:origin: ehcache/ehcache3

@SuppressWarnings("unchecked")
private Set<TreeNode> queryProperty(String key, String value) {
 Query statQuery = queryBuilder()
  .descendants()
  .filter(context(attributes(Matchers.<Map<String, Object>>allOf(
   hasAttribute("name", "test"),
   hasProperty(key, value)
  ))))
  .build();
 return statQuery.execute(Collections.singleton(ContextManager.nodeFor(cache)));
}

代码示例来源:origin: ehcache/ehcache3

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)));
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * Run the supplied {@code Query} against this {@code ContextManager}'s 
 * root context.
 * <p>
 * The initial node in the queries traversal will be the node whose children
 * form the root set of this {@code ContextManager}.  That is, the following
 * code will select the root set of this instance.<br>
 * <pre>
 * public static Set<TreeNode> roots(ContextManager manager) {
 *   return manager.query(QueryBuilder.queryBuilder().children().build());
 * }
 * </pre>
 * 
 * @param query the query to execute
 * @return the set of nodes selected by the query
 */
public Set<TreeNode> query(Query query) {
 return query.execute(Collections.<TreeNode>singleton(root));
}

代码示例来源:origin: ehcache/ehcache3

.execute(singleton(nodeFor(cache)))
.iterator()
.next()

代码示例来源:origin: net.sf.ehcache/ehcache

return object.containsAll(tags);
}))))).build().execute(passThroughStatisticNodes);

代码示例来源:origin: org.sonatype.nexus.bundles/org.sonatype.nexus.bundles.ehcache

/**
   * {@inheritDoc}
   */
  @Override
  public Set<TreeNode> execute(Set<TreeNode> input) {
    return query.execute(input);
  }
}

代码示例来源:origin: net.sf.ehcache/ehcache

return object.containsAll(tags);
}))))).build().execute(operationStatisticNodes);

代码示例来源:origin: org.terracotta/statistics

@Override
public Set<TreeNode> execute(Set<TreeNode> input) {
 Set<TreeNode> descendants = new HashSet<>();
 for (Set<TreeNode> children = Children.INSTANCE.execute(input); !children.isEmpty(); children = Children.INSTANCE.execute(children)) {
  if (!descendants.addAll(children)) {
   break;
  }
 }
 return descendants;
}

代码示例来源:origin: org.sonatype.nexus.bundles/org.sonatype.nexus.bundles.ehcache

@Override
public Set<TreeNode> execute(Set<TreeNode> input) {
 Set<TreeNode> descendants = new HashSet<TreeNode>();
 for (Set<TreeNode> children = Children.INSTANCE.execute(input); !children.isEmpty(); children = Children.INSTANCE.execute(children)) {
  if (!descendants.addAll(children)) {
   break;
  }
 }
 return descendants;
}

代码示例来源:origin: org.terracotta.internal/statistics

@Override
public Set<TreeNode> execute(Set<TreeNode> input) {
 Set<TreeNode> descendants = new HashSet<TreeNode>();
 for (Set<TreeNode> children = Children.INSTANCE.execute(input); !children.isEmpty(); children = Children.INSTANCE.execute(children)) {
  if (!descendants.addAll(children)) {
   break;
  }
 }
 return descendants;
}

相关文章