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

    相冊

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲人成网站在线观看播放| 亚洲精品视频免费观看| 久久亚洲美女精品国产精品| 爱丫爱丫影院在线观看免费| 亚洲一区精品无码| 国产在线精品一区免费香蕉| 亚洲AV无码乱码在线观看富二代| 国产精品99爱免费视频| 日本亚洲视频在线| 99re视频精品全部免费| 亚洲激情黄色小说| 亚洲毛片在线免费观看| 亚洲AV色吊丝无码| 日本免费v片一二三区| 一级毛片a女人刺激视频免费| 国产性爱在线观看亚洲黄色一级片| 中文永久免费观看网站| 久久久久亚洲AV片无码| 无码av免费毛片一区二区| 亚洲AV无码片一区二区三区 | www.亚洲精品.com| 国产精品免费久久| 亚洲春色另类小说| 最新中文字幕免费视频| 全黄A免费一级毛片| 亚洲春色在线视频| 香蕉97超级碰碰碰免费公| 精品亚洲av无码一区二区柚蜜| 亚洲日韩涩涩成人午夜私人影院| 久艹视频在线免费观看| 亚洲综合无码一区二区痴汉 | 亚洲另类激情综合偷自拍图| 114级毛片免费观看| 亚洲av成人无码网站… | 国产91在线|亚洲| 亚洲国产高清在线一区二区三区 | 亚洲成熟丰满熟妇高潮XXXXX| 亚洲一区AV无码少妇电影☆| 免费H网站在线观看的| 一区二区三区AV高清免费波多| 亚洲激情电影在线|