ReferenceConfigCache { public void destroy(String key, Class<?> type) { ReferenceConfigBase<?> rc = referredReferences.remove(key); if (rc == null) { return; } ApplicationModel.getConfigManager().removeConfig(rc); rc.destroy(); Map<String, Object> proxiesOftype = proxies.get(type); if (CollectionUtils.isNotEmptyMap(proxiesOftype)) { proxiesOftype.remove(key); if (proxiesOftype.isEmpty()) { proxies.remove(type); } } } 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 testDestroy() 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.destroy(config); assertTrue(config.isDestroyMethodRun()); assertEquals(1, cache.getReferredReferences().size()); cache.destroy(configCopy); assertTrue(configCopy.isDestroyMethodRun()); assertEquals(0, cache.getReferredReferences().size()); }