Example #1
0
  /** Associate Advice to all n-cubes that match the passed in regular expression. */
  public static void addAdvice(ApplicationID appId, String wildcard, Advice advice) {
    validateAppId(appId);
    ConcurrentMap<String, Advice> current = advices.get(appId);
    if (current == null) {
      current = new ConcurrentHashMap<>();
      ConcurrentMap<String, Advice> mapRef = advices.putIfAbsent(appId, current);
      if (mapRef != null) {
        current = mapRef;
      }
    }

    current.put(advice.getName() + '/' + wildcard, advice);

    // Apply newly added advice to any fully loaded (hydrated) cubes.
    String regex = StringUtilities.wildcardToRegexString(wildcard);
    Map<String, Object> cubes = getCacheForApp(appId);

    for (Object value : cubes.values()) {
      if (value instanceof NCube) { // apply advice to hydrated cubes
        NCube ncube = (NCube) value;
        Axis axis = ncube.getAxis("method");
        addAdviceToMatchedCube(advice, regex, ncube, axis);
      }
    }
  }
Example #2
0
  /**
   * Apply existing advices loaded into the NCubeManager, to the passed in n-cube. This allows
   * advices to be added first, and then let them be applied 'on demand' as an n-cube is loaded
   * later.
   *
   * @param appId ApplicationID
   * @param ncube NCube to which all matching advices will be applied.
   */
  private static void applyAdvices(ApplicationID appId, NCube ncube) {
    final Map<String, Advice> appAdvices = advices.get(appId);

    if (MapUtilities.isEmpty(appAdvices)) {
      return;
    }
    for (Map.Entry<String, Advice> entry : appAdvices.entrySet()) {
      final Advice advice = entry.getValue();
      final String wildcard = entry.getKey().replace(advice.getName() + '/', "");
      final String regex = StringUtilities.wildcardToRegexString(wildcard);
      final Axis axis = ncube.getAxis("method");
      addAdviceToMatchedCube(advice, regex, ncube, axis);
    }
  }