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

    相冊

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 女人毛片a级大学毛片免费| 99久热只有精品视频免费看| 嫩草视频在线免费观看| 亚洲视频无码高清在线| 免费精品人在线二线三线区别| 精品久久久久久亚洲精品| 成人毛片免费观看| 免费亚洲视频在线观看| 亚洲av午夜成人片精品电影| 一区二区三区免费在线视频| 亚洲自偷自偷偷色无码中文| 免费黄网站在线看| 亚洲图片激情小说| 女人被弄到高潮的免费视频| 国产精品手机在线亚洲| 中文字幕亚洲一区二区va在线| 99久久精品毛片免费播放| 亚洲AV无码国产丝袜在线观看| 777爽死你无码免费看一二区| 亚洲春色另类小说| 国产成人aaa在线视频免费观看| 国产99久久久国产精免费| 亚洲AV日韩AV永久无码久久| 青春禁区视频在线观看直播免费| 婷婷亚洲综合一区二区| 亚洲精品无码av人在线观看| 亚洲黄色免费在线观看| 亚洲AV无码专区在线厂| 国产亚洲精品国产| 免费电影在线观看网站| 一个人看的免费视频www在线高清动漫| 亚洲欧洲成人精品香蕉网| 人与禽交免费网站视频| 无码精品人妻一区二区三区免费| 亚洲av午夜成人片精品网站| 无码视频免费一区二三区| a级大片免费观看| 亚洲av无码兔费综合| 亚洲国产香蕉碰碰人人| 国产一区二区三区无码免费| 91精品全国免费观看含羞草|