Class RuleConstructor
- java.lang.Object
-
- org.jboss.byteman.contrib.dtest.RuleConstructor
-
public final class RuleConstructor extends java.lang.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 class
RuleConstructor.ActionClause
class
RuleConstructor.ClassClause
class
RuleConstructor.ConditionClause
class
RuleConstructor.LocationClause
class
RuleConstructor.MethodClause
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
action
private java.lang.String
bind
private static java.lang.String
CLASS_CONSTRUCTOR
private java.lang.String
className
private java.lang.String
compile
private static java.lang.String
CONSTRUCTOR_METHOD
private static java.util.concurrent.atomic.AtomicReference<Instrumentor>
defaultInstrumentor
private java.lang.String
helperName
private java.lang.String
ifcondition
private java.lang.String
imports
private boolean
isIncludeSubclases
private boolean
isInterface
private static java.lang.String
LINEBREAK
private java.lang.String
methodName
private java.lang.String
ruleName
private java.lang.String
where
-
Constructor Summary
Constructors Modifier Constructor Description private
RuleConstructor(java.lang.String ruleName)
No use of constructor, new rule creation with:RuleConstructor.createRule("myRule")
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
build()
Builds the rule defined by this instance ofRuleConstructor
and returns its representation as string.static RuleConstructor.ClassClause
createRule(java.lang.String ruleName)
This is where you start.static Instrumentor
getDefaultInstrumentor()
Returning value of the previously set defaultInstrumentor
instance.(package private) java.lang.String
getRuleName()
RuleConstructor
install()
Installing/submitting rule to the Byteman agent via instance of instrumentor defined as default to theRuleConstructor
class.RuleConstructor
install(Instrumentor instrumentor)
Installing/submitting rule to the Byteman agent via instance of instrumentor.static 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 java.lang.String
stringifyClauses(java.lang.String... clauses)
private java.lang.String
stringJoin(java.lang.String join, java.lang.String... strings)
RuleConstructor
submit()
Facade to methodinstall()
.RuleConstructor
submit(Instrumentor instrumentor)
Facade to methodinstall(Instrumentor)
.static void
undefineDefaultInstrumentor()
Undefinining value of default instrumentor.
-
-
-
Field Detail
-
defaultInstrumentor
private static java.util.concurrent.atomic.AtomicReference<Instrumentor> defaultInstrumentor
-
LINEBREAK
private static final java.lang.String LINEBREAK
-
CONSTRUCTOR_METHOD
private static final java.lang.String CONSTRUCTOR_METHOD
- See Also:
- Constant Field Values
-
CLASS_CONSTRUCTOR
private static final java.lang.String CLASS_CONSTRUCTOR
- See Also:
- Constant Field Values
-
ruleName
private java.lang.String ruleName
-
className
private java.lang.String className
-
isInterface
private boolean isInterface
-
isIncludeSubclases
private boolean isIncludeSubclases
-
methodName
private java.lang.String methodName
-
helperName
private java.lang.String helperName
-
where
private java.lang.String where
-
bind
private java.lang.String bind
-
ifcondition
private java.lang.String ifcondition
-
action
private java.lang.String action
-
imports
private java.lang.String imports
-
compile
private java.lang.String compile
-
-
Method Detail
-
setDefaultInstrumentor
public static final void setDefaultInstrumentor(Instrumentor instrumentor)
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
public static final Instrumentor getDefaultInstrumentor()
Returning value of the previously set defaultInstrumentor
instance.- Returns:
- instrumentor instance or null, when was not set
-
createRule
public static final RuleConstructor.ClassClause createRule(java.lang.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:
- 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:
java.lang.IllegalStateException
- if default instrumentor is not setjava.lang.RuntimeException
- 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:
java.lang.NullPointerException
- if instrumentor param is provided as nulljava.lang.RuntimeException
- 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:
java.lang.IllegalStateException
- if default instrumentor is not setjava.lang.RuntimeException
- 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:
java.lang.NullPointerException
- if instrumentor param is provided as nulljava.lang.RuntimeException
- if error happens during installation rule
-
build
public java.lang.String build()
Builds the rule defined by this instance ofRuleConstructor
and returns its representation as string.- Returns:
- the rule as a string
-
getRuleName
java.lang.String getRuleName()
-
stringJoin
private java.lang.String stringJoin(java.lang.String join, java.lang.String... strings)
-
stringifyClauses
private java.lang.String stringifyClauses(java.lang.String... clauses)
-
-