public TransformSet ensureTransformSet(ClassLoader loader, String triggerClass, Rule installedRule) { TransformSet transformSet = lookupTransformSet(loader, triggerClass); if (transformSet == null) { transformSet = new TransformSet(loader, triggerClass); transformSet.setInstalled(installedRule); transformSets.add(transformSet); } return transformSet; }
public boolean isInstalled() { return getInstalledRule() != null; }
public List<Transform> allTransforms() { List<Transform> allTransforms = new ArrayList<Transform>(); for (TransformSet transformSet : transformSets) { allTransforms.addAll(transformSet.getTransforms()); } return allTransforms; }
/** * check whether a rule has been used to transform a specific class. this can be used when * rules are redefined to decide whether or not a class needs to be retransformed. Note that * it must only be called after the script has been deleted by calling setDeleted. * @param clazz the class for which a transform is being sought. * @return true if the class has been transformed using this script otherwise false. */ public synchronized boolean hasTransform(Class<?> clazz) { ClassLoader loader = clazz.getClassLoader(); if (loader == null) { loader = ClassLoader.getSystemClassLoader(); } for (TransformSet transformSet : transformSets) { if (transformSet.isFor(loader, clazz.getName())) { return !transformSet.isEmpty(); } } return false; } /**
for (TransformSet oldTransformSet : oldRuleScript.getTransformSets()) { TransformSet newTransformSet = newRuleScript.lookupTransformSet(oldTransformSet.getLoader(), oldTransformSet.getTriggerClass()); if(newTransformSet == null || newTransformSet.isInstalled()) { if(oldTransformSet.isInstalled()) { oldTransformSet.getInstalledRule().uninstalled(); newTransformSet.setInstalled(oldTransformSet.getInstalledRule()); } else { newRuleScript.ensureTransformSet(oldTransformSet.getLoader(), oldTransformSet.getTriggerClass(), oldTransformSet.getInstalledRule()); if(oldTransformSet.isInstalled()) { oldTransformSet.getInstalledRule().uninstalled();
/** * record the fact that a rule has been compiled with or without success * @param triggerClass the name of the trigger class to which the rule is attached * @param loader the classloader of the trigger class * @param successful true if the rule compiled successfully and false if it suffered from parse, * type or compile errors * @param detail text describing more details of the compilation outcome * @return true if the rule needs to be installed otherwise false */ public synchronized boolean recordCompile(Rule rule, String triggerClass, ClassLoader loader, boolean successful, String detail) { if(deleted) { return false; } // find an existing transform set or create a new one TransformSet transformSet = ensureTransformSet(loader, triggerClass, null); for (Transform transform : transformSet.getTransforms()) { if(transform.getRule() == rule) { transform.setCompiled(successful, detail); boolean isInstalled = transformSet.isInstalled(); // record this as the latest rule to be installed transformSet.setInstalled(rule); // if this is the first installed rule then // we need to perform lifecycle processing return !isInstalled; } } // no such rule so no lifecycle processing return false; }
/** * uninstall all transforms associated with this script. this is called after marking the script as * deleted and regenerating the methods for any associated transformed class to ensure that it does * not cause a rule trigger call to fail. */ public synchronized void purge() { for (TransformSet transformSet : transformSets) { for (Transform transform : transformSet.getTransforms()) { Rule rule = transform.getRule(); if(rule != null) { rule.purge(); } } transformSet.clearTransforms(); } transformSets.clear(); }
public TransformSet lookupTransformSet(ClassLoader loader, String triggerClass) { for (TransformSet transformSet : transformSets) { if (transformSet.isFor(loader, triggerClass)) { return transformSet; } } return null; }
/** * record the fact that a trigger call has failed to install into bytecode associated with a specific * class and loader * @param loader the loader of the class for which injection was attempted * @param internalClassName the internal Java name of the class * @param triggerMethodName the name of the method injected into * @param desc the descriptor of the method injected into * @param rule the rule which was injected * @param th throwable generated during the attempt to parse the rule text or inject code at the trigger point * @return true if the successful injection was recorded false if not */ public synchronized boolean recordTransform(ClassLoader loader, String internalClassName, String triggerMethodName, String desc, Rule rule, Throwable th) { if (deleted) { return false; } String fullMethodName = null; if (triggerMethodName != null) { fullMethodName = triggerMethodName + TypeHelper.internalizeDescriptor(desc); } // make sure we know about this specific loader and classname combination TransformSet transformSet = ensureTransformSet(loader, internalClassName, null); // and install the transform in the set transformSet.add(new Transform(loader, internalClassName, fullMethodName, rule, th)); return true; }
for (TransformSet oldTransformSet : oldRuleScript.getTransformSets()) { TransformSet newTransformSet = newRuleScript.lookupTransformSet(oldTransformSet.getLoader(), oldTransformSet.getTriggerClass()); if(newTransformSet == null || newTransformSet.isInstalled()) { if(oldTransformSet.isInstalled()) { oldTransformSet.getInstalledRule().uninstalled(); newTransformSet.setInstalled(oldTransformSet.getInstalledRule()); } else { newRuleScript.ensureTransformSet(oldTransformSet.getLoader(), oldTransformSet.getTriggerClass(), oldTransformSet.getInstalledRule()); if(oldTransformSet.isInstalled()) { oldTransformSet.getInstalledRule().uninstalled();
/** * record the fact that a rule has been compiled with or without success * @param triggerClass the name of the trigger class to which the rule is attached * @param loader the classloader of the trigger class * @param successful true if the rule compiled successfully and false if it suffered from parse, * type or compile errors * @param detail text describing more details of the compilation outcome * @return true if the rule needs to be installed otherwise false */ public synchronized boolean recordCompile(Rule rule, String triggerClass, ClassLoader loader, boolean successful, String detail) { if(deleted) { return false; } // find an existing transform set or create a new one TransformSet transformSet = ensureTransformSet(loader, triggerClass, null); for (Transform transform : transformSet.getTransforms()) { if(transform.getRule() == rule) { transform.setCompiled(successful, detail); boolean isInstalled = transformSet.isInstalled(); // record this as the latest rule to be installed transformSet.setInstalled(rule); // if this is the first installed rule then // we need to perform lifecycle processing return !isInstalled; } } // no such rule so no lifecycle processing return false; }
/** * uninstall all transforms associated with this script. this is called after marking the script as * deleted and regenerating the methods for any associated transformed class to ensure that it does * not cause a rule trigger call to fail. */ public synchronized void purge() { for (TransformSet transformSet : transformSets) { for (Transform transform : transformSet.getTransforms()) { Rule rule = transform.getRule(); if(rule != null) { rule.purge(); } } transformSet.clearTransforms(); } transformSets.clear(); }
/** * check whether a rule has been used to transform a specific class. this can be used when * rules are redefined to decide whether or not a class needs to be retransformed. Note that * it must only be called after the script has been deleted by calling setDeleted. * @param clazz the class for which a transform is being sought. * @return true if the class has been transformed using this script otherwise false. */ public synchronized boolean hasTransform(Class<?> clazz) { ClassLoader loader = clazz.getClassLoader(); if (loader == null) { loader = ClassLoader.getSystemClassLoader(); } for (TransformSet transformSet : transformSets) { if (transformSet.isFor(loader, clazz.getName())) { return !transformSet.isEmpty(); } } return false; } /**
public TransformSet lookupTransformSet(ClassLoader loader, String triggerClass) { for (TransformSet transformSet : transformSets) { if (transformSet.isFor(loader, triggerClass)) { return transformSet; } } return null; }
/** * record the fact that a trigger call has failed to install into bytecode associated with a specific * class and loader * @param loader the loader of the class for which injection was attempted * @param internalClassName the internal Java name of the class * @param triggerMethodName the name of the method injected into * @param desc the descriptor of the method injected into * @param rule the rule which was injected * @param th throwable generated during the attempt to parse the rule text or inject code at the trigger point * @return true if the successful injection was recorded false if not */ public synchronized boolean recordTransform(ClassLoader loader, String internalClassName, String triggerMethodName, String desc, Rule rule, Throwable th) { if (deleted) { return false; } String fullMethodName = null; if (triggerMethodName != null) { fullMethodName = triggerMethodName + TypeHelper.internalizeDescriptor(desc); } // make sure we know about this specific loader and classname combination TransformSet transformSet = ensureTransformSet(loader, internalClassName, null); // and install the transform in the set transformSet.add(new Transform(loader, internalClassName, fullMethodName, rule, th)); return true; }
for (TransformSet oldTransformSet : oldRuleScript.getTransformSets()) { TransformSet newTransformSet = newRuleScript.lookupTransformSet(oldTransformSet.getLoader(), oldTransformSet.getTriggerClass()); if(newTransformSet == null || newTransformSet.isInstalled()) { if(oldTransformSet.isInstalled()) { oldTransformSet.getInstalledRule().uninstalled(); newTransformSet.setInstalled(oldTransformSet.getInstalledRule()); } else { newRuleScript.ensureTransformSet(oldTransformSet.getLoader(), oldTransformSet.getTriggerClass(), oldTransformSet.getInstalledRule());
/** * delete any transforms associated with a specific trigger class and loader for * deletion. this is called just before any attempt to retransform the class * to inject the script's associated rule. it ensures that records of previous * transforms associated with a prior retransformation of the class are removed * before any new ones are added */ public synchronized void purge(ClassLoader loader, String triggerClassName) { TransformSet transformSet = lookupTransformSet(loader, triggerClassName); if (transformSet != null) { for (Transform transform : transformSet.getTransforms()) { Rule rule = transform.getRule(); if(rule != null) { rule.purge(); } } transformSet.clearTransforms(); } }
public TransformSet ensureTransformSet(ClassLoader loader, String triggerClass, Rule installedRule) { TransformSet transformSet = lookupTransformSet(loader, triggerClass); if (transformSet == null) { transformSet = new TransformSet(loader, triggerClass); transformSet.setInstalled(installedRule); transformSets.add(transformSet); } return transformSet; }
public boolean isInstalled() { return getInstalledRule() != null; }
public List<Transform> allTransforms() { List<Transform> allTransforms = new ArrayList<Transform>(); for (TransformSet transformSet : transformSets) { allTransforms.addAll(transformSet.getTransforms()); } return allTransforms; }