dubbo学习笔记 十三 dubbo-filter
2016-12-19 17:16
176 查看
前面学了rpc的filter,那么这模块就简单了
dubbo-filter-cache和dubbo-filter-validation
dubbo-filter-cache和dubbo-filter-validation
dubbo-filter-cache
通过判断是否命中缓存,来决定是否都cachepublic Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { if (cacheFactory != null && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.CACHE_KEY))) { Cache cache = cacheFactory.getCache(invoker.getUrl().addParameter(Constants.METHOD_KEY, invocation.getMethodName())); if (cache != null) { String key = StringUtils.toArgumentString(invocation.getArguments()); if (cache != null && key != null) { Object value = cache.get(key); if (value != null) { return new RpcResult(value); } Result result = invoker.invoke(invocation); if (! result.hasException()) { cache.put(key, result.getValue()); } return result; } } } return invoker.invoke(invocation); }
dubbo-filter-validation
同样,利用Validator 的validate的方法, 如果校验不过,直接报异常。public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { if (validation != null && ! invocation.getMethodName().startsWith("$") && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.VALIDATION_KEY))) { try { Validator validator = validation.getValidator(invoker.getUrl()); if (validator != null) { validator.validate(invocation.getMethodName(), invocation.getParameterTypes(), invocation.getArguments()); } } catch (RpcException e) { throw e; } catch (Throwable t) { throw new RpcException(t.getMessage(), t); } } return invoker.invoke(invocation); }
相关文章推荐
- Linux netfilter 学习笔记 之十三 netfilter的SNAT模块是否支持UDP打洞
- Linux实践工程师学习笔记十三
- 设计模式学习笔记(十三)——Proxy代理模式
- Windows编程学习笔记(十三)
- 有关AutoCompleteBox组件的研究[3]_FilterMode和ItemFilter——Silverlight学习笔记[38]
- 学习笔记: CIC filter及其matlab实现
- GTK+图形化应用程序开发学习笔记(十三)—微调构件(1)
- MonoRail学习笔记六:Filter功能使用
- MonoRail学习笔记六:Filter功能使用
- JavaScript学习笔记(十三)
- DirectShow 学习笔记(二)Filter
- oracle9i学习笔记之十三 SQL练习
- GTK+图形化应用程序开发学习笔记(十三)—微调构件
- java学习笔记(十三)----IO操作
- 强大的DataGrid组件[13]_字段过滤(Filter)——Silverlight学习笔记[21]
- 设计模式学习笔记(十三)——Proxy代理模式
- 设计模式学习笔记(十三)——Proxy代理
- [ASP.NET学习笔记之十三]ASP.NET中水晶报表使用
- WPF and Silverlight 学习笔记(十三):依赖项属性和路由事件
- JUnit学习笔记13---对servlet和filter进行单元测试2