Search in sources :

Example 31 with Response

use of com.weibo.api.motan.rpc.Response 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

Response (com.weibo.api.motan.rpc.Response)31 URL (com.weibo.api.motan.rpc.URL)13 MotanServiceException (com.weibo.api.motan.exception.MotanServiceException)11 DefaultResponse (com.weibo.api.motan.rpc.DefaultResponse)11 Request (com.weibo.api.motan.rpc.Request)11 Expectations (org.jmock.Expectations)10 Test (org.junit.Test)9 DefaultRequest (com.weibo.api.motan.rpc.DefaultRequest)7 IHello (com.weibo.api.motan.protocol.example.IHello)6 MotanFrameworkException (com.weibo.api.motan.exception.MotanFrameworkException)4 IWorld (com.weibo.api.motan.protocol.example.IWorld)4 Referer (com.weibo.api.motan.rpc.Referer)4 RegistryService (com.weibo.api.motan.registry.RegistryService)3 HashMap (java.util.HashMap)3 MotanBizException (com.weibo.api.motan.exception.MotanBizException)2 AccessLogFilter (com.weibo.api.motan.filter.AccessLogFilter)2 Filter (com.weibo.api.motan.filter.Filter)2 Channel (com.weibo.api.motan.transport.Channel)2 YarResponse (com.weibo.yar.YarResponse)2 MockTracer (io.opentracing.mock.MockTracer)2