This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 9938d48ea1d Remove DispatchEventBuilder (#34217)
9938d48ea1d is described below
commit 9938d48ea1df04d6e9953432b80637775d388659
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Jan 1 15:00:13 2025 +0800
Remove DispatchEventBuilder (#34217)
* Remove DispatchEventBuilder
* Remove DispatchEventBuilder
---
.../dispatch/builder/DispatchEventBuilder.java | 56 -----------------
.../listener/DataChangedEventListenerRegistry.java | 7 ---
.../type/GlobalMetaDataChangedListener.java | 42 -------------
...ter.event.dispatch.builder.DispatchEventBuilder | 16 -----
.../type/GlobalMetaDataChangedListenerTest.java | 70 ----------------------
5 files changed, 191 deletions(-)
diff --git
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/DispatchEventBuilder.java
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/DispatchEventBuilder.java
deleted file mode 100644
index 1ea4ab224ae..00000000000
---
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/DispatchEventBuilder.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder;
-
-import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI;
-import org.apache.shardingsphere.mode.event.DataChangedEvent;
-import org.apache.shardingsphere.mode.event.DataChangedEvent.Type;
-
-import java.util.Collection;
-import java.util.Optional;
-
-/**
- * Dispatch event builder.
- *
- * @param <T> type of event
- */
-@SingletonSPI
-public interface DispatchEventBuilder<T> {
-
- /**
- * Get subscribed key.
- *
- * @return subscribed key
- */
- String getSubscribedKey();
-
- /**
- * Get subscribed types.
- *
- * @return subscribed types
- */
- Collection<Type> getSubscribedTypes();
-
- /**
- * Create dispatch event.
- *
- * @param event registry center data changed event
- * @return dispatch event
- */
- Optional<T> build(DataChangedEvent event);
-}
diff --git
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DataChangedEventListenerRegistry.java
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DataChangedEventListenerRegistry.java
index 9122a5006c9..052a89e1434 100644
---
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DataChangedEventListenerRegistry.java
+++
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DataChangedEventListenerRegistry.java
@@ -21,11 +21,9 @@ import
org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
import org.apache.shardingsphere.metadata.persist.node.DatabaseMetaDataNode;
import org.apache.shardingsphere.mode.manager.ContextManager;
-import
org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.DispatchEventBuilder;
import
org.apache.shardingsphere.mode.manager.cluster.event.dispatch.handler.DataChangedEventHandler;
import
org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener.type.DatabaseMetaDataChangedListener;
import
org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener.type.GlobalMetaDataChangedHandler;
-import
org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener.type.GlobalMetaDataChangedListener;
import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
import java.util.Collection;
@@ -55,7 +53,6 @@ public final class DataChangedEventListenerRegistry {
*/
public void register() {
databaseNames.forEach(this::registerDatabaseListeners);
-
ShardingSphereServiceLoader.getServiceInstances(DispatchEventBuilder.class).forEach(this::registerGlobalListeners);
ShardingSphereServiceLoader.getServiceInstances(DataChangedEventHandler.class).forEach(this::registerGlobalHandlers);
}
@@ -63,10 +60,6 @@ public final class DataChangedEventListenerRegistry {
repository.watch(DatabaseMetaDataNode.getDatabaseNamePath(databaseName), new
DatabaseMetaDataChangedListener(eventBusContext));
}
- private void registerGlobalListeners(final DispatchEventBuilder<?>
builder) {
- repository.watch(builder.getSubscribedKey(), new
GlobalMetaDataChangedListener(eventBusContext, builder));
- }
-
private void registerGlobalHandlers(final DataChangedEventHandler handler)
{
repository.watch(handler.getSubscribedKey(), new
GlobalMetaDataChangedHandler(contextManager, handler));
}
diff --git
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/GlobalMetaDataChangedListener.java
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/GlobalMetaDataChangedListener.java
deleted file mode 100644
index cbdc96d6a0d..00000000000
---
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/GlobalMetaDataChangedListener.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package
org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener.type;
-
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
-import org.apache.shardingsphere.mode.event.DataChangedEvent;
-import
org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.DispatchEventBuilder;
-import
org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEventListener;
-
-/**
- * Global meta data changed listener.
- */
-@RequiredArgsConstructor
-public final class GlobalMetaDataChangedListener implements
DataChangedEventListener {
-
- private final EventBusContext eventBusContext;
-
- private final DispatchEventBuilder<?> eventBuilder;
-
- @Override
- public void onChange(final DataChangedEvent event) {
- if (eventBuilder.getSubscribedTypes().contains(event.getType())) {
- eventBuilder.build(event).ifPresent(eventBusContext::post);
- }
- }
-}
diff --git
a/mode/type/cluster/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.DispatchEventBuilder
b/mode/type/cluster/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.DispatchEventBuilder
deleted file mode 100644
index b1312a0905c..00000000000
---
a/mode/type/cluster/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.DispatchEventBuilder
+++ /dev/null
@@ -1,16 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
diff --git
a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/GlobalMetaDataChangedListenerTest.java
b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/GlobalMetaDataChangedListenerTest.java
deleted file mode 100644
index 14ea417fa57..00000000000
---
a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/GlobalMetaDataChangedListenerTest.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package
org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener.type;
-
-import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
-import org.apache.shardingsphere.mode.event.DataChangedEvent;
-import org.apache.shardingsphere.mode.event.DataChangedEvent.Type;
-import
org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.DispatchEventBuilder;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
-
-import java.util.Collections;
-import java.util.Optional;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-@ExtendWith(MockitoExtension.class)
-class GlobalMetaDataChangedListenerTest {
-
- private GlobalMetaDataChangedListener listener;
-
- @Mock
- private EventBusContext eventBusContext;
-
- @Mock
- private DispatchEventBuilder<Object> builder;
-
- @BeforeEach
- void setUp() {
- listener = new GlobalMetaDataChangedListener(eventBusContext, builder);
-
when(builder.getSubscribedTypes()).thenReturn(Collections.singleton(Type.ADDED));
- }
-
- @Test
- void assertOnChangeWithUnsupportedType() {
- DataChangedEvent event = new DataChangedEvent("key", "value",
Type.DELETED);
- listener.onChange(event);
- verify(builder, times(0)).build(event);
- }
-
- @Test
- void assertOnChangeWithSupportedType() {
- DataChangedEvent event = new DataChangedEvent("key", "value",
Type.ADDED);
- Object builtEvent = mock(Object.class);
- when(builder.build(event)).thenReturn(Optional.of(builtEvent));
- listener.onChange(event);
- verify(eventBusContext).post(builtEvent);
- }
-}