<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    J2EE之巔

     

    Spring AOP on Annotation

    1 The annotation:
    @Retention(RetentionPolicy.RUNTIME)
    @Target(ElementType.METHOD)
    @Inherited
    public @interface NeedToRetry {
        Class<?>[] recoverableExceptions();
        int retryTime();
        int intervalIncrementalFactor() default 0;
        long retryInterval() default 0L;
    }

    2 The Aspect
    @Aspect
    public class InvokingRetryInterceptor {
        private static Logger log = Logger.getLogger(InvokingRetryInterceptor.class);
        private boolean isNeedToRetry(Throwable t,Class<?>[] recoverableExceptions){
            String exceptionName= t.getClass().getName();
            for (Class<?> exp:recoverableExceptions){            
                if (exp.isInstance(t)){
                    return true;
                }
            }
            log.warn("The exception doesn't need recover!"+exceptionName);
            return false;
        }

        private long getRetryInterval(int tryTimes,long interval,int incrementalFactor){
            return interval+(tryTimes*incrementalFactor);
        }
        
        @Around(value="@annotation(amazon.internal.dropship.common.NeedToRetry)&&@annotation(retryParam)",argNames="retryParam")
        public Object process(ProceedingJoinPoint pjp,NeedToRetry retryParam ) throws Throwable{
            boolean isNeedTry=true;
            int count=0;
            Throwable fault;            
            Class<?>[] recoverableExceptions=retryParam.recoverableExceptions();
            int retryTime=retryParam.retryTime();
            long retryInterval=retryParam.retryInterval();
            int incrementalFactor=retryParam.intervalIncrementalFactor();
            do{
                try{                
                    return pjp.proceed();            
                }catch(Throwable t){
                    fault=t;
                    if (!isNeedToRetry(t,recoverableExceptions)){
                        break;
                    }
                    Thread.sleep(getRetryInterval(retryTime,retryInterval,incrementalFactor));
                }
                count++;
            }while(count<(retryTime+1));
            throw fault;
            
        }
    }

    posted on 2011-06-07 11:34 超越巔峰 閱讀(4439) 評論(3)  編輯  收藏 所屬分類: Java EE

    評論

    # re: Spring AOP on Annotation[未登錄] 2011-06-07 16:24 quaff

    用spring aop有個限制就是被aop攔截的方法被this對象的另一個方法調用會繞過aop  回復  更多評論   

    # re: Spring AOP on Annotation 2011-06-15 13:42 懶人助手

    有些圖片會更好,http://www.lrtool.net  回復  更多評論   

    # re: Spring AOP on Annotation[未登錄] 2013-05-17 14:06 cc

    more examples:
    @Around("execution(public * amazon.internal.dropship.core.external.services.*Gateway*.*(..)) && (!execution(public * amazon.internal.dropship.core.external.services.*GatewayMemory*.*(..)))")

    About cast AOP proxy:
    if(AopUtils.isJdkDynamicProxy(gateway)){
    impl = (SCSGatewayImpl) ((Advised)gateway).getTargetSource().getTarget();
    }else{
    impl = (SCSGatewayImpl) gateway;
    }  回復  更多評論   

    導航

    統計

    常用鏈接

    留言簿(12)

    隨筆分類(54)

    隨筆檔案(59)

    文章分類(2)

    文章檔案(1)

    相冊

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 久久九九亚洲精品| 国产成人毛片亚洲精品| 久久久综合亚洲色一区二区三区| 一级毛片免费毛片毛片| 亚洲免费一区二区| 亚洲免费日韩无码系列| 91麻豆国产自产在线观看亚洲| 又长又大又粗又硬3p免费视频| 四虎永久在线免费观看| 一级人做人a爰免费视频| 精品亚洲成α人无码成α在线观看 | 全部免费国产潢色一级| 337P日本欧洲亚洲大胆艺术图| 日本不卡高清中文字幕免费| 亚洲国产精品无码中文lv| 国产精品深夜福利免费观看| 无套内谢孕妇毛片免费看看| 国产成人精品日本亚洲专区61| 国产一级a毛一级a看免费视频 | 亚洲自偷自偷偷色无码中文| a级毛片在线免费看| 亚洲男人都懂得羞羞网站| 曰批视频免费30分钟成人| 亚洲欧洲无码一区二区三区| www亚洲精品少妇裸乳一区二区| fc2成年免费共享视频网站| 亚洲色大成网站www永久一区| 91成人在线免费视频| 亚洲色欲色欲www在线播放| 国内精品免费视频自在线| 美女露隐私全部免费直播| 亚洲色欲久久久综合网| 最近中文字幕完整免费视频ww | 全部在线播放免费毛片| 国产精品亚洲A∨天堂不卡| 亚洲第一网站免费视频| 国产精品亚洲一区二区三区在线观看| 亚洲一区二区三区偷拍女厕| 3d动漫精品啪啪一区二区免费 | 精品国产污污免费网站| 亚洲最大无码中文字幕|