<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有個限制就是被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)

    相冊

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 国产AV无码专区亚洲Av| 免费黄色福利视频| 国产国产人免费视频成69大陆| 久久亚洲私人国产精品| 久久国产精品免费视频| 亚洲成Av人片乱码色午夜| 你好老叔电影观看免费| 亚洲成av人影院| 96免费精品视频在线观看| 亚洲精品高清国产麻豆专区| 久久精品无码精品免费专区| 久久亚洲精精品中文字幕| **一级毛片免费完整视| 亚洲a视频在线观看| 免费黄色小视频网站| 色婷婷亚洲一区二区三区| 免费一级毛片在线播放| a色毛片免费视频| 亚洲精品在线播放| 女人张开腿等男人桶免费视频| 久久精品国产亚洲AV未满十八| 亚洲高清成人一区二区三区| 中文字幕乱码系列免费| 亚洲成色在线影院| 在人线av无码免费高潮喷水| 国产精品亚洲AV三区| 亚洲线精品一区二区三区 | 成人免费视频一区二区| 国产午夜亚洲精品理论片不卡| 伊人免费在线观看高清版| 亚洲日本人成中文字幕| 又粗又硬又黄又爽的免费视频| 两性色午夜视频免费网| 亚洲专区一路线二| 亚洲av手机在线观看| 免费v片在线观看视频网站| 亚洲高清视频免费| 麻豆国产VA免费精品高清在线| 一级做a爰片久久毛片免费陪| 亚洲国产综合精品中文第一区| 久久久久国产精品免费免费搜索|