Search in sources :

Example 1 with Filter

use of com.weibo.api.motan.filter.Filter in project motan by weibocom.

the class ProtocolFilterDecorator method addIfAbsent.

private void addIfAbsent(List<Filter> filters, String extensionName) {
    if (StringUtils.isBlank(extensionName)) {
        return;
    }
    Filter extFilter = ExtensionLoader.getExtensionLoader(Filter.class).getExtension(extensionName);
    if (extFilter == null) {
        return;
    }
    boolean exists = false;
    for (Filter f : filters) {
        if (f.getClass() == extFilter.getClass()) {
            exists = true;
            break;
        }
    }
    if (!exists) {
        filters.add(extFilter);
    }
}
Also used : Filter(com.weibo.api.motan.filter.Filter) AccessLogFilter(com.weibo.api.motan.filter.AccessLogFilter)

Example 2 with Filter

use of com.weibo.api.motan.filter.Filter 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)

Example 3 with Filter

use of com.weibo.api.motan.filter.Filter in project motan by weibocom.

the class ProtocolFilterDecorator method decorateWithFilter.

private <T> Provider<T> decorateWithFilter(Provider<T> provider, URL url) {
    List<Filter> filters = getFilters(url, MotanConstants.NODE_TYPE_SERVICE);
    if (filters == null || filters.size() == 0) {
        return provider;
    }
    Provider<T> lastProvider = provider;
    for (Filter filter : filters) {
        final Filter f = filter;
        final Provider<T> lp = lastProvider;
        lastProvider = new Provider<T>() {

            @Override
            public Response call(Request request) {
                return f.filter(lp, request);
            }

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

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

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

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

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

            @Override
            public boolean isAvailable() {
                return lp.isAvailable();
            }
        };
    }
    return lastProvider;
}
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) URL(com.weibo.api.motan.rpc.URL)

Aggregations

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