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

    相冊

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 免费高清在线影片一区| a级毛片高清免费视频就| 8x8×在线永久免费视频| 亚洲综合另类小说色区色噜噜| 亚洲午夜精品久久久久久app| 美丽的姑娘免费观看在线播放| 中文字幕亚洲色图| 久久久久久久99精品免费观看| 国产亚洲美日韩AV中文字幕无码成人| 色屁屁www影院免费观看视频| 免费国产在线观看| 色屁屁在线观看视频免费| 亚洲AV无码一区二区三区国产 | 午夜亚洲国产理论秋霞| 大地资源在线资源免费观看| 国产中文在线亚洲精品官网| 中文字幕a∨在线乱码免费看 | 免费观看大片毛片| 日韩精品亚洲专区在线影视| 一本久久综合亚洲鲁鲁五月天| 九九久久精品国产免费看小说| 亚洲XX00视频| 国产真人无码作爱免费视频| 亚洲国产精品无码中文字| 久久国产免费一区二区三区| 久久亚洲精品中文字幕| 97国产免费全部免费观看| 亚洲欧洲日韩极速播放| 日韩激情无码免费毛片| 国产视频精品免费视频| 图图资源网亚洲综合网站| 成熟女人特级毛片www免费| 欧洲亚洲国产精华液| 一本色道久久综合亚洲精品| 麻豆成人久久精品二区三区免费| 亚洲精品电影天堂网| 国产高清免费观看| 久久久精品午夜免费不卡| 亚洲精品福利你懂| 伊人久久综在合线亚洲91 | 女人18毛片特级一级免费视频|