Java Code Examples for org.springframework.aop.framework.AdvisedSupport#addAdvisor()

The following examples show how to use org.springframework.aop.framework.AdvisedSupport#addAdvisor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DtsTransactionScaner.java    From dts with Apache License 2.0 5 votes vote down vote up
@Override
protected Object wrapIfNecessary(Object bean, String beanName, Object cacheKey) {
    try {
        synchronized (proxyedSet) {
            if (proxyedSet.contains(beanName)) {
                return bean;
            }
            proxyedSet.add(beanName);
            Class<?> serviceInterface = findTargetClass(bean);
            Method[] methods = serviceInterface.getMethods();
            LinkedList<MethodDesc> methodDescList = new LinkedList<MethodDesc>();
            for (Method method : methods) {
                DtsTransaction anno = method.getAnnotation(DtsTransaction.class);
                if (anno != null) {
                    methodDescList.add(makeMethodDesc(anno, method));
                }
            }
            if (methodDescList.size() != 0) {
                interceptor = new TransactionDtsInterceptor(methodDescList);
            } else {
                return bean;
            }
            if (!AopUtils.isAopProxy(bean)) {
                bean = super.wrapIfNecessary(bean, beanName, cacheKey);
            } else {
                AdvisedSupport advised = getAdvisedSupport(bean);
                Advisor[] advisor = buildAdvisors(beanName, getAdvicesAndAdvisorsForBean(null, null, null));
                for (Advisor avr : advisor) {
                    advised.addAdvisor(0, avr);
                }
            }
            return bean;
        }
    } catch (Exception e) {
        throw new DtsException(e);
    }
}
 
Example 2
Source File: DelayQueueScaner.java    From summerframework with Apache License 2.0 5 votes vote down vote up
@Override
protected Object wrapIfNecessary(Object bean, String beanName, Object cacheKey) {
    try {
        Object beanCopy = bean;
        synchronized (proxyedSet) {
            if (proxyedSet.contains(beanName)) {
                return beanCopy;
            }
            proxyedSet.add(beanName);
            Class<?> serviceInterface = this.findTargetClass(beanCopy);
            Method[] methods = serviceInterface.getMethods();
            List<Method> annotationMethods = Lists.newArrayList();
            for (Method method : methods) {
                Delay anno = method.getAnnotation(Delay.class);
                if (anno != null) {
                    annotationMethods.add(method);
                }
            }
            if (!annotationMethods.isEmpty()) {
                interceptor = new DelayQueueInterceptor(rabbitTemplate);
            } else {
                return beanCopy;
            }
            if (!AopUtils.isAopProxy(beanCopy)) {
                beanCopy = super.wrapIfNecessary(beanCopy, beanName, cacheKey);
            } else {
                AdvisedSupport advised = this.getAdvisedSupport(beanCopy);
                Advisor[] advisor = buildAdvisors(beanName, this.getAdvicesAndAdvisorsForBean(null, null, null));
                for (Advisor avr : advisor) {
                    advised.addAdvisor(0, avr);
                }
            }
            return beanCopy;
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 3
Source File: GlobalTransactionScanner.java    From seata-samples with Apache License 2.0 4 votes vote down vote up
@Override
protected Object wrapIfNecessary(Object bean, String beanName, Object cacheKey) {
    if (disableGlobalTransaction) {
        return bean;
    }
    try {
        synchronized (PROXYED_SET) {
            if (PROXYED_SET.contains(beanName)) {
                return bean;
            }
            interceptor = null;
            //check TCC proxy
            if (TCCBeanParserUtils.isTccAutoProxy(bean, beanName, applicationContext)) {
                //TCC interceptor, proxy bean of sofa:reference/dubbo:reference, and LocalTCC
                interceptor = new TccActionInterceptor(TCCBeanParserUtils.getRemotingDesc(beanName));
            } else {
                Class<?> serviceInterface = SpringProxyUtils.findTargetClass(bean);
                Class<?>[] interfacesIfJdk = SpringProxyUtils.findInterfaces(bean);

                if (!existsAnnotation(new Class[] {serviceInterface})
                        && !existsAnnotation(interfacesIfJdk)) {
                    return bean;
                }

                if (interceptor == null) {
                    interceptor = new GlobalTransactionalInterceptor(failureHandlerHook);
                }
            }

            LOGGER.info(
                    "Bean[" + bean.getClass().getName() + "] with name [" + beanName + "] would use interceptor ["
                            + interceptor.getClass().getName() + "]");
            if (!AopUtils.isAopProxy(bean)) {
                bean = super.wrapIfNecessary(bean, beanName, cacheKey);
            } else {
                AdvisedSupport advised = SpringProxyUtils.getAdvisedSupport(bean);
                Advisor[] advisor = buildAdvisors(beanName, getAdvicesAndAdvisorsForBean(null, null, null));
                for (Advisor avr : advisor) {
                    advised.addAdvisor(0, avr);
                }
            }
            PROXYED_SET.add(beanName);
            return bean;
        }
    } catch (Exception exx) {
        throw new RuntimeException(exx);
    }
}
 
Example 4
Source File: GlobalTransactionScanner.java    From seata-samples with Apache License 2.0 4 votes vote down vote up
@Override
protected Object wrapIfNecessary(Object bean, String beanName, Object cacheKey) {
    if (disableGlobalTransaction) {
        return bean;
    }
    try {
        synchronized (PROXYED_SET) {
            if (PROXYED_SET.contains(beanName)) {
                return bean;
            }
            interceptor = null;
            //check TCC proxy
            if (TCCBeanParserUtils.isTccAutoProxy(bean, beanName, applicationContext)) {
                //TCC interceptor, proxy bean of sofa:reference/dubbo:reference, and LocalTCC
                interceptor = new TccActionInterceptor(TCCBeanParserUtils.getRemotingDesc(beanName));
            } else {
                Class<?> serviceInterface = SpringProxyUtils.findTargetClass(bean);
                Class<?>[] interfacesIfJdk = SpringProxyUtils.findInterfaces(bean);

                if (!existsAnnotation(new Class[] {serviceInterface})
                        && !existsAnnotation(interfacesIfJdk)) {
                    return bean;
                }

                if (interceptor == null) {
                    interceptor = new GlobalTransactionalInterceptor(failureHandlerHook);
                }
            }

            LOGGER.info(
                    "Bean[" + bean.getClass().getName() + "] with name [" + beanName + "] would use interceptor ["
                            + interceptor.getClass().getName() + "]");
            if (!AopUtils.isAopProxy(bean)) {
                bean = super.wrapIfNecessary(bean, beanName, cacheKey);
            } else {
                AdvisedSupport advised = SpringProxyUtils.getAdvisedSupport(bean);
                Advisor[] advisor = buildAdvisors(beanName, getAdvicesAndAdvisorsForBean(null, null, null));
                for (Advisor avr : advisor) {
                    advised.addAdvisor(0, avr);
                }
            }
            PROXYED_SET.add(beanName);
            return bean;
        }
    } catch (Exception exx) {
        throw new RuntimeException(exx);
    }
}