Class BlockHound.Builder

java.lang.Object
reactor.blockhound.BlockHound.Builder
Enclosing class:
BlockHound

public static class BlockHound.Builder extends Object
  • Method Details

    • markAsBlocking

      public BlockHound.Builder markAsBlocking(Class clazz, String methodName, String signature)
      Marks provided method of the provided class as "blocking". The descriptor should be in JVM's format: https://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/types.html#wp276
      Parameters:
      clazz - a class reference
      methodName - a method name
      signature - a method descriptor in JVM's format
      Returns:
      this
    • markAsBlocking

      public BlockHound.Builder markAsBlocking(String className, String methodName, String signature)
      Marks provided method of the class identified by the provided name as "blocking". The descriptor should be in JVM's format: https://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/types.html#wp276
      Parameters:
      className - class' name (e.g. "java.lang.Thread")
      methodName - a method name
      signature - a method signature (in JVM's format)
      Returns:
      this
    • allowBlockingCallsInside

      public BlockHound.Builder allowBlockingCallsInside(String className, String methodName)
      Allows blocking calls inside any method of a class with name identified by the provided className and which name matches the provided methodName.

      There are two special cases for methodName:

      • static initializers are currently supported by their JVM reserved name of "<clinit>"
      • constructors are currently not supported (ByteBuddy cannot weave the necessary instrumentation around a constructor that throws an exception, see gh174)
      Parameters:
      className - class' name (e.g. "java.lang.Thread")
      methodName - a method name
      Returns:
      this
    • disallowBlockingCallsInside

      public BlockHound.Builder disallowBlockingCallsInside(String className, String methodName)
      Disallows blocking calls inside any method of a class with name identified by the provided className and which name matches the provided methodName.

      There are two special cases for methodName:

      • static initializers are currently supported by their JVM reserved name of "<clinit>"
      • constructors are currently not supported (ByteBuddy cannot weave the necessary instrumentation around a constructor that throws an exception, see gh174)
      Parameters:
      className - class' name (e.g. "java.lang.Thread")
      methodName - a method name
      Returns:
      this
    • blockingMethodCallback

      public BlockHound.Builder blockingMethodCallback(Consumer<BlockingMethod> consumer)
      Overrides the callback that is being triggered when a blocking method is detected
      Parameters:
      consumer - a consumer of the detected blocking method call's description (BlockingMethod).
      Returns:
      this
    • nonBlockingThreadPredicate

      public BlockHound.Builder nonBlockingThreadPredicate(Function<Predicate<Thread>,Predicate<Thread>> function)
      Replaces the current non-blocking thread predicate with the result of applying the provided function. Warning! Consider always using Predicate.or(Predicate) and not override the previous one: nonBlockingThreadPredicate(current -> current.or(MyMarker.class::isInstance))
      Parameters:
      function - a function to immediately apply on the current instance of the predicate
      Returns:
      this
    • dynamicThreadPredicate

      public BlockHound.Builder dynamicThreadPredicate(Function<Predicate<Thread>,Predicate<Thread>> function)
      Replaces the current dynamic thread predicate with the result of applying the provided function. Warning! Consider always using Predicate.or(Predicate) and not override the previous one: dynamicThreadPredicate(current -> current.or(MyMarker.class::isInstance))
      Parameters:
      function - a function to immediately apply on the current instance of the predicate
      Returns:
      this
    • addDynamicThreadPredicate

      public BlockHound.Builder addDynamicThreadPredicate(Predicate<Thread> predicate)
      Appends the provided predicate to the current one.
      Parameters:
      predicate - a predicate to append to the current instance of the predicate
      Returns:
      this
    • loadIntegrations

      public BlockHound.Builder loadIntegrations(BlockHoundIntegration... integrations)
      Loads integrations with ServiceLoader and adds provided integrations using {with(BlockHoundIntegration)}. If you don't want to load the integrations using service loader, only use with(BlockHoundIntegration) method.
      Parameters:
      integrations - an array of integrations to automatically apply on the builder using with(BlockHoundIntegration)
      Returns:
      this
      See Also:
    • with

      public BlockHound.Builder with(BlockHoundIntegration integration)
      Applies the provided BlockHoundIntegration to the current builder
      Parameters:
      integration - an integration to apply
      Returns:
      this
    • with

      public BlockHound.Builder with(Instrumentation instrumentation)
      Configure the Instrumentation to use. If not provided, ByteBuddyAgent.install() is used.
      Parameters:
      instrumentation - The instrumentation instance to use.
      Returns:
      this
    • install

      public void install()
      Installs the agent and runs the instrumentation, but only if BlockHound wasn't installed yet (it is global).