@Overridepublic<T>Exporter<T>export(finalInvoker<T>originInvoker)throwsRpcException{...// 获取 registry,比如 ZookeeperRegistry (接口级注册)finalRegistryregistry=getRegistry(registryUrl);finalURLregisteredProviderUrl=getUrlToRegistry(providerUrl,registryUrl);// decide if we need to delay publish (provider itself and registry should both need to register)// 如果是接口级别,register 为 truebooleanregister=providerUrl.getParameter(REGISTER_KEY,true)&®istryUrl.getParameter(REGISTER_KEY,true);if(register){// 注册 providerUrl,最终调用 ZookeeperRegistry#registry 方法register(registry,registeredProviderUrl);}...returnnewDestroyableExporter<>(exporter);}
// 注册 url, 这个类是 ZookeeperRegistry 的 父类@Overridepublicvoidregister(URLurl){...super.register(url);// 移除 urlremoveFailedRegistered(url);removeFailedUnregistered(url);try{// Sending a registration request to the server side// 调用子类的注册方法, 这里以 ZookeeperRegistry 为例doRegister(url);}catch(Exceptione){Throwablet=e;// If the startup detection is opened, the Exception is thrown directly.booleancheck=getUrl().getParameter(Constants.CHECK_KEY,true)&&url.getParameter(Constants.CHECK_KEY,true)&&(url.getPort()!=0);booleanskipFailback=tinstanceofSkipFailbackWrapperException;// 检查 check 参数,如果是 true,表示第一次一定要注册成功if(check||skipFailback){if(skipFailback){t=t.getCause();}thrownewIllegalStateException("Failed to register "+url+" to registry "+getUrl().getAddress()+", cause: "+t.getMessage(),t);}else{logger.error(INTERNAL_ERROR,"unknown error in registry module","","Failed to register "+url+", waiting for retry, cause: "+t.getMessage(),t);}// Record a failed registration request to a failed list, retry regularly// 添加失败的 url,稍后定时任务会重新注册addFailedRegistered(url);}}