Class RuleConstructor
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 ClassesModifier and TypeClassDescriptionfinal class
final class
final class
final class
final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
private String
private static final String
private String
private String
private static final String
private static AtomicReference
<Instrumentor> private String
private String
private String
private boolean
private boolean
private static final String
private String
private String
private String
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
RuleConstructor
(String ruleName) No use of constructor, new rule creation with:RuleConstructor.createRule("myRule")
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Builds the rule defined by this instance ofRuleConstructor
and returns its representation as string.static final RuleConstructor.ClassClause
createRule
(String ruleName) This is where you start.static final Instrumentor
Returning value of the previously set defaultInstrumentor
instance.(package private) String
install()
Installing/submitting rule to the Byteman agent via instance of instrumentor defined as default to theRuleConstructor
class.install
(Instrumentor instrumentor) Installing/submitting rule to the Byteman agent via instance of instrumentor.static final void
setDefaultInstrumentor
(Instrumentor instrumentor) Setting default initialize instance ofInstrumentor
class 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.
null
is permitted theninstall()
method throws exceptionprivate String
stringifyClauses
(String... clauses) private String
stringJoin
(String join, String... strings) submit()
Facade to methodinstall()
.submit
(Instrumentor instrumentor) Facade to methodinstall(Instrumentor)
.static final void
Undefinining value of default instrumentor.
-
Field Details
-
defaultInstrumentor
-
LINEBREAK
-
CONSTRUCTOR_METHOD
- See Also:
-
CLASS_CONSTRUCTOR
- See Also:
-
ruleName
-
className
-
isInterface
private boolean isInterface -
isIncludeSubclases
private boolean isIncludeSubclases -
methodName
-
helperName
-
where
-
bind
-
ifcondition
-
action
-
imports
-
compile
-
-
Constructor Details
-
RuleConstructor
No use of constructor, new rule creation with:RuleConstructor.createRule("myRule")
-
-
Method Details
-
setDefaultInstrumentor
Setting default initialize instance of
Instrumentor
class 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.
null
is permitted theninstall()
method throws exception- Parameters:
instrumentor
- initiated instrumentor instance or null
-
undefineDefaultInstrumentor
public static final void undefineDefaultInstrumentor() -
getDefaultInstrumentor
Returning value of the previously set defaultInstrumentor
instance.- Returns:
- instrumentor instance or null, when was not set
-
createRule
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
Installing/submitting rule to the Byteman agent via instance of instrumentor defined as default to the
RuleConstructor
class.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
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
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
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
Builds the rule defined by this instance ofRuleConstructor
and returns its representation as string.- Returns:
- the rule as a string
-
getRuleName
String getRuleName() -
stringJoin
-
stringifyClauses
-