parent
f9d696beb4
commit
3d8b2c0b17
@ -42,7 +42,7 @@ public class NamingGrpcConnectionEventListener implements ConnectionEventListene
|
|||||||
|
|
||||||
private final NamingGrpcClientProxy clientProxy;
|
private final NamingGrpcClientProxy clientProxy;
|
||||||
|
|
||||||
private final ConcurrentMap<String, Set<Instance>> registeredInstanceCached = new ConcurrentHashMap<String, Set<Instance>>();
|
private final ConcurrentMap<String, Instance> registeredInstanceCached = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private final Set<String> subscribes = new ConcurrentHashSet<String>();
|
private final Set<String> subscribes = new ConcurrentHashSet<String>();
|
||||||
|
|
||||||
@ -70,21 +70,19 @@ public class NamingGrpcConnectionEventListener implements ConnectionEventListene
|
|||||||
|
|
||||||
private void redoRegisterEachService() {
|
private void redoRegisterEachService() {
|
||||||
LogUtils.NAMING_LOGGER.info("Grpc re-connect, redo register services");
|
LogUtils.NAMING_LOGGER.info("Grpc re-connect, redo register services");
|
||||||
for (Map.Entry<String, Set<Instance>> each : registeredInstanceCached.entrySet()) {
|
for (Map.Entry<String, Instance> each : registeredInstanceCached.entrySet()) {
|
||||||
String serviceName = NamingUtils.getServiceName(each.getKey());
|
String serviceName = NamingUtils.getServiceName(each.getKey());
|
||||||
String groupName = NamingUtils.getGroupName(each.getKey());
|
String groupName = NamingUtils.getGroupName(each.getKey());
|
||||||
redoRegisterEachInstance(serviceName, groupName, each.getValue());
|
redoRegisterEachInstance(serviceName, groupName, each.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void redoRegisterEachInstance(String serviceName, String groupName, Set<Instance> instances) {
|
private void redoRegisterEachInstance(String serviceName, String groupName, Instance instance) {
|
||||||
for (Instance each : instances) {
|
try {
|
||||||
try {
|
clientProxy.registerService(serviceName, groupName, instance);
|
||||||
clientProxy.registerService(serviceName, groupName, each);
|
} catch (NacosException e) {
|
||||||
} catch (NacosException e) {
|
LogUtils.NAMING_LOGGER.warn(String
|
||||||
LogUtils.NAMING_LOGGER
|
.format("redo register for service %s@@%s, %s failed", groupName, serviceName, instance.toString()), e);
|
||||||
.warn(String.format("redo register for service %s@@%s failed", groupName, serviceName), e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,8 +100,7 @@ public class NamingGrpcConnectionEventListener implements ConnectionEventListene
|
|||||||
*/
|
*/
|
||||||
public void cacheInstanceForRedo(String serviceName, String groupName, Instance instance) {
|
public void cacheInstanceForRedo(String serviceName, String groupName, Instance instance) {
|
||||||
String key = NamingUtils.getGroupedName(serviceName, groupName);
|
String key = NamingUtils.getGroupedName(serviceName, groupName);
|
||||||
registeredInstanceCached.putIfAbsent(key, new ConcurrentHashSet<Instance>());
|
registeredInstanceCached.put(key, instance);
|
||||||
registeredInstanceCached.get(key).add(instance);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -115,10 +112,7 @@ public class NamingGrpcConnectionEventListener implements ConnectionEventListene
|
|||||||
*/
|
*/
|
||||||
public void removeInstanceForRedo(String serviceName, String groupName, Instance instance) {
|
public void removeInstanceForRedo(String serviceName, String groupName, Instance instance) {
|
||||||
String key = NamingUtils.getGroupedName(serviceName, groupName);
|
String key = NamingUtils.getGroupedName(serviceName, groupName);
|
||||||
Set<Instance> instances = registeredInstanceCached.get(key);
|
registeredInstanceCached.remove(key);
|
||||||
if (null != instances) {
|
|
||||||
instances.remove(instance);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cacheSubscriberForRedo(String fullServiceName, String cluster) {
|
public void cacheSubscriberForRedo(String fullServiceName, String cluster) {
|
||||||
|
Loading…
Reference in New Issue
Block a user