diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java index 3456426cbe47b..27f3f9a686008 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java @@ -31,7 +31,6 @@ import org.apache.shardingsphere.mode.manager.ContextManagerAware; import org.apache.shardingsphere.mode.manager.ContextManagerBuilder; import org.apache.shardingsphere.mode.manager.ContextManagerBuilderParameter; -import org.apache.shardingsphere.mode.manager.cluster.coordinator.RegistryCenter; import org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.GlobalLockPersistService; import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcherFactory; import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.subscriber.ShardingSphereSchemaDataRegistrySubscriber; @@ -65,17 +64,16 @@ public final class ClusterContextManagerBuilder implements ContextManagerBuilder @Override public ContextManager build(final ContextManagerBuilderParameter param, final EventBusContext eventBusContext) throws SQLException { ClusterPersistRepository repository = getClusterPersistRepository((ClusterPersistRepositoryConfiguration) param.getModeConfiguration().getRepository()); - RegistryCenter registryCenter = new RegistryCenter(eventBusContext, repository, param.getInstanceMetaData(), param.getDatabaseConfigs()); InstanceContext instanceContext = buildInstanceContext(repository, param, eventBusContext); - if (registryCenter.getRepository() instanceof InstanceContextAware) { - ((InstanceContextAware) registryCenter.getRepository()).setInstanceContext(instanceContext); + if (repository instanceof InstanceContextAware) { + ((InstanceContextAware) repository).setInstanceContext(instanceContext); } MetaDataPersistService metaDataPersistService = new MetaDataPersistService(repository); MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(metaDataPersistService, param, instanceContext, new QualifiedDataSourceStatusService(repository).loadStatus()); ContextManager result = new ContextManager(metaDataContexts, instanceContext); setContextManagerAware(result); createSubscribers(eventBusContext, repository); - registerOnline(eventBusContext, instanceContext, registryCenter, param, result); + registerOnline(eventBusContext, instanceContext, repository, param, result); setClusterState(repository, result); return result; } @@ -111,16 +109,16 @@ private void createSubscribers(final EventBusContext eventBusContext, final Clus } private void registerOnline(final EventBusContext eventBusContext, final InstanceContext instanceContext, - final RegistryCenter registryCenter, final ContextManagerBuilderParameter param, final ContextManager contextManager) { - ComputeNodeStatusService computeNodeStatusService = new ComputeNodeStatusService(registryCenter.getRepository()); + final ClusterPersistRepository repository, final ContextManagerBuilderParameter param, final ContextManager contextManager) { + ComputeNodeStatusService computeNodeStatusService = new ComputeNodeStatusService(repository); computeNodeStatusService.registerOnline(instanceContext.getInstance().getMetaData()); computeNodeStatusService.persistInstanceLabels(instanceContext.getInstance().getCurrentInstanceId(), instanceContext.getInstance().getLabels()); computeNodeStatusService.persistInstanceState(instanceContext.getInstance().getCurrentInstanceId(), instanceContext.getInstance().getState()); - new GovernanceWatcherFactory(registryCenter.getRepository(), + new GovernanceWatcherFactory(repository, eventBusContext, param.getInstanceMetaData() instanceof JDBCInstanceMetaData ? param.getDatabaseConfigs().keySet() : Collections.emptyList()).watchListeners(); contextManager.getInstanceContext().getInstance().setLabels(param.getLabels()); - contextManager.getInstanceContext().getAllClusterInstances().addAll(new ComputeNodeStatusService(registryCenter.getRepository()).loadAllComputeNodeInstances()); - new ClusterEventSubscriberRegistry(contextManager, registryCenter).register(); + contextManager.getInstanceContext().getAllClusterInstances().addAll(new ComputeNodeStatusService(repository).loadAllComputeNodeInstances()); + new ClusterEventSubscriberRegistry(contextManager, repository).register(); } private void setClusterState(final ClusterPersistRepository repository, final ContextManager contextManager) { diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ClusterEventSubscriberRegistry.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ClusterEventSubscriberRegistry.java index 06b88cce8e9b0..7c421b5de1c41 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ClusterEventSubscriberRegistry.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ClusterEventSubscriberRegistry.java @@ -18,8 +18,8 @@ package org.apache.shardingsphere.mode.manager.cluster.coordinator.subscriber; import org.apache.shardingsphere.mode.manager.ContextManager; -import org.apache.shardingsphere.mode.manager.cluster.coordinator.RegistryCenter; import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.process.subscriber.ProcessListChangedSubscriber; +import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; import org.apache.shardingsphere.mode.subsciber.EventSubscriberRegistry; import org.apache.shardingsphere.mode.subsciber.RuleItemChangedSubscriber; @@ -28,15 +28,15 @@ */ public final class ClusterEventSubscriberRegistry extends EventSubscriberRegistry { - public ClusterEventSubscriberRegistry(final ContextManager contextManager, final RegistryCenter registryCenter) { + public ClusterEventSubscriberRegistry(final ContextManager contextManager, final ClusterPersistRepository repository) { super(contextManager, new RuleItemChangedSubscriber(contextManager), new ConfigurationChangedSubscriber(contextManager), new ConfigurationChangedSubscriber(contextManager), new ResourceMetaDataChangedSubscriber(contextManager), - new StateChangedSubscriber(contextManager, registryCenter.getRepository()), + new StateChangedSubscriber(contextManager, repository), new DatabaseChangedSubscriber(contextManager), - new ProcessListChangedSubscriber(contextManager, registryCenter.getRepository()), + new ProcessListChangedSubscriber(contextManager, repository), new CacheEvictedSubscriber()); } }