@Override default List<Invoker<T>> list(Invocation invocation) throws RpcException { List<com.alibaba.dubbo.rpc.Invoker<T>> res = this.list(new com.alibaba.dubbo.rpc.Invocation.CompatibleInvocation(invocation)); return res.stream().map(i -> i.getOriginal()).collect(Collectors.toList()); } }
@Override public URL getUrl() { return directory.getUrl(); }
/** * 返回MockInvoker 契约: * directory根据invocation中是否有Constants.INVOCATION_NEED_MOCK,来判断获取的是一个normal * invoker 还是一个 mock invoker 如果directorylist 返回多个mock invoker,只使用第一个invoker. * * @param invocation * @return */ private List<Invoker<T>> selectMockInvoker(Invocation invocation) { List<Invoker<T>> invokers = null; // TODO generic invoker? if (invocation instanceof RpcInvocation) { // 存在隐含契约(虽然在接口声明中增加描述,但扩展性会存在问题.同时放在attachement中的做法需要改进 ((RpcInvocation) invocation).setAttachment(Constants.INVOCATION_NEED_MOCK, Boolean.TRUE.toString()); // directory根据invocation中attachment是否有Constants.INVOCATION_NEED_MOCK,来判断获取的是normal // invokers or mock invokers try { invokers = directory.list(invocation); } catch (JahhanException e) { if (log.isInfoEnabled()) { log.info("Exception when try to invoke mock. Get mock invokers error for service:" + directory.getUrl().getServiceInterface() + ", method:" + invocation.getMethodName() + ", will contruct a new mock with 'new MockInvoker()'.", e); } } } return invokers; }
@Override public boolean isAvailable() { return directory.isAvailable(); }
@Override public Class<T> getInterface() { return directory.getInterface(); }
@Override public void destroy() { directory.destroy(); }
@Override public URL getUrl() { return directory.getUrl(); }
/** * Return MockInvoker * Contract: * directory.list() will return a list of normal invokers if Constants.INVOCATION_NEED_MOCK is present in invocation, otherwise, a list of mock invokers will return. * if directory.list() returns more than one mock invoker, only one of them will be used. * * @param invocation * @return */ private List<Invoker<T>> selectMockInvoker(Invocation invocation) { List<Invoker<T>> invokers = null; //TODO generic invoker? if (invocation instanceof RpcInvocation) { //Note the implicit contract (although the description is added to the interface declaration, but extensibility is a problem. The practice placed in the attachement needs to be improved) ((RpcInvocation) invocation).setAttachment(Constants.INVOCATION_NEED_MOCK, Boolean.TRUE.toString()); //directory will return a list of normal invokers if Constants.INVOCATION_NEED_MOCK is present in invocation, otherwise, a list of mock invokers will return. try { invokers = directory.list(invocation); } catch (RpcException e) { if (logger.isInfoEnabled()) { logger.info("Exception when try to invoke mock. Get mock invokers error for service:" + directory.getUrl().getServiceInterface() + ", method:" + invocation.getMethodName() + ", will contruct a new mock with 'new MockInvoker()'.", e); } } } return invokers; }
@Override public boolean isAvailable() { return directory.isAvailable(); }
@Override public Class<T> getInterface() { return directory.getInterface(); }
public void destroy() { directory.destroy(); }
@Override default List<Invoker<T>> list(Invocation invocation) throws RpcException { List<com.alibaba.dubbo.rpc.Invoker<T>> res = this.list(new com.alibaba.dubbo.rpc.Invocation.CompatibleInvocation(invocation)); return res.stream().map(i -> i.getOriginal()).collect(Collectors.toList()); } }
@Override public URL getUrl() { return directory.getUrl(); }
/** * Return MockInvoker * Contract: * directory.list() will return a list of normal invokers if Constants.INVOCATION_NEED_MOCK is present in invocation, otherwise, a list of mock invokers will return. * if directory.list() returns more than one mock invoker, only one of them will be used. * * @param invocation * @return */ private List<Invoker<T>> selectMockInvoker(Invocation invocation) { List<Invoker<T>> invokers = null; //TODO generic invoker? if (invocation instanceof RpcInvocation) { //Note the implicit contract (although the description is added to the interface declaration, but extensibility is a problem. The practice placed in the attachement needs to be improved) ((RpcInvocation) invocation).setAttachment(Constants.INVOCATION_NEED_MOCK, Boolean.TRUE.toString()); //directory will return a list of normal invokers if Constants.INVOCATION_NEED_MOCK is present in invocation, otherwise, a list of mock invokers will return. try { invokers = directory.list(invocation); } catch (RpcException e) { if (logger.isInfoEnabled()) { logger.info("Exception when try to invoke mock. Get mock invokers error for service:" + directory.getUrl().getServiceInterface() + ", method:" + invocation.getMethodName() + ", will contruct a new mock with 'new MockInvoker()'.", e); } } } return invokers; }
@Override public boolean isAvailable() { return directory.isAvailable(); }
@Override public Class<T> getInterface() { return directory.getInterface(); }
@Override public void destroy() { directory.destroy(); }
protected List<Invoker<T>> list(Invocation invocation) throws RpcException { List<Invoker<T>> invokers = directory.list(invocation); return invokers; } }
public URL getUrl() { return directory.getUrl(); }
@Override public boolean isAvailable() { return directory.isAvailable(); }