|
17 | 17 |
|
18 | 18 | package org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.global.node;
|
19 | 19 |
|
| 20 | +import org.apache.shardingsphere.infra.instance.ClusterInstanceRegistry; |
20 | 21 | import org.apache.shardingsphere.infra.instance.ComputeNodeData;
|
21 | 22 | import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
|
22 | 23 | import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData;
|
@@ -56,14 +57,19 @@ public void handle(final ContextManager contextManager, final DataChangedEvent e
|
56 | 57 | if (!NodePathSearcher.isMatchedPath(event.getKey(), OnlineNodePath.createInstanceIdSearchCriteria())) {
|
57 | 58 | return;
|
58 | 59 | }
|
| 60 | + ClusterInstanceRegistry clusterInstanceRegistry = contextManager.getComputeNodeInstanceContext().getClusterInstanceRegistry(); |
59 | 61 | 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()); |
61 | 63 | ComputeNodeData computeNodeData = new YamlComputeNodeDataSwapper().swapToObject(YamlEngine.unmarshal(event.getValue(), YamlComputeNodeData.class));
|
62 | 64 | 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: |
67 | 73 | }
|
68 | 74 | }
|
69 | 75 | }
|
0 commit comments