diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/ServiceManager.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/ServiceManager.java index cee6e01003..176bee160e 100644 --- a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/ServiceManager.java +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/ServiceManager.java @@ -192,6 +192,7 @@ public BaseService handle(BaseService source, BaseService target) { * @param serviceName service name */ protected static void stopService(String serviceName) { + System.out.println("shutdown:" + serviceName); SERVICES.remove(serviceName).stop(); } diff --git a/sermant-plugins/sermant-service-registry/spring-cloud-registry-service/src/main/java/io/sermant/registry/service/cache/AddressCache.java b/sermant-plugins/sermant-service-registry/spring-cloud-registry-service/src/main/java/io/sermant/registry/service/cache/AddressCache.java index e69ceba624..bf9b7317b0 100644 --- a/sermant-plugins/sermant-service-registry/spring-cloud-registry-service/src/main/java/io/sermant/registry/service/cache/AddressCache.java +++ b/sermant-plugins/sermant-service-registry/spring-cloud-registry-service/src/main/java/io/sermant/registry/service/cache/AddressCache.java @@ -16,12 +16,16 @@ package io.sermant.registry.service.cache; +import com.alibaba.fastjson.JSONObject; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; +import com.google.common.cache.RemovalListener; +import com.google.common.cache.RemovalNotification; import io.sermant.core.plugin.config.PluginConfigManager; import io.sermant.registry.config.GraceConfig; +import java.time.LocalDateTime; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -43,6 +47,15 @@ public enum AddressCache { cache = CacheBuilder.newBuilder() .maximumSize(pluginConfig.getUpstreamAddressMaxSize()) // 设置缓存的最大容量 .expireAfterWrite(pluginConfig.getUpstreamAddressExpiredTime(), TimeUnit.SECONDS) // 设置缓存失效时间 + .removalListener(new RemovalListener() { + @Override + public void onRemoval(RemovalNotification notification) { + System.out.println(Thread.currentThread().getName() + LocalDateTime.now() + "remove" + + notification.getKey()); + System.out.println(Thread.currentThread().getName() + LocalDateTime.now() + "remove" + + notification.getValue()); + } + }) .build(); } @@ -52,6 +65,7 @@ public enum AddressCache { * @param address Address */ public void addAddress(String address) { + System.out.println(Thread.currentThread().getName() + LocalDateTime.now() + "add address: " + address); cache.put(address, ""); } @@ -61,13 +75,18 @@ public void addAddress(String address) { * @return Set Address Set */ public Set getAddressSet() { - return cache.asMap().keySet(); + Set strings = cache.asMap().keySet(); + System.out.println( + Thread.currentThread().getName() + LocalDateTime.now() + "getAddressSet: " + JSONObject.toJSONString( + strings)); + return strings; } /** * Clear all caches */ public void cleanCache() { + System.out.println(Thread.currentThread().getName() + LocalDateTime.now() + "cleanCache"); cache.invalidateAll(); } } \ No newline at end of file