Skip to content

Commit 27be65e

Browse files
authored
Refactor ComputeNodeOnlineHandler (#34936)
1 parent 811e0f5 commit 27be65e

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/node/ComputeNodeOnlineHandler.java

+11-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.global.node;
1919

20+
import org.apache.shardingsphere.infra.instance.ClusterInstanceRegistry;
2021
import org.apache.shardingsphere.infra.instance.ComputeNodeData;
2122
import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
2223
import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData;
@@ -56,14 +57,19 @@ public void handle(final ContextManager contextManager, final DataChangedEvent e
5657
if (!NodePathSearcher.isMatchedPath(event.getKey(), OnlineNodePath.createInstanceIdSearchCriteria())) {
5758
return;
5859
}
60+
ClusterInstanceRegistry clusterInstanceRegistry = contextManager.getComputeNodeInstanceContext().getClusterInstanceRegistry();
5961
InstanceType instanceType = InstanceType.valueOf(NodePathSearcher.get(event.getKey(), OnlineNodePath.createInstanceTypeSearchCriteria()).toUpperCase());
60-
String instanceId = NodePathSearcher.find(event.getKey(), OnlineNodePath.createInstanceIdSearchCriteria()).orElse("");
62+
String instanceId = NodePathSearcher.get(event.getKey(), OnlineNodePath.createInstanceIdSearchCriteria());
6163
ComputeNodeData computeNodeData = new YamlComputeNodeDataSwapper().swapToObject(YamlEngine.unmarshal(event.getValue(), YamlComputeNodeData.class));
6264
InstanceMetaData instanceMetaData = InstanceMetaDataFactory.create(instanceId, instanceType, computeNodeData);
63-
if (Type.ADDED == event.getType()) {
64-
contextManager.getComputeNodeInstanceContext().getClusterInstanceRegistry().add(contextManager.getPersistServiceFacade().getComputeNodePersistService().loadInstance(instanceMetaData));
65-
} else if (Type.DELETED == event.getType()) {
66-
contextManager.getComputeNodeInstanceContext().getClusterInstanceRegistry().delete(new ComputeNodeInstance(instanceMetaData));
65+
switch (event.getType()) {
66+
case ADDED:
67+
clusterInstanceRegistry.add(contextManager.getPersistServiceFacade().getComputeNodePersistService().loadInstance(instanceMetaData));
68+
break;
69+
case DELETED:
70+
clusterInstanceRegistry.delete(new ComputeNodeInstance(instanceMetaData));
71+
break;
72+
default:
6773
}
6874
}
6975
}

0 commit comments

Comments
 (0)