Skip to content

Commit

Permalink
*Fix graceful shutdown notify failure
Browse files Browse the repository at this point in the history
Signed-off-by: provenceee <[email protected]>
  • Loading branch information
provenceee committed Sep 24, 2024
1 parent cdc94bb commit 90341fc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -43,6 +47,15 @@ public enum AddressCache {
cache = CacheBuilder.newBuilder()
.maximumSize(pluginConfig.getUpstreamAddressMaxSize()) // 设置缓存的最大容量
.expireAfterWrite(pluginConfig.getUpstreamAddressExpiredTime(), TimeUnit.SECONDS) // 设置缓存失效时间
.removalListener(new RemovalListener<Object, Object>() {
@Override
public void onRemoval(RemovalNotification<Object, Object> notification) {
System.out.println(Thread.currentThread().getName() + LocalDateTime.now() + "remove"
+ notification.getKey());
System.out.println(Thread.currentThread().getName() + LocalDateTime.now() + "remove"
+ notification.getValue());
}
})
.build();
}

Expand All @@ -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, "");
}

Expand All @@ -61,13 +75,18 @@ public void addAddress(String address) {
* @return Set Address Set
*/
public Set<String> getAddressSet() {
return cache.asMap().keySet();
Set<String> 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();
}
}

0 comments on commit 90341fc

Please sign in to comment.