Search in sources :

Example 1 with Activation

use of com.weibo.api.motan.core.extension.Activation in project motan by weibocom.

the class ProtocolFilterDecorator method decorateWithFilter.

private <T> Referer<T> decorateWithFilter(Referer<T> referer, URL url) {
    List<Filter> filters = getFilters(url, MotanConstants.NODE_TYPE_REFERER);
    Referer<T> lastRef = referer;
    for (Filter filter : filters) {
        final Filter f = filter;
        final Referer<T> lf = lastRef;
        lastRef = new Referer<T>() {

            @Override
            public Response call(Request request) {
                Activation activation = f.getClass().getAnnotation(Activation.class);
                if (activation != null && !activation.retry() && request.getRetries() != 0) {
                    return lf.call(request);
                }
                return f.filter(lf, request);
            }

            @Override
            public String desc() {
                return lf.desc();
            }

            @Override
            public void destroy() {
                lf.destroy();
            }

            @Override
            public Class<T> getInterface() {
                return lf.getInterface();
            }

            @Override
            public URL getUrl() {
                return lf.getUrl();
            }

            @Override
            public void init() {
                lf.init();
            }

            @Override
            public boolean isAvailable() {
                return lf.isAvailable();
            }

            @Override
            public int activeRefererCount() {
                return lf.activeRefererCount();
            }

            @Override
            public URL getServiceUrl() {
                return lf.getServiceUrl();
            }
        };
    }
    return lastRef;
}
Also used : Response(com.weibo.api.motan.rpc.Response) Filter(com.weibo.api.motan.filter.Filter) AccessLogFilter(com.weibo.api.motan.filter.AccessLogFilter) Request(com.weibo.api.motan.rpc.Request) Activation(com.weibo.api.motan.core.extension.Activation) URL(com.weibo.api.motan.rpc.URL)

Aggregations

Activation (com.weibo.api.motan.core.extension.Activation)1 AccessLogFilter (com.weibo.api.motan.filter.AccessLogFilter)1 Filter (com.weibo.api.motan.filter.Filter)1 Request (com.weibo.api.motan.rpc.Request)1 Response (com.weibo.api.motan.rpc.Response)1 URL (com.weibo.api.motan.rpc.URL)1