Class RuleConstructor

java.lang.Object
org.jboss.byteman.contrib.dtest.RuleConstructor

public final class RuleConstructor extends Object

Provides a fluent API for creating Byteman rules without needing to mess around with String concatenation.

Example:

RuleConstructor rb = RuleConstructor.createRule("myRule")
.onClass("org.jboss.byteman.ExampleClass")
.inMethod("doInterestingStuff")
.atEntry()
.ifTrue()
.doAction("myAction()");
System.out.println(rb.build());

will print:

RULE myRule
CLASS org.jboss.byteman.ExampleClass
METHOD doInterestingStuff
AT ENTRY
IF true
DO myAction()
ENDRULE

  • Field Details

    • defaultInstrumentor

      private static AtomicReference<Instrumentor> defaultInstrumentor
    • LINEBREAK

      private static final String LINEBREAK
    • CONSTRUCTOR_METHOD

      private static final String CONSTRUCTOR_METHOD
      See Also:
    • CLASS_CONSTRUCTOR

      private static final String CLASS_CONSTRUCTOR
      See Also:
    • ruleName

      private String ruleName
    • className

      private String className
    • isInterface

      private boolean isInterface
    • isIncludeSubclases

      private boolean isIncludeSubclases
    • methodName

      private String methodName
    • helperName

      private String helperName
    • where

      private String where
    • bind

      private String bind
    • ifcondition

      private String ifcondition
    • action

      private String action
    • imports

      private String imports
    • compile

      private String compile
  • Constructor Details

    • RuleConstructor

      private RuleConstructor(String ruleName)
      No use of constructor, new rule creation with: RuleConstructor.createRule("myRule")
  • Method Details

    • setDefaultInstrumentor

      public static final void setDefaultInstrumentor(Instrumentor instrumentor)

      Setting default initialize instance of Instrumentor class that will be used when install()/submit() method is used for the created rule.
      You can define this default Instrumentor which could be used whenever the new rule is submitted to the Byteman agent.
      null is permitted then install() method throws exception

      Parameters:
      instrumentor - initiated instrumentor instance or null
    • undefineDefaultInstrumentor

      public static final void undefineDefaultInstrumentor()
      Undefinining value of default instrumentor. Methods install()/submit() are illegal to be used from now up to time it's set again.
    • getDefaultInstrumentor

      public static final Instrumentor getDefaultInstrumentor()
      Returning value of the previously set default Instrumentor instance.
      Returns:
      instrumentor instance or null, when was not set
    • createRule

      public static final RuleConstructor.ClassClause createRule(String ruleName)

      This is where you start.

      Byteman rule builder initialization method.

      Parameters:
      ruleName - name of rule is required to construct any rule
      Returns:
      a rule constructor ready to have its class or interface specified
    • install

      public RuleConstructor install()

      Installing/submitting rule to the Byteman agent via instance of instrumentor defined as default to the RuleConstructor class.

      Internally this:


      Prerequisite: you need set up the instrumentor by call setDefaultInstrumentor(Instrumentor)
      Returns:
      rule constructor if expected to be used later again
      Throws:
      IllegalStateException - if default instrumentor is not set
      RuntimeException - if error happens during installation rule via default instrumentor instance
    • install

      public RuleConstructor install(Instrumentor instrumentor)

      Installing/submitting rule to the Byteman agent via instance of instrumentor.

      Internally this:

      Parameters:
      instrumentor - instance of instrumentor to be used to submit the rule to
      Returns:
      rule constructor if expected to be used later again
      Throws:
      NullPointerException - if instrumentor param is provided as null
      RuntimeException - if error happens during installation rule via default instrumentor instance
    • submit

      public RuleConstructor submit()
      Facade to method install().
      Returns:
      rule constructor, if expected to be used later again
      Throws:
      IllegalStateException - if default instrumentor is not set
      RuntimeException - if error happens during installation rule
    • submit

      public RuleConstructor submit(Instrumentor instrumentor)
      Facade to method install(Instrumentor).
      Parameters:
      instrumentor - instance of instrumentor to be used to submit the rule to
      Returns:
      rule constructor, if expected to be used later again
      Throws:
      NullPointerException - if instrumentor param is provided as null
      RuntimeException - if error happens during installation rule
    • build

      public String build()
      Builds the rule defined by this instance of RuleConstructor and returns its representation as string.
      Returns:
      the rule as a string
    • getRuleName

      String getRuleName()
    • stringJoin

      private String stringJoin(String join, String... strings)
    • stringifyClauses

      private String stringifyClauses(String... clauses)