@Test public void getRegistry() { try { RegistryConfig registryConfig = new RegistryConfig().setProtocol("test111"); Registry registry = RegistryFactory.getRegistry(registryConfig); Assert.fail(); } catch (Exception e) { Assert.assertTrue(e instanceof SofaRpcRuntimeException); } { RegistryConfig registryConfig = new RegistryConfig().setProtocol("test"); Registry registry = RegistryFactory.getRegistry(registryConfig); Assert.assertTrue(registry instanceof TestRegistry); registry.destroy(new Destroyable.DestroyHook() { @Override public void preDestroy() { } @Override public void postDestroy() { } }); } for (int i = 0; i < 3; i++) { RegistryConfig registryConfig = new RegistryConfig().setProtocol("test").setTimeout(1000 + i); Registry registry = RegistryFactory.getRegistry(registryConfig); Assert.assertTrue(registry instanceof TestRegistry); } Assert.assertTrue(RegistryFactory.getRegistries().size() == 4); RegistryFactory.destroyAll(); }
public static synchronized Registry getRegistry(RegistryConfig registryConfig) { if (ALL_REGISTRIES.size() > 3) { if (LOGGER.isWarnEnabled()) { LOGGER.warn("Size of registry is greater than 3, Please check it!"); } } String protocol = null; try { Registry registry = ALL_REGISTRIES.get(registryConfig); if (registry == null) { protocol = registryConfig.getProtocol(); ExtensionClass<Registry> ext = ExtensionLoaderFactory.getExtensionLoader(Registry.class) .getExtensionClass(protocol); if (ext == null) { throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_LOAD_EXT, "Registry", protocol)); } registry = ext.getExtInstance(new Class[] { RegistryConfig.class }, new Object[] { registryConfig }); ALL_REGISTRIES.put(registryConfig, registry); } return registry; } catch (SofaRpcRuntimeException e) { throw e; } catch (Throwable e) { throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_LOAD_EXT, "Registry", protocol)); } }
RegistryFactory { public static synchronized Registry getRegistry(RegistryConfig registryConfig) { if (ALL_REGISTRIES.size() > 3) { if (LOGGER.isWarnEnabled()) { LOGGER.warn("Size of registry is greater than 3, Please check it!"); } } String protocol = null; try { Registry registry = ALL_REGISTRIES.get(registryConfig); if (registry == null) { protocol = registryConfig.getProtocol(); ExtensionClass<Registry> ext = ExtensionLoaderFactory.getExtensionLoader(Registry.class) .getExtensionClass(protocol); if (ext == null) { throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_LOAD_EXT, "Registry", protocol)); } registry = ext.getExtInstance(new Class[] { RegistryConfig.class }, new Object[] { registryConfig }); ALL_REGISTRIES.put(registryConfig, registry); } return registry; } catch (SofaRpcRuntimeException e) { throw e; } catch (Throwable e) { throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_LOAD_EXT, "Registry", protocol)); } } }
RegistryFactory { public static synchronized Registry getRegistry(RegistryConfig registryConfig) { if (ALL_REGISTRIES.size() > 3) { if (LOGGER.isWarnEnabled()) { LOGGER.warn("Size of registry is greater than 3, Please check it!"); } } String protocol = null; try { Registry registry = ALL_REGISTRIES.get(registryConfig); if (registry == null) { protocol = registryConfig.getProtocol(); ExtensionClass<Registry> ext = ExtensionLoaderFactory.getExtensionLoader(Registry.class) .getExtensionClass(protocol); if (ext == null) { throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_LOAD_EXT, "Registry", protocol)); } registry = ext.getExtInstance(new Class[] { RegistryConfig.class }, new Object[] { registryConfig }); ALL_REGISTRIES.put(registryConfig, registry); } return registry; } catch (SofaRpcRuntimeException e) { throw e; } catch (Throwable e) { throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_LOAD_EXT, "Registry", protocol)); } }  }
RegistryFactory { public static synchronized Registry getRegistry(RegistryConfig registryConfig) { if (ALL_REGISTRIES.size() > 3) { if (LOGGER.isWarnEnabled()) { LOGGER.warn("Size of registry is greater than 3, Please check it!"); } } String protocol = null; try { Registry registry = ALL_REGISTRIES.get(registryConfig); if (registry == null) { protocol = registryConfig.getProtocol(); ExtensionClass<Registry> ext = ExtensionLoaderFactory.getExtensionLoader(Registry.class) .getExtensionClass(protocol); if (ext == null) { throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_LOAD_EXT, "Registry", protocol)); } registry = ext.getExtInstance(new Class[] { RegistryConfig.class }, new Object[] { registryConfig }); ALL_REGISTRIES.put(registryConfig, registry); } return registry; } catch (SofaRpcRuntimeException e) { throw e; } catch (Throwable e) { throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_LOAD_EXT, "Registry", protocol)); } }  static synchronized Registry getRegistry(RegistryConfig registryConfig); static List<RegistryConfig> getRegistryConfigs(); static List<Registry> getRegistries(); static void destroyAll(); }
RegistryFactory { public static synchronized Registry getRegistry(RegistryConfig registryConfig) { if (ALL_REGISTRIES.size() > 3) { if (LOGGER.isWarnEnabled()) { LOGGER.warn("Size of registry is greater than 3, Please check it!"); } } String protocol = null; try { Registry registry = ALL_REGISTRIES.get(registryConfig); if (registry == null) { protocol = registryConfig.getProtocol(); ExtensionClass<Registry> ext = ExtensionLoaderFactory.getExtensionLoader(Registry.class) .getExtensionClass(protocol); if (ext == null) { throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_LOAD_EXT, "Registry", protocol)); } registry = ext.getExtInstance(new Class[] { RegistryConfig.class }, new Object[] { registryConfig }); ALL_REGISTRIES.put(registryConfig, registry); } return registry; } catch (SofaRpcRuntimeException e) { throw e; } catch (Throwable e) { throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_LOAD_EXT, "Registry", protocol)); } }  static synchronized Registry getRegistry(RegistryConfig registryConfig); static List<RegistryConfig> getRegistryConfigs(); static List<Registry> getRegistries(); static void destroyAll();  }