Class CallerMatcher

java.lang.Object
org.apache.solr.util.CallerMatcher

public class CallerMatcher extends Object
Helper class to collect interesting callers at specific points. These calling points are identified by the calling class' simple name and optionally a method name and the optional maximum count, e.g. MoreLikeThisComponent or ClusteringComponent.finishStage , ClusteringComponent.finishStage:100. A single wildcard name * may be used to mean "any class", which may be useful to e.g. collect all callers using an expression *:-1.

Within your caller you should invoke checkCaller() to count any matching frames in the current stack, and check if any of the count limits has been reached. Each invocation will increase the call count of the matching expression(s). For one invocation multiple matching expression counts can be affected because all current stack frames are examined against the matching expressions.

NOTE: implementation details cause the expression simpleName[:NNN] to be disabled when also any simpleName.anyMethod[:NNN] expression is used for the same class name.

NOTE 2: when maximum count is a negative number e.g. simpleName[.someMethod]:-1 then only the number of calls to checkCaller() for the matching expressions will be reported but checkCaller() will never return this expression.

  • Field Details

  • Constructor Details

    • CallerMatcher

      public CallerMatcher(Collection<String> callerExprs, Collection<String> excludeExprs)
      Create an instance that reacts to the specified caller expressions.
      Parameters:
      callerExprs - list of expressions in the format of ( simpleClassName[.methodName] | * )[:NNN]. If the list is empty or null then the first call to checkCaller() ()} from any caller will match.
  • Method Details

    • getTrippedBy

      public Set<String> getTrippedBy()
      Returns the set of caller expressions that were tripped (reached their count limit). This method can be called after checkCaller() returns a matching expression to obtain all expressions that exceeded their count limits.
    • getCallCounts

      public Map<String,Integer> getCallCounts()
      Returns a map of matched caller expressions to their current call counts.
    • checkCaller

      public Optional<String> checkCaller()
      Returns the matching caller expression when its count limit was reached, or empty if no caller or no count limit was reached. Each invocation increases the call count of the matching caller, if any. It's up to the caller to decide whether to continue processing after this count limit is reached. The matching expression returned by this call will be also present in getTrippedBy().