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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classRuleConstructor.ActionClauseclassRuleConstructor.ClassClauseclassRuleConstructor.ConditionClauseclassRuleConstructor.LocationClauseclassRuleConstructor.MethodClause
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Stringbuild()Builds the rule defined by this instance ofRuleConstructorand returns its representation as string.static RuleConstructor.ClassClausecreateRule(String ruleName)This is where you start.static InstrumentorgetDefaultInstrumentor()Returning value of the previously set defaultInstrumentorinstance.RuleConstructorinstall()Installing/submitting rule to the Byteman agent via instance of instrumentor defined as default to theRuleConstructorclass.RuleConstructorinstall(Instrumentor instrumentor)Installing/submitting rule to the Byteman agent via instance of instrumentor.static voidsetDefaultInstrumentor(Instrumentor instrumentor)Setting default initialize instance ofInstrumentorclass that will be used wheninstall()/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.
nullis permitted theninstall()method throws exceptionRuleConstructorsubmit()Facade to methodinstall().RuleConstructorsubmit(Instrumentor instrumentor)Facade to methodinstall(Instrumentor).static voidundefineDefaultInstrumentor()Undefinining value of default instrumentor.
-
-
-
Method Detail
-
setDefaultInstrumentor
public static final void setDefaultInstrumentor(Instrumentor instrumentor)
Setting default initialize instance of
Instrumentorclass that will be used wheninstall()/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.
nullis permitted theninstall()method throws exception- Parameters:
instrumentor- initiated instrumentor instance or null
-
undefineDefaultInstrumentor
public static final void undefineDefaultInstrumentor()
-
getDefaultInstrumentor
public static final Instrumentor getDefaultInstrumentor()
Returning value of the previously set defaultInstrumentorinstance.- Returns:
- instrumentor instance or null, when was not set
-
createRule
public static final RuleConstructor.ClassClause createRule(String ruleName)
This is where you start.
Bytemanrule 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
RuleConstructorclass.Internally this:
- build the rule where
build()is called to generate rule asString - calling submit of the rule over instance of
Instrumentor
Prerequisite: you need set up the instrumentor by callsetDefaultInstrumentor(Instrumentor)- Returns:
- rule constructor if expected to be used later again
- Throws:
IllegalStateException- if default instrumentor is not setRuntimeException- if error happens during installation rule via default instrumentor instance
- build the rule where
-
install
public RuleConstructor install(Instrumentor instrumentor)
Installing/submitting rule to the Byteman agent via instance of instrumentor.
Internally this:
- build the rule where
build()is called to generate rule asString - calling submit of the rule over instance of
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 nullRuntimeException- if error happens during installation rule via default instrumentor instance
- build the rule where
-
submit
public RuleConstructor submit()
Facade to methodinstall().- Returns:
- rule constructor, if expected to be used later again
- Throws:
IllegalStateException- if default instrumentor is not setRuntimeException- if error happens during installation rule
-
submit
public RuleConstructor submit(Instrumentor instrumentor)
Facade to methodinstall(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 nullRuntimeException- if error happens during installation rule
-
build
public String build()
Builds the rule defined by this instance ofRuleConstructorand returns its representation as string.- Returns:
- the rule as a string
-
-