/** * 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; }
@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()); }
/** * Select the children of the current node set * * @return children */ EhcacheQuery children() { return new EhcacheQuery(queryBuilder().chain(query).children().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()); }
Set<TreeNode> passThroughStatisticNodes = manager.query(queryBuilder().chain(contextQuery).children() .filter(context(identifier(subclassOf(ValueStatistic.class)))).build()); Set<TreeNode> result = queryBuilder()
Set<TreeNode> operationStatisticNodes = manager.query(queryBuilder().chain(contextQuery).children() .filter(context(identifier(subclassOf(OperationStatistic.class)))).build()); Set<TreeNode> result = queryBuilder()
/** * Creates a query selecting all children. * * @return children query */ public static Query children() { return queryBuilder().children().build(); }
/** * Select the children of the current node set * * @return children */ EhcacheQuery children() { return new EhcacheQuery(queryBuilder().chain(query).children().build()); }
/** * Select the children of the current node set * * @return children */ EhcacheQuery children() { return new EhcacheQuery(queryBuilder().chain(query).children().build()); }
/** * 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; }
/** * 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()); }
Set<TreeNode> passThroughStatisticNodes = manager.query(queryBuilder().chain(contextQuery).children() .filter(context(identifier(subclassOf(ValueStatistic.class)))).build()); Set<TreeNode> result = queryBuilder()
Set<TreeNode> passThroughStatisticNodes = manager.query(queryBuilder().chain(contextQuery).children() .filter(context(identifier(subclassOf(ValueStatistic.class)))).build()); Set<TreeNode> result = queryBuilder()
Set<TreeNode> operationStatisticNodes = manager.query(queryBuilder().chain(contextQuery).children() .filter(context(identifier(subclassOf(OperationStatistic.class)))).build()); Set<TreeNode> result = queryBuilder()
Set<TreeNode> operationStatisticNodes = manager.query(queryBuilder().chain(contextQuery).children() .filter(context(identifier(subclassOf(OperationStatistic.class)))).build()); Set<TreeNode> result = queryBuilder()