<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 超越巔峰 閱讀(4427) 評論(3)  編輯  收藏 所屬分類: Java EE

    評論

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

    用spring aop有個(gè)限制就是被aop攔截的方法被this對象的另一個(gè)方法調(diào)用會繞過aop  回復(fù)  更多評論   

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

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

    # 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;
    }  回復(fù)  更多評論   

    導(dǎo)航

    統(tǒng)計(jì)

    常用鏈接

    留言簿(12)

    隨筆分類(54)

    隨筆檔案(59)

    文章分類(2)

    文章檔案(1)

    相冊

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲午夜久久久久久噜噜噜| 日韩成人在线免费视频 | 亚洲香蕉在线观看| 十八禁无码免费网站| 亚洲国产精品国自产电影| 国产午夜免费高清久久影院| 亚洲AV无码一区二区三区DV| a级毛片免费完整视频| 亚洲AV一宅男色影视| 国精产品一区一区三区免费视频| 精品国产亚洲一区二区三区| 国产成人免费ā片在线观看老同学| 亚洲中文字幕在线观看| 毛片在线播放免费观看| 精品无码一区二区三区亚洲桃色 | 国产亚洲精品第一综合| 亚洲精品456播放| a在线视频免费观看| 亚洲国产综合91精品麻豆| 国产精品免费观看| 亚洲欧美国产国产综合一区| 日韩亚洲精品福利| 女人隐私秘视频黄www免费| 亚洲精品网站在线观看你懂的| 青草草色A免费观看在线| 亚洲成a∧人片在线观看无码| 免费看一级做a爰片久久| 国产特黄特色的大片观看免费视频| 国产A在亚洲线播放| 日韩精品成人无码专区免费| 亚洲AV无码国产剧情| 中文字幕精品亚洲无线码二区| 最近2019中文字幕免费大全5 | 日韩在线天堂免费观看| aa午夜免费剧场| 亚洲国产精品日韩在线观看| 国产美女无遮挡免费视频网站| 中文在线日本免费永久18近| 亚洲白色白色在线播放| 亚洲日本一区二区一本一道| 99久久99久久精品免费观看|