FailbackRegistry extends AbstractRegistry { @Override public void register(URL url) { if (!acceptable(url)) { logger.info("URL " + url + " will not be registered to Registry. Registry " + url + " does not accept service of this protocol type."); return; } super.register(url); removeFailedRegistered(url); removeFailedUnregistered(url); try { doRegister(url); } catch (Exception e) { Throwable t = e; boolean check = getUrl().getParameter(Constants.CHECK_KEY, true) && url.getParameter(Constants.CHECK_KEY, true) && !CONSUMER_PROTOCOL.equals(url.getProtocol()); boolean skipFailback = t instanceof SkipFailbackWrapperException; if (check || skipFailback) { if (skipFailback) { t = t.getCause(); } throw new IllegalStateException("Failed to register " + url + " to registry " + getUrl().getAddress() + ", cause: " + t.getMessage(), t); } else { logger.error("Failed to register " + url + ", waiting for retry, cause: " + t.getMessage(), t); } addFailedRegistered(url); } } FailbackRegistry(URL url); void removeFailedRegisteredTask(URL url); void removeFailedUnregisteredTask(URL url); void removeFailedSubscribedTask(URL url, NotifyListener listener); void removeFailedUnsubscribedTask(URL url, NotifyListener listener); @Override void register(URL url); @Override void reExportRegister(URL url); @Override void unregister(URL url); @Override void reExportUnregister(URL url); @Override void subscribe(URL url, NotifyListener listener); @Override void unsubscribe(URL url, NotifyListener listener); @Override void destroy(); abstract void doRegister(URL url); abstract void doUnregister(URL url); abstract void doSubscribe(URL url, NotifyListener listener); abstract void doUnsubscribe(URL url, NotifyListener listener);  }
@Test public void testDoRetry_subscribe() throws Exception { final CountDownLatch latch = new CountDownLatch(1); registry = new MockRegistry(registryUrl, latch); registry.setBad(true); registry.register(serviceUrl); registry.setBad(false); for (int i = 0; i < trytimes; i++) { System.out.println("failback registry retry ,times:" + i); if (latch.getCount() == 0) break; Thread.sleep(sleeptime); } assertEquals(0, latch.getCount()); }