public 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;
  }
public static String [ ] findTiers ( Cache < ? , ? > cache ) { @ 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 ; }
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