ReferenceConfigCache { public void destroyAll() { if (CollectionUtils.isEmptyMap(referredReferences)) { return; } referredReferences.forEach((_k, referenceConfig) -> { referenceConfig.destroy(); ApplicationModel.getConfigManager().removeConfig(referenceConfig); }); proxies.forEach((_type, proxiesOfType) -> { proxiesOfType.forEach((_k, v) -> { Destroyable proxy = (Destroyable) v; proxy.$destroy(); }); }); referredReferences.clear(); proxies.clear(); } private  ReferenceConfigCache(String name, KeyGenerator generator); static ReferenceConfigCache getCache(); static ReferenceConfigCache getCache(String name); static ReferenceConfigCache getCache(String name, KeyGenerator keyGenerator); @SuppressWarnings("unchecked") T get(ReferenceConfigBase<T> referenceConfig); @SuppressWarnings("unchecked") T get(String key, Class<T> type); @SuppressWarnings("unchecked") T get(String key); @SuppressWarnings("unchecked") List<T> getAll(Class<T> type); @SuppressWarnings("unchecked") T get(Class<T> type); void destroy(String key, Class<?> type); void destroy(Class<?> type); void destroy(ReferenceConfigBase<T> referenceConfig); void destroyAll(); ConcurrentMap<String, ReferenceConfigBase<?>> getReferredReferences(); ConcurrentMap<Class<?>, ConcurrentMap<String, Object>> getProxies(); @Override String toString(); static final String DEFAULT_NAME; static final KeyGenerator DEFAULT_KEY_GENERATOR; }
@Test public void testDestroyAll() throws Exception { ReferenceConfigCache cache = ReferenceConfigCache.getCache(); MockReferenceConfig config = buildMockReferenceConfig("org.apache.dubbo.config.utils.service.FooService", "group1", "1.0.0"); cache.get(config); XxxMockReferenceConfig configCopy = buildXxxMockReferenceConfig("org.apache.dubbo.config.utils.service.XxxService", "group1", "1.0.0"); cache.get(configCopy); assertEquals(2, cache.getReferredReferences().size()); cache.destroyAll(); assertTrue(config.isDestroyMethodRun()); assertTrue(configCopy.isDestroyMethodRun()); assertEquals(0, cache.getReferredReferences().size()); }