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

    評論

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

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

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

    有些圖片會(huì)更好,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)

    相冊

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲婷婷天堂在线综合| 亚洲精品白色在线发布| 色噜噜噜噜亚洲第一| 女人被免费视频网站| 亚洲人成网站在线播放2019| 波多野结衣在线免费视频| 亚洲欧洲日产国产最新| 国产情侣激情在线视频免费看| 2022年亚洲午夜一区二区福利 | 亚洲精品一区二区三区四区乱码| 免费无码又爽又刺激网站| 亚洲AV无码国产在丝袜线观看| 免费成人在线电影| 亚洲综合男人的天堂色婷婷| 免费观看国产网址你懂的| 久久狠狠爱亚洲综合影院| 免费观看的a级毛片的网站| 在线观看免费亚洲| 亚洲日韩中文字幕日韩在线| 97在线视频免费公开视频| 亚洲人成在线观看| 大地资源免费更新在线播放| 色天使亚洲综合一区二区| 亚洲精品国产精品乱码不卡√ | 国产精品久久久久影院免费| 香港经典a毛片免费观看看| 伊人久久大香线蕉亚洲五月天| 免费成人在线电影| 中文无码亚洲精品字幕| 亚洲精品国产V片在线观看| 久久久久成人片免费观看蜜芽| 激情综合亚洲色婷婷五月APP| 国产禁女女网站免费看| 国产成人免费AV在线播放| 在线亚洲午夜片AV大片| 亚洲日本一区二区三区在线不卡| 四虎国产精品永久免费网址| 亚洲国产精品精华液| 久久精品国产69国产精品亚洲| 男人的好免费观看在线视频| 国产精品亚洲二区在线|