protected void createMethodTables() throws Exception { initAdvisedMethodsMap(); populateMethodTables(clazz.getSuperclass()); addDeclaredMethods(clazz); }
protected void finalizeMethodCalledByMethodInterceptorChain(MethodByMethodInfo info) { adjustInfoForAddedBinding(info); ArrayList<Interceptor> list = info.getInterceptorChain(); Interceptor[] interceptors = null; if (list.size() > 0) { interceptors = applyPrecedence(list.toArray(new Interceptor[list.size()])); } info.setInterceptors(interceptors); }
public synchronized void addClassMetaData(ClassMetaDataBinding data) { initClassMetaDataBindingsList(); classMetaDataBindings.add(data); if (this.clazz == null) return; // don't bind till later. bindClassMetaData(data); // Recalculate interceptorPointcuts because of MetaDataInterceptorPointcuts adviceBindings.clear(); doesHaveAspects = false; rebuildInterceptors(); }
ArrayList<InterfaceIntroduction> introductions = advisor.getInterfaceIntroductions(); if (introductions != null && introductions.size() > 0) pw.println("<constructors>"); indent++; for (int i = 0; i < advisor.getConstructors().length; i++) Constructor<?> con = advisor.getConstructors()[i]; Interceptor[] chain = advisor.getConstructorInfos()[i].getInterceptors(); HashMap<String, TLongObjectHashMap> methodCallers = advisor.getMethodCalledByConInterceptors()[i]; HashMap<String, TLongObjectHashMap> conCallers = advisor.getConCalledByConInterceptors()[i]; pw.println("<fields-read>"); indent++; for (int i = 0; i < advisor.getAdvisedFields().length; i++) Field f = advisor.getAdvisedFields()[i]; Interceptor[] chain = advisor.getFieldReadInfos()[i].getInterceptors(); if (chain != null && chain.length > 0) pw.println("<fields-write>"); indent++; for (int i = 0; i < advisor.getAdvisedFields().length; i++) Field f = advisor.getAdvisedFields()[i]; Interceptor[] chain = advisor.getFieldReadInfos()[i].getInterceptors(); if (chain != null && chain.length > 0) pw.println("<methods>");
private ConByConInfo doResolveConstructorCallerConstructorInfo(Class<?> callingClass, int callingIndex, String calledClass, long calledConHash) { try { Constructor<?> callingConstructor = constructors[callingIndex]; if (callingConstructor == null) throw new RuntimeException("Unable to figure out calling method of a caller pointcut"); Class<?> called = SecurityActions.getClassLoader(callingClass).loadClass(calledClass); Constructor<?> calledCon = MethodHashing.findConstructorByHash(called, calledConHash); if (calledCon == null) throw new RuntimeException("Unable to figure out calledcon of a caller pointcut"); boolean matched = false; ClassifiedBindingAndPointcutCollection bindingCol = manager.getBindingCollection(); for (AdviceBinding binding : bindingCol.getConstructorCallBindings()) { if (binding.getPointcut().matchesCall(this, callingConstructor, called, calledCon)) { addConstructorCalledByConPointcut(callingIndex, calledClass, calledConHash, binding); matched = true; } } if (!matched) initializeConCalledByConEmptyChain(callingIndex, calledClass, calledConHash); ConByConInfo info = initializeConCalledByConInterceptorsMap(callingClass, callingIndex, calledClass, calledConHash, calledCon); ArrayList<AdviceBinding> bindings = getConCalledByConBindings(callingIndex, calledClass, calledConHash); bindConCalledByConInterceptorChain(bindings, callingIndex, calledClass, calledConHash); return info; } catch (Exception x) { throw new RuntimeException(x); } }
private MethodByConInfo doResolveConstructorCallerMethodInfo(Class<?> callingClass, int callingIndex, String calledClass, long calledMethodHash) { try { Constructor<?> callingConstructor = constructors[callingIndex]; if (callingConstructor == null) throw new RuntimeException("Unable to figure out calling method of a caller pointcut"); Class<?> called = SecurityActions.getClassLoader(callingClass).loadClass(calledClass); Method calledMethod = MethodHashing.findMethodByHash(called, calledMethodHash); if (calledMethod == null) throw new RuntimeException("Unable to figure out calledmethod of a caller pointcut"); boolean matched = false; ClassifiedBindingAndPointcutCollection bindingCol = manager.getBindingCollection(); for (AdviceBinding binding : bindingCol.getConstructorCallBindings()) { if (binding.getPointcut().matchesCall(this, callingConstructor, called, calledMethod)) { addConstructorCallerPointcut(callingIndex, calledClass, calledMethodHash, binding); matched = true; } } if (!matched) initializeEmptyConstructorCallerChain(callingIndex, calledClass, calledMethodHash); MethodByConInfo info = initializeConstructorCallerInterceptorsMap(callingClass, callingIndex, calledClass, calledMethodHash, calledMethod); ArrayList<AdviceBinding> bindings = getConstructorCallerBindings(callingIndex, calledClass, calledMethodHash); bindConstructorCallerInterceptorChain(bindings, callingIndex, calledClass, calledMethodHash); return info; } catch (Exception x) { throw new RuntimeException(x); } }
private Field[] interceptGetDeclaredFields(Class<?> clazz) { ClassAdvisor advisor = AspectManager.instance().getAdvisorIfAdvised(clazz); if (advisor == null) { return getDeclaredFields(clazz); } else { Field[] advisedFields = advisor.getAdvisedFields(); ArrayList<Field> fields = new ArrayList<Field>(advisedFields.length); for (int i = 0; i < advisedFields.length; i++) { Field f = advisedFields[i]; if (clazz.equals(f.getDeclaringClass())) { fields.add(f); } } return fields.toArray(new Field[fields.size()]); } }
/** * Create a HashMap of method hash and Method * Superclasses get added first so subclasses will override with * correct overriden method */ private void populateMethodTables(Class<?> superclass) throws Exception { if (superclass == null) return; if (superclass.equals(Object.class)) return; populateMethodTables(superclass.getSuperclass()); //The advisor for the superclass may be a container Advisor superAdvisor = manager.getAnyAdvisorIfAdvised(superclass); if (superAdvisor != null && superAdvisor instanceof ClassAdvisor) { TLongObjectHashMap superHash = ((ClassAdvisor)superAdvisor).getUnadvisedMethods(); long[] keys = superHash.keys(); for (int i = 0; i < keys.length; i++) { unadvisedMethods.put(keys[i], superHash.get(keys[i])); } } addDeclaredMethods(superclass); }
protected void rebindClassMetaData() { defaultMetaData.clear(); methodMetaData.clear(); fieldMetaData.clear(); constructorMetaData.clear(); classMetaData.clear(); for (int i = 0; i < classMetaDataBindings.size(); i++) { ClassMetaDataBinding data = classMetaDataBindings.get(i); bindClassMetaData(data); } deployAnnotationOverrides(); }
if (advisor != null && advisor.getClazz() == loadedClass) return new ClassAdvisor(className, am);
public void initialiseClassAdvisor(Class<?> clazz, ClassAdvisor advisor) { // avoiding deadlock. Other threads first get the bindignCollection lock // and then the advisors // as we know that the bindingCollection lock will be needed during the // Advisor.attachClass method execution, we get the lock at this point // making sure we are avoiding the deadlock. lock.lockRead(); try { synchronized (advisors) { advisors.put(clazz, new WeakReference<Advisor>(advisor)); registerClass(clazz); advisor.attachClass(clazz); InterceptorChainObserver observer = dynamicStrategy.getInterceptorChainObserver(clazz); advisor.setInterceptorChainObserver(observer); if (notificationHandler != null) { notificationHandler.attachClass(clazz.getName()); } } } finally { lock.unlockRead(); } }
/** * Take into account that an advisor may be a container */ public Advisor getAnyAdvisorIfAdvised(Class<?> clazz) { try { Advisor advisor; advisor = findAdvisor(clazz); if (advisor == null) { return null; } if (advisor.getClazz() == null && advisor instanceof ClassAdvisor) { ((ClassAdvisor)advisor).attachClass(clazz); if (notificationHandler != null) { notificationHandler.attachClass(clazz.getName()); } } return advisor; } catch (RuntimeException ex) { ex.printStackTrace(); throw ex; } }
cadvisor.addPerInstanceJoinpointAspect(joinpoint, def); aspect = def.getFactory().createPerJoinpoint(getClassAdvisor(), instanceAdvisor, joinpoint); WeakHashMap<AspectDefinition, ConcurrentHashMap<Joinpoint, Object>> copy = new WeakHashMap<AspectDefinition, ConcurrentHashMap<Joinpoint, Object>>(joinpointAspects);
public void checkOptimisticLock(Transaction tx) { // NOTE THIS CODE ASSUMES THAT A WRITELOCK HAS BEEN ACQUIRED!!!! HashMap state = getTxState(tx); Iterator it = state.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry)it.next(); Integer index = (Integer)entry.getKey(); DistributedFieldUpdate update = (DistributedFieldUpdate)entry.getValue(); DistributedFieldUpdate orig = (DistributedFieldUpdate)fieldMap.get(index); if (update.getVersionId() <= orig.getVersionId()) { Advised advised = null; if (advisedRef != null) { advised = (Advised)advisedRef.get(); } if (advised != null) { ClassAdvisor advisor = (ClassAdvisor)advised._getAdvisor(); Field field = advisor.getAdvisedFields()[index.intValue()]; throw new OptimisticLockFailure("optimistic lock failure for field " + field.getName() + " of class " + field.getDeclaringClass().getName()); } } } }
private Field interceptGetDeclaredField(Class<?> clazz, Object[] args) throws NoSuchFieldException { ClassAdvisor advisor = AspectManager.instance().getAdvisorIfAdvised(clazz); Field field = getDeclaredField(clazz, (String) args[0]); if (advisor == null) { return field; } else { Field[] advisedFields = advisor.getAdvisedFields(); for (int i = 0; i < advisedFields.length; i++) { Field f = advisedFields[i]; if (f.equals(field)) { return field; } } } throw new NoSuchFieldException(); }
protected void finalizeConCalledByConInterceptorChain(ConByConInfo info) { adjustInfoForAddedBinding(info); ArrayList<Interceptor> list = info.getInterceptorChain(); Interceptor[] interceptors = null; if (list.size() > 0) { interceptors = applyPrecedence(list.toArray(new Interceptor[list.size()])); } info.setInterceptors(interceptors); }
log.trace("build field " + advisor.getAdvisedFields()[update.getFieldIndex()].getName()); Object val = update.getNonDereferencedValue(); if (val != null && (val instanceof VersionReference)) log.trace("VersionReference.guid: " + ref.getGUID() + " for field " + advisor.getAdvisedFields()[update.getFieldIndex()].getName()); val = manager.getObject(ref.getGUID()); if (val == null)
protected void finalizeMethodCalledByConInterceptorChain(MethodByConInfo info) { adjustInfoForAddedBinding(info); ArrayList<Interceptor> list = info.getInterceptorChain(); Interceptor[] interceptors = null; if (list.size() > 0) { interceptors = applyPrecedence(list.toArray(new Interceptor[list.size()])); } info.setInterceptors(interceptors); }
try Field[] advisedFields = ((ClassAdvisor)advised._getAdvisor()).getAdvisedFields(); for (int i = 0; i < advisedFields.length; i++)
protected void finalizeConCalledByMethodInterceptorChain(ConByMethodInfo info) { adjustInfoForAddedBinding(info); ArrayList<Interceptor> list = info.getInterceptorChain(); Interceptor[] interceptors = null; if (list.size() > 0) { interceptors = applyPrecedence(list.toArray(new Interceptor[list.size()])); } info.setInterceptors(interceptors); }