Package org.jboss.byteman.rule
Class Rule
- java.lang.Object
-
- org.jboss.byteman.rule.Rule
-
public class Rule extends Object
A rule ties together an event, condition and action. It also maintains a TypeGroup identifying type information derived from these components.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
addAccessibleConstructorInvoker(Constructor constructor)
int
addAccessibleFieldGetter(Field field)
int
addAccessibleFieldSetter(Field field)
int
addAccessibleMethodInvoker(Method method)
void
compile()
install helper class used to execute this rule.static Rule
create(RuleScript ruleScript, ClassLoader loader, HelperManager helperManager, AccessEnabler accessEnabler)
static boolean
disableTriggers()
disable triggering of rules inside the current thread.static boolean
disableTriggersInternal()
disable triggering of rules inside the current thread.static boolean
enableTriggers()
enable triggering of rules inside the current thread.static boolean
enableTriggersInternal()
enable triggering of rules inside the current thread n.b.static void
execute(String key, Object recipient, Object[] args)
forward an execute request a rule identified by its unique keyObject
getAccessibleField(Object owner, int fieldIndex)
Action
getAction()
Bindings
getBindings()
Condition
getCondition()
Event
getEvent()
String
getFile()
retrieve the name of the file containing this ruleClass
getHelperClass()
a getter allowing the helper class for the rule to be identifiedString
getHelperImplementationClassName()
a getter allowing the helper implementation class name for the rule to be identifiedClassLoader
getHelperLoader()
get the class loader of the rule-specific helper adapter classString
getKey()
called when a trigger is compiled for the rule to provide a String key which can be used at execution time to obtain a handle on the rule instanceint
getLine()
retrieve the start line for the ruleClassLoader
getLoader()
get the class loader of the target class for the ruleModuleSystem
getModuleSystem()
String
getName()
long
getObjectSize(Object o)
Type
getReturnType()
String
getTargetClass()
Location
getTargetLocation()
String
getTargetMethod()
String
getTriggerClass()
String
getTriggerDescriptor()
String
getTriggerMethod()
TypeGroup
getTypeGroup()
void
installed()
method called when the rule has been successfully injected into a class, type checked and compiled.void
invokeAccessibleConstructor(Object[] args, int methodIndex)
Object
invokeAccessibleMethod(Object target, Object[] args, int methodIndex)
boolean
isChecked()
has this rule been typechecked and/or compiledboolean
isCheckedOk()
has this rule been typechecked and compiled without error.boolean
isCheckFailed()
has this rule failed to typecheck or compileboolean
isInterface()
boolean
isOverride()
static boolean
isTriggeringEnabled()
check if triggering of rules is enabled inside the current threadString
lookupKey()
return the key under which this rule has been indexed in the rule key mapvoid
purge()
delete any reference to the rule from the rule mapboolean
requiresAccess(Field field)
boolean
requiresAccess(Method method)
boolean
requiresAccess(Type type)
void
setAccessibleField(Object owner, Object value, int fieldIndex)
void
setAction(String actionSpec)
void
setCondition(String conditionSpec)
void
setEvent(String eventSpec)
void
setTypeInfo(String className, int access, String methodName, String desc, String[] exceptions)
String
toString()
generate a string representation of the rulevoid
typeCheck()
type check this rulevoid
uninstalled()
method called when the rule has been uninstalled after previously being successfully injected into a class, type checked and compiled.
-
-
-
Method Detail
-
getTypeGroup
public TypeGroup getTypeGroup()
-
getBindings
public Bindings getBindings()
-
getName
public String getName()
-
getTargetClass
public String getTargetClass()
-
getTargetMethod
public String getTargetMethod()
-
getTargetLocation
public Location getTargetLocation()
-
isOverride
public boolean isOverride()
-
isInterface
public boolean isInterface()
-
getLine
public int getLine()
retrieve the start line for the rule- Returns:
- the start line for the rule
-
getFile
public String getFile()
retrieve the name of the file containing this rule- Returns:
- the name of the file containing this rule
-
getEvent
public Event getEvent()
-
getCondition
public Condition getCondition()
-
getAction
public Action getAction()
-
getTriggerClass
public String getTriggerClass()
-
getTriggerMethod
public String getTriggerMethod()
-
getTriggerDescriptor
public String getTriggerDescriptor()
-
getReturnType
public Type getReturnType()
-
getLoader
public ClassLoader getLoader()
get the class loader of the target class for the rule- Returns:
- the class loader
-
getHelperLoader
public ClassLoader getHelperLoader()
get the class loader of the rule-specific helper adapter class- Returns:
- the class loader
-
create
public static Rule create(RuleScript ruleScript, ClassLoader loader, HelperManager helperManager, AccessEnabler accessEnabler) throws ParseException, TypeException, CompileException
-
setEvent
public void setEvent(String eventSpec) throws ParseException, TypeException
- Throws:
ParseException
TypeException
-
setCondition
public void setCondition(String conditionSpec) throws ParseException, TypeException
- Throws:
ParseException
TypeException
-
setAction
public void setAction(String actionSpec) throws ParseException, TypeException
- Throws:
ParseException
TypeException
-
setTypeInfo
public void setTypeInfo(String className, int access, String methodName, String desc, String[] exceptions)
-
isChecked
public boolean isChecked()
has this rule been typechecked and/or compiled- Returns:
- true if this rule has been typechecked and/or compiled otherwise false
-
isCheckFailed
public boolean isCheckFailed()
has this rule failed to typecheck or compile- Returns:
- true if this rule has failed to typecheck or compile otherwise false
-
isCheckedOk
public boolean isCheckedOk()
has this rule been typechecked and compiled without error.- Returns:
- true if this rule has been typechecked and compiled without error otherwise false
-
disableTriggersInternal
public static boolean disableTriggersInternal()
disable triggering of rules inside the current thread. this is the version called internally after returning from a method call in a rule binding, condition or action.- Returns:
- true if triggering was previously enabled and false if it was already disabled
-
enableTriggersInternal
public static boolean enableTriggersInternal()
enable triggering of rules inside the current thread n.b. this is called internally by the rule engine before it executes a method call in a rule binding, condition or action. it will not enable triggers if they have been switched off by an earlier call to userDisableTriggers.- Returns:
- true if triggering was previously enabled and false if it was already disabled
-
disableTriggers
public static boolean disableTriggers()
disable triggering of rules inside the current thread. this is the version which should be called from a Helper class to ensure that subsequent method invocatiosn during execution of the current rule bindings, condition or action do not recursively trigger rules. It ensures that subsequent calls to enableTriggers have no effect. The effect lasts until the end of processing for the current rule when resetTriggers is called.- Returns:
- true if triggering was previously enabled and false if it was already disabled
-
enableTriggers
public static boolean enableTriggers()
enable triggering of rules inside the current thread. this is called internally by the rule engine after rule execution has completed. it will re-enable triggers even if they have been switched off by an earlier call to userDisableTriggers. It is also called by the default helper to reverse the effect of calling userDisableTriggers.- Returns:
- true if triggering was previously enabled and false if it was already disabled
-
isTriggeringEnabled
public static boolean isTriggeringEnabled()
check if triggering of rules is enabled inside the current thread- Returns:
- true if triggering is enabled and false if it is disabled
-
typeCheck
public void typeCheck() throws TypeException
type check this rule- Throws:
TypeException
- if the rule contains type errors
-
getModuleSystem
public ModuleSystem getModuleSystem()
-
compile
public void compile() throws CompileException
install helper class used to execute this rule. this may involve generating a compiled helper class for the rule and, if compilation to bytecode is enabled, generating bytecode for a method of this class used to execute the rule binding, condition and action expressions. If the rule employ sthe default helper without enabling compilation to bytecode then no class need be generated. the installed helper class will be the predefined class InterpretedHelper.- Throws:
CompileException
- if the rule cannot be compiled
-
execute
public static void execute(String key, Object recipient, Object[] args) throws ExecuteException
forward an execute request a rule identified by its unique key- Parameters:
key
- a string key identifying the rule instance to be firedrecipient
- the recipient of the method from which execution of the rule was triggered or null if it was a static methodargs
- the arguments of the method from which execution of the rule was triggered- Throws:
ExecuteException
-
getKey
public String getKey()
called when a trigger is compiled for the rule to provide a String key which can be used at execution time to obtain a handle on the rule instance- Returns:
- a key which can be used later to obtain a reference to the rule
-
lookupKey
public String lookupKey()
return the key under which this rule has been indexed in the rule key map- Returns:
- the key
-
purge
public void purge()
delete any reference to the rule from the rule map
-
toString
public String toString()
generate a string representation of the rule
-
getHelperClass
public Class getHelperClass()
a getter allowing the helper class for the rule to be identified- Returns:
- the helper
-
getHelperImplementationClassName
public String getHelperImplementationClassName()
a getter allowing the helper implementation class name for the rule to be identified- Returns:
- the helper
-
installed
public void installed()
method called when the rule has been successfully injected into a class, type checked and compiled. it passes the message on to the Transformer so it can perform helper lifecycle management.
-
uninstalled
public void uninstalled()
method called when the rule has been uninstalled after previously being successfully injected into a class, type checked and compiled. it passes the message on to the Transformer so it can perform helper lifecycle management.
-
requiresAccess
public boolean requiresAccess(Type type)
-
requiresAccess
public boolean requiresAccess(Field field)
-
requiresAccess
public boolean requiresAccess(Method method)
-
addAccessibleFieldGetter
public int addAccessibleFieldGetter(Field field)
-
addAccessibleFieldSetter
public int addAccessibleFieldSetter(Field field)
-
addAccessibleMethodInvoker
public int addAccessibleMethodInvoker(Method method)
-
addAccessibleConstructorInvoker
public int addAccessibleConstructorInvoker(Constructor constructor)
-
getAccessibleField
public Object getAccessibleField(Object owner, int fieldIndex) throws ExecuteException
- Throws:
ExecuteException
-
setAccessibleField
public void setAccessibleField(Object owner, Object value, int fieldIndex) throws ExecuteException
- Throws:
ExecuteException
-
invokeAccessibleMethod
public Object invokeAccessibleMethod(Object target, Object[] args, int methodIndex)
-
invokeAccessibleConstructor
public void invokeAccessibleConstructor(Object[] args, int methodIndex)
-
getObjectSize
public long getObjectSize(Object o)
-
-