This is an automated email from the ASF dual-hosted git repository.

chengzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 0eabc08f5df Rename ComputeNodeInstanceStateChangedEvent (#31303)
0eabc08f5df is described below

commit 0eabc08f5df7f198daef5bacada4d808235c4a7a
Author: Liang Zhang <[email protected]>
AuthorDate: Sun May 19 19:56:36 2024 +0800

    Rename ComputeNodeInstanceStateChangedEvent (#31303)
---
 .../shardingsphere/infra/instance/InstanceContext.java       | 12 ++++++------
 .../shardingsphere/infra/instance/InstanceContextTest.java   |  4 ++--
 ...eEvent.java => ComputeNodeInstanceStateChangedEvent.java} |  4 ++--
 .../compute/watcher/ComputeNodeStateChangedWatcher.java      |  4 ++--
 .../coordinator/subscriber/StateChangedSubscriber.java       | 10 +++++-----
 .../compute/watcher/ComputeNodeStateChangedWatcherTest.java  | 10 +++++-----
 .../coordinator/subscriber/StateChangedSubscriberTest.java   |  6 +++---
 7 files changed, 25 insertions(+), 25 deletions(-)

diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java
index d36e9fe74da..1c989927e80 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java
@@ -30,10 +30,10 @@ import 
org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
 
 import java.util.Collection;
 import java.util.LinkedHashMap;
-import java.util.LinkedList;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Properties;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 /**
  * Instance context.
@@ -56,19 +56,19 @@ public final class InstanceContext {
     
     private final EventBusContext eventBusContext;
     
-    private final Collection<ComputeNodeInstance> 
allClusterComputeNodeInstances = new LinkedList<>();
+    private final Collection<ComputeNodeInstance> 
allClusterComputeNodeInstances = new CopyOnWriteArrayList<>();
     
     /**
      * Update instance status.
      *
-     * @param instanceId instance id
+     * @param id instance ID
      * @param status status
      */
-    public void updateInstanceStatus(final String instanceId, final String 
status) {
-        if (instance.getMetaData().getId().equals(instanceId)) {
+    public void updateStatus(final String id, final String status) {
+        if (instance.getMetaData().getId().equals(id)) {
             instance.switchState(status);
         }
-        updateRelatedComputeNodeInstancesStatus(instanceId, status);
+        updateRelatedComputeNodeInstancesStatus(id, status);
     }
     
     private void updateRelatedComputeNodeInstancesStatus(final String 
instanceId, final String status) {
diff --git 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/instance/InstanceContextTest.java
 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/instance/InstanceContextTest.java
index 522949a9e65..8cb58569a79 100644
--- 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/instance/InstanceContextTest.java
+++ 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/instance/InstanceContextTest.java
@@ -58,10 +58,10 @@ class InstanceContextTest {
                 new WorkerIdGeneratorFixture(Integer.MIN_VALUE), modeConfig, 
modeContextManager, lockContext, eventBusContext);
         InstanceState actual = 
context.getInstance().getState().getCurrentState();
         assertThat(actual, is(InstanceState.OK));
-        context.updateInstanceStatus(instanceMetaData.getId(), 
InstanceState.CIRCUIT_BREAK.name());
+        context.updateStatus(instanceMetaData.getId(), 
InstanceState.CIRCUIT_BREAK.name());
         actual = context.getInstance().getState().getCurrentState();
         assertThat(actual, is(InstanceState.CIRCUIT_BREAK));
-        context.updateInstanceStatus(instanceMetaData.getId(), 
InstanceState.OK.name());
+        context.updateStatus(instanceMetaData.getId(), 
InstanceState.OK.name());
         actual = context.getInstance().getState().getCurrentState();
         assertThat(actual, is(InstanceState.OK));
     }
diff --git 
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/event/StateEvent.java
 
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/event/ComputeNodeInstanceStateChangedEvent.java
similarity index 89%
rename from 
mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/event/StateEvent.java
rename to 
mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/event/ComputeNodeInstanceStateChangedEvent.java
index 4d0e954ff81..6a6d86ca094 100644
--- 
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/event/StateEvent.java
+++ 
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/event/ComputeNodeInstanceStateChangedEvent.java
@@ -22,11 +22,11 @@ import lombok.RequiredArgsConstructor;
 import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
 
 /**
- * State event.
+ * Compute node instance state changed event.
  */
 @RequiredArgsConstructor
 @Getter
-public final class StateEvent implements GovernanceEvent {
+public final class ComputeNodeInstanceStateChangedEvent implements 
GovernanceEvent {
     
     private final String instanceId;
     
diff --git 
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/watcher/ComputeNodeStateChangedWatcher.java
 
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/watcher/ComputeNodeStateChangedWatcher.java
index aef26af8f1c..c2ec0416b53 100644
--- 
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/watcher/ComputeNodeStateChangedWatcher.java
+++ 
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/watcher/ComputeNodeStateChangedWatcher.java
@@ -33,7 +33,7 @@ import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.statu
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.LabelsEvent;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.ReportLocalProcessesCompletedEvent;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.ReportLocalProcessesEvent;
-import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.StateEvent;
+import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.ComputeNodeInstanceStateChangedEvent;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.WorkerIdEvent;
 import org.apache.shardingsphere.mode.event.DataChangedEvent;
 import org.apache.shardingsphere.mode.event.DataChangedEvent.Type;
@@ -85,7 +85,7 @@ public final class ComputeNodeStateChangedWatcher implements 
GovernanceWatcher<G
     @SuppressWarnings("unchecked")
     private Optional<GovernanceEvent> createInstanceGovernanceEvent(final 
DataChangedEvent event, final String instanceId) {
         if 
(event.getKey().equals(ComputeNode.getInstanceStatusNodePath(instanceId)) && 
Type.DELETED != event.getType()) {
-            return Optional.of(new StateEvent(instanceId, event.getValue()));
+            return Optional.of(new 
ComputeNodeInstanceStateChangedEvent(instanceId, event.getValue()));
         }
         if 
(event.getKey().equals(ComputeNode.getInstanceLabelsNodePath(instanceId)) && 
Type.DELETED != event.getType()) {
             return Optional.of(new LabelsEvent(instanceId, 
Strings.isNullOrEmpty(event.getValue()) ? new ArrayList<>() : 
YamlEngine.unmarshal(event.getValue(), Collection.class)));
diff --git 
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriber.java
 
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriber.java
index 296fadf72ee..f4d22d45676 100644
--- 
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriber.java
+++ 
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriber.java
@@ -32,7 +32,7 @@ import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.statu
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.InstanceOfflineEvent;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.InstanceOnlineEvent;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.LabelsEvent;
-import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.StateEvent;
+import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.ComputeNodeInstanceStateChangedEvent;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.WorkerIdEvent;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.service.ComputeNodeStatusService;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.event.StorageNodeChangedEvent;
@@ -92,13 +92,13 @@ public final class StateChangedSubscriber implements 
EventSubscriber {
     }
     
     /**
-     * Renew instance status.
+     * Renew compute node instance state.
      * 
-     * @param event state event
+     * @param event compute node instance state changed event
      */
     @Subscribe
-    public synchronized void renew(final StateEvent event) {
-        
contextManager.getInstanceContext().updateInstanceStatus(event.getInstanceId(), 
event.getStatus());
+    public synchronized void renew(final ComputeNodeInstanceStateChangedEvent 
event) {
+        
contextManager.getInstanceContext().updateStatus(event.getInstanceId(), 
event.getStatus());
     }
     
     /**
diff --git 
a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/watcher/ComputeNodeStateChangedWatcherTest.java
 
b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/watcher/ComputeNodeStateChangedWatcherTest.java
index b0ee5781295..08c74c5d1ef 100644
--- 
a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/watcher/ComputeNodeStateChangedWatcherTest.java
+++ 
b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/watcher/ComputeNodeStateChangedWatcherTest.java
@@ -21,7 +21,7 @@ import 
org.apache.shardingsphere.infra.state.instance.InstanceState;
 import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
 import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.LabelsEvent;
-import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.StateEvent;
+import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.ComputeNodeInstanceStateChangedEvent;
 import org.apache.shardingsphere.mode.event.DataChangedEvent;
 import org.apache.shardingsphere.mode.event.DataChangedEvent.Type;
 import org.junit.jupiter.api.Test;
@@ -40,8 +40,8 @@ class ComputeNodeStateChangedWatcherTest {
         Optional<GovernanceEvent> actual = new ComputeNodeStateChangedWatcher()
                 .createGovernanceEvent(new 
DataChangedEvent("/nodes/compute_nodes/status/foo_instance_id", 
InstanceState.CIRCUIT_BREAK.name(), Type.ADDED));
         assertTrue(actual.isPresent());
-        assertThat(((StateEvent) actual.get()).getStatus(), 
is(InstanceState.CIRCUIT_BREAK.name()));
-        assertThat(((StateEvent) actual.get()).getInstanceId(), 
is("foo_instance_id"));
+        assertThat(((ComputeNodeInstanceStateChangedEvent) 
actual.get()).getStatus(), is(InstanceState.CIRCUIT_BREAK.name()));
+        assertThat(((ComputeNodeInstanceStateChangedEvent) 
actual.get()).getInstanceId(), is("foo_instance_id"));
     }
     
     @Test
@@ -49,8 +49,8 @@ class ComputeNodeStateChangedWatcherTest {
         Optional<GovernanceEvent> actual = new ComputeNodeStateChangedWatcher()
                 .createGovernanceEvent(new 
DataChangedEvent("/nodes/compute_nodes/status/foo_instance_id", "", 
Type.UPDATED));
         assertTrue(actual.isPresent());
-        assertTrue(((StateEvent) actual.get()).getStatus().isEmpty());
-        assertThat(((StateEvent) actual.get()).getInstanceId(), 
is("foo_instance_id"));
+        assertTrue(((ComputeNodeInstanceStateChangedEvent) 
actual.get()).getStatus().isEmpty());
+        assertThat(((ComputeNodeInstanceStateChangedEvent) 
actual.get()).getInstanceId(), is("foo_instance_id"));
     }
     
     @Test
diff --git 
a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java
 
b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java
index adac8980c0b..4466440750e 100644
--- 
a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java
+++ 
b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java
@@ -41,7 +41,7 @@ import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.statu
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.InstanceOfflineEvent;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.InstanceOnlineEvent;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.LabelsEvent;
-import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.StateEvent;
+import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.ComputeNodeInstanceStateChangedEvent;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.WorkerIdEvent;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.event.StorageNodeChangedEvent;
 import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
@@ -136,8 +136,8 @@ class StateChangedSubscriberTest {
     
     @Test
     void assertRenewInstanceStatus() {
-        StateEvent mockStateEvent = new 
StateEvent(contextManager.getInstanceContext().getInstance().getMetaData().getId(),
 InstanceState.OK.name());
-        subscriber.renew(mockStateEvent);
+        ComputeNodeInstanceStateChangedEvent event = new 
ComputeNodeInstanceStateChangedEvent(contextManager.getInstanceContext().getInstance().getMetaData().getId(),
 InstanceState.OK.name());
+        subscriber.renew(event);
         
assertThat(contextManager.getInstanceContext().getInstance().getState().getCurrentState(),
 is(InstanceState.OK));
     }
     

Reply via email to