<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)

    相冊

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 2022国内精品免费福利视频| 亚洲性色精品一区二区在线| 欧洲美女大片免费播放器视频| 最新仑乱免费视频| 国产精品亚洲一区二区麻豆| 日本妇人成熟免费中文字幕| 亚洲一级视频在线观看| 97视频免费在线| 亚洲日韩精品无码专区加勒比☆| 卡1卡2卡3卡4卡5免费视频| 亚洲狠狠婷婷综合久久蜜芽| 国产婷婷高清在线观看免费| 国产精品亚洲а∨无码播放麻豆| 亚洲国产中文v高清在线观看| 一级毛片免费视频网站| 国产精品亚洲一区二区三区在线| 久热免费在线视频| 亚洲人成在线播放| 国产成人免费一区二区三区| 一级做性色a爰片久久毛片免费| 国产亚洲一区二区手机在线观看| 日韩午夜理论免费TV影院| 亚洲av永久无码精品三区在线4 | 亚洲美女视频免费| 女人18毛片水真多免费播放| 精品特级一级毛片免费观看| 久久久久亚洲爆乳少妇无| 性色午夜视频免费男人的天堂| 无码国产精品一区二区免费vr| 亚洲小视频在线播放| 日韩中文字幕在线免费观看| 国产大片免费天天看| 亚洲中文久久精品无码1| 亚洲av成人一区二区三区在线观看 | 国产成人无码区免费A∨视频网站 国产成人涩涩涩视频在线观看免费 | 国产精品亚洲综合网站| 亚洲理论电影在线观看| 久久久久久毛片免费播放| 亚洲精品亚洲人成在线| 亚洲成在人线av| 精品久久久久久久免费人妻|