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

soulasuna 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 106d38706c3 Remove ScheduleStrategy singleton and bind with 
InstanceContext (#20794)
106d38706c3 is described below

commit 106d38706c31fe115b11a4e252db364dd23df2b0
Author: zhaojinchao <[email protected]>
AuthorDate: Mon Sep 5 19:06:49 2022 +0800

    Remove ScheduleStrategy singleton and bind with InstanceContext (#20794)
---
 .../collector/ProxyInfoCollectorTest.java          |  3 +-
 .../service/PrometheusPluginBootServiceTest.java   |  3 +-
 .../dbdiscovery/rule/DatabaseDiscoveryRule.java    | 18 ++++-----
 .../route/DatabaseDiscoverySQLRouterTest.java      |  8 +---
 .../rule/DatabaseDiscoveryRuleTest.java            |  8 +---
 ...hmProvidedDatabaseDiscoveryRuleBuilderTest.java |  3 +-
 .../builder/DatabaseDiscoveryRuleBuilderTest.java  |  3 +-
 .../keygen/SnowflakeKeyGenerateAlgorithmTest.java  |  5 ++-
 .../CosIdSnowflakeKeyGenerateAlgorithmTest.java    | 12 +++---
 .../infra/instance/InstanceContext.java            |  7 +++-
 .../shardingsphere/infra/schedule}/CronJob.java    |  2 +-
 .../infra/schedule/ScheduleContext.java            |  6 +--
 .../infra/instance/InstanceContextTest.java        | 27 ++++++++-----
 .../builder/global/GlobalRulesBuilderTest.java     |  3 +-
 .../schedule/core/ScheduleContextFactory.java      | 44 +++++-----------------
 .../ClusterScheduleContext.java}                   | 10 ++---
 .../StandaloneScheduleContext.java}                | 10 ++---
 .../cluster/ClusterContextManagerBuilder.java      |  4 +-
 .../StandaloneContextManagerBuilder.java           |  4 +-
 19 files changed, 77 insertions(+), 103 deletions(-)

diff --git 
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollectorTest.java
 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollectorTest.java
index a3741d72945..08bc9cc32a4 100644
--- 
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollectorTest.java
+++ 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollectorTest.java
@@ -24,6 +24,7 @@ import 
org.apache.shardingsphere.infra.instance.InstanceContext;
 import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData;
 import org.apache.shardingsphere.infra.lock.LockContext;
 import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.schedule.ScheduleContext;
 import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
 import org.apache.shardingsphere.mode.manager.ContextManager;
 import 
org.apache.shardingsphere.mode.manager.standalone.workerid.generator.StandaloneWorkerIdGenerator;
@@ -42,7 +43,7 @@ public final class ProxyInfoCollectorTest extends 
ProxyContextRestorer {
         MetaDataContexts metaDataContexts = new 
MetaDataContexts(mock(MetaDataPersistService.class), new 
ShardingSphereMetaData());
         InstanceContext instanceContext = new InstanceContext(
                 new ComputeNodeInstance(mock(InstanceMetaData.class)), new 
StandaloneWorkerIdGenerator(), new ModeConfiguration("Standalone", null, 
false), mock(LockContext.class),
-                new EventBusContext());
+                new EventBusContext(), mock(ScheduleContext.class));
         ProxyContext.init(new ContextManager(metaDataContexts, 
instanceContext));
         assertFalse(new ProxyInfoCollector().collect().isEmpty());
     }
diff --git 
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootServiceTest.java
 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootServiceTest.java
index 8f6dcd45f17..ab2fcfc7aca 100644
--- 
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootServiceTest.java
+++ 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootServiceTest.java
@@ -25,6 +25,7 @@ import 
org.apache.shardingsphere.infra.instance.InstanceContext;
 import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData;
 import org.apache.shardingsphere.infra.lock.LockContext;
 import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.schedule.ScheduleContext;
 import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
 import org.apache.shardingsphere.mode.manager.ContextManager;
 import 
org.apache.shardingsphere.mode.manager.standalone.workerid.generator.StandaloneWorkerIdGenerator;
@@ -55,7 +56,7 @@ public final class PrometheusPluginBootServiceTest extends 
ProxyContextRestorer
         MetaDataContexts metaDataContexts = new 
MetaDataContexts(mock(MetaDataPersistService.class), new 
ShardingSphereMetaData());
         InstanceContext instanceContext = new InstanceContext(
                 new ComputeNodeInstance(mock(InstanceMetaData.class)), new 
StandaloneWorkerIdGenerator(), new ModeConfiguration("Standalone", null, 
false), mock(LockContext.class),
-                new EventBusContext());
+                new EventBusContext(), mock(ScheduleContext.class));
         ProxyContext.init(new ContextManager(metaDataContexts, 
instanceContext));
         PROMETHEUS_PLUGIN_BOOT_SERVICE.start(new 
PluginConfiguration("localhost", 8090, "", createProperties()));
         new Socket().connect(new InetSocketAddress("localhost", 8090));
diff --git 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
index e0251318067..6ea7eff5213 100644
--- 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
@@ -38,12 +38,10 @@ import 
org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule;
 import 
org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
 import 
org.apache.shardingsphere.infra.rule.identifier.type.DynamicDataSourceContainedRule;
 import 
org.apache.shardingsphere.infra.rule.identifier.type.exportable.ExportableRule;
+import org.apache.shardingsphere.infra.schedule.CronJob;
 import org.apache.shardingsphere.mode.metadata.storage.StorageNodeStatus;
 import 
org.apache.shardingsphere.mode.metadata.storage.event.PrimaryDataSourceChangedEvent;
 import 
org.apache.shardingsphere.mode.metadata.storage.event.StorageNodeDataSourceChangedEvent;
-import org.apache.shardingsphere.schedule.core.ScheduleContextFactory;
-import org.apache.shardingsphere.schedule.core.model.CronJob;
-import org.apache.shardingsphere.schedule.core.strategy.ScheduleStrategy;
 
 import javax.sql.DataSource;
 import java.util.Collection;
@@ -82,7 +80,7 @@ public final class DatabaseDiscoveryRule implements 
DatabaseRule, DataSourceCont
         discoveryTypes = 
getDiscoveryProviderAlgorithms(ruleConfig.getDiscoveryTypes());
         dataSourceRules = getDataSourceRules(ruleConfig.getDataSources(), 
ruleConfig.getDiscoveryHeartbeats());
         findPrimaryReplicaRelationship(databaseName, dataSourceMap);
-        
initHeartBeatJobs(instanceContext.getInstance().getCurrentInstanceId());
+        initHeartBeatJobs();
     }
     
     public DatabaseDiscoveryRule(final String databaseName,
@@ -94,7 +92,7 @@ public final class DatabaseDiscoveryRule implements 
DatabaseRule, DataSourceCont
         discoveryTypes = ruleConfig.getDiscoveryTypes();
         dataSourceRules = getDataSourceRules(ruleConfig.getDataSources(), 
ruleConfig.getDiscoveryHeartbeats());
         findPrimaryReplicaRelationship(databaseName, dataSourceMap);
-        
initHeartBeatJobs(instanceContext.getInstance().getCurrentInstanceId());
+        initHeartBeatJobs();
     }
     
     private static Map<String, DatabaseDiscoveryProviderAlgorithm> 
getDiscoveryProviderAlgorithms(final Map<String, AlgorithmConfiguration> 
discoveryTypesConfig) {
@@ -162,27 +160,25 @@ public final class DatabaseDiscoveryRule implements 
DatabaseRule, DataSourceCont
         DatabaseDiscoveryDataSourceRule dataSourceRule = 
dataSourceRules.get(qualifiedDatabase.getGroupName());
         Preconditions.checkState(null != dataSourceRule, "Can 't find database 
discovery data source rule in database `%s`.", databaseName);
         
dataSourceRule.changePrimaryDataSourceName(qualifiedDatabase.getDataSourceName());
-        
initHeartBeatJobs(instanceContext.getInstance().getCurrentInstanceId());
+        initHeartBeatJobs();
     }
     
     @Override
     public void closeHeartBeatJob() {
-        ScheduleStrategy scheduleStrategy = 
ScheduleContextFactory.getInstance().get(instanceContext.getInstance().getCurrentInstanceId());
         for (Entry<String, DatabaseDiscoveryDataSourceRule> entry : 
dataSourceRules.entrySet()) {
             DatabaseDiscoveryDataSourceRule rule = entry.getValue();
-            
scheduleStrategy.closeSchedule(rule.getDatabaseDiscoveryProviderAlgorithm().getType()
 + "-" + databaseName + "-" + rule.getGroupName());
+            
instanceContext.getScheduleContext().closeSchedule(rule.getDatabaseDiscoveryProviderAlgorithm().getType()
 + "-" + databaseName + "-" + rule.getGroupName());
         }
     }
     
-    private void initHeartBeatJobs(final String instanceId) {
-        ScheduleStrategy scheduleStrategy = 
ScheduleContextFactory.getInstance().get(instanceId);
+    private void initHeartBeatJobs() {
         for (Entry<String, DatabaseDiscoveryDataSourceRule> entry : 
dataSourceRules.entrySet()) {
             DatabaseDiscoveryDataSourceRule rule = entry.getValue();
             String jobName = 
rule.getDatabaseDiscoveryProviderAlgorithm().getType() + "-" + databaseName + 
"-" + rule.getGroupName();
             CronJob job = new CronJob(jobName, each -> new 
HeartbeatJob(databaseName, rule.getGroupName(), 
rule.getPrimaryDataSourceName(), rule.getDataSourceGroup(dataSourceMap),
                     rule.getDatabaseDiscoveryProviderAlgorithm(), 
rule.getDisabledDataSourceNames(), 
instanceContext.getEventBusContext()).execute(null),
                     rule.getHeartbeatProps().getProperty("keep-alive-cron"));
-            scheduleStrategy.startSchedule(job);
+            instanceContext.getScheduleContext().startSchedule(job);
         }
     }
     
diff --git 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouterTest.java
 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouterTest.java
index 82e71b17b71..e82f6a0d77d 100644
--- 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouterTest.java
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouterTest.java
@@ -41,7 +41,6 @@ import 
org.apache.shardingsphere.infra.route.context.RouteUnit;
 import org.apache.shardingsphere.schedule.core.ScheduleContextFactory;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
 import org.apache.shardingsphere.test.mock.MockedDataSource;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -76,7 +75,7 @@ public final class DatabaseDiscoverySQLRouterTest {
     
     @Before
     public void setUp() {
-        ScheduleContextFactory.getInstance().init("foo_id", new 
ModeConfiguration("Cluster", mock(PersistRepositoryConfiguration.class), 
false));
+        ScheduleContextFactory.newInstance(new ModeConfiguration("Cluster", 
mock(PersistRepositoryConfiguration.class), false));
         DatabaseDiscoveryDataSourceRuleConfiguration dataSourceConfig = new 
DatabaseDiscoveryDataSourceRuleConfiguration(
                 DATA_SOURCE_NAME, 
Collections.singletonList(PRIMARY_DATA_SOURCE), "", "CORE.FIXTURE");
         AlgorithmConfiguration algorithmConfig = new 
AlgorithmConfiguration("CORE.FIXTURE", new Properties());
@@ -89,11 +88,6 @@ public final class DatabaseDiscoverySQLRouterTest {
         sqlRouter = (DatabaseDiscoverySQLRouter) 
SQLRouterFactory.getInstances(Collections.singleton(rule)).get(rule);
     }
     
-    @After
-    public void tearDown() {
-        
ScheduleContextFactory.getInstance().getScheduleStrategy().remove("foo_id");
-    }
-    
     @Test
     public void assertCreateRouteContextToPrimaryWithoutRouteUnits() {
         QueryContext queryContext = new 
QueryContext(mock(SQLStatementContext.class), "", Collections.emptyList());
diff --git 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java
 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java
index 144a84264dc..85946b88720 100644
--- 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java
@@ -27,7 +27,6 @@ import 
org.apache.shardingsphere.infra.distsql.constant.ExportableConstants;
 import org.apache.shardingsphere.infra.instance.InstanceContext;
 import org.apache.shardingsphere.schedule.core.ScheduleContextFactory;
 import org.apache.shardingsphere.test.mock.MockedDataSource;
-import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -53,12 +52,7 @@ public final class DatabaseDiscoveryRuleTest {
     
     @BeforeClass
     public static void setUp() {
-        ScheduleContextFactory.getInstance().init("foo_id", new 
ModeConfiguration("Cluster", mock(PersistRepositoryConfiguration.class), 
false));
-    }
-    
-    @AfterClass
-    public static void tearDown() {
-        
ScheduleContextFactory.getInstance().getScheduleStrategy().remove("foo_id");
+        ScheduleContextFactory.newInstance(new ModeConfiguration("Cluster", 
mock(PersistRepositoryConfiguration.class), false));
     }
     
     @Test
diff --git 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/AlgorithmProvidedDatabaseDiscoveryRuleBuilderTest.java
 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/AlgorithmProvidedDatabaseDiscoveryRuleBuilderTest.java
index 18cbc7d5228..e3946e061c1 100644
--- 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/AlgorithmProvidedDatabaseDiscoveryRuleBuilderTest.java
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/AlgorithmProvidedDatabaseDiscoveryRuleBuilderTest.java
@@ -45,7 +45,7 @@ public final class 
AlgorithmProvidedDatabaseDiscoveryRuleBuilderTest {
     @SuppressWarnings({"rawtypes", "unchecked"})
     @Test
     public void assertBuild() {
-        ScheduleContextFactory.getInstance().init("foo_id", new 
ModeConfiguration("Cluster", mock(PersistRepositoryConfiguration.class), 
false));
+        ScheduleContextFactory.newInstance(new ModeConfiguration("Cluster", 
mock(PersistRepositoryConfiguration.class), false));
         AlgorithmProvidedDatabaseDiscoveryRuleConfiguration 
algorithmProvidedRuleConfig = new 
AlgorithmProvidedDatabaseDiscoveryRuleConfiguration(
                 Collections.singletonList(new 
DatabaseDiscoveryDataSourceRuleConfiguration("name", 
Collections.singletonList("name"), "", "discoveryTypeName")),
                 Collections.singletonMap("ha_heartbeat", new 
DatabaseDiscoveryHeartBeatConfiguration(new Properties())),
@@ -55,6 +55,5 @@ public final class 
AlgorithmProvidedDatabaseDiscoveryRuleBuilderTest {
         
when(instanceContext.getInstance().getCurrentInstanceId()).thenReturn("foo_id");
         assertThat(builder.build(algorithmProvidedRuleConfig, "",
                 Collections.singletonMap("name", new MockedDataSource()), 
Collections.emptyList(), instanceContext), 
instanceOf(DatabaseDiscoveryRule.class));
-        
ScheduleContextFactory.getInstance().getScheduleStrategy().remove("foo_id");
     }
 }
diff --git 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilderTest.java
 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilderTest.java
index 639516f4926..65422e2243b 100644
--- 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilderTest.java
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilderTest.java
@@ -45,7 +45,7 @@ public final class DatabaseDiscoveryRuleBuilderTest {
     @SuppressWarnings({"rawtypes", "unchecked"})
     @Test
     public void assertBuild() {
-        ScheduleContextFactory.getInstance().init("foo_id", new 
ModeConfiguration("Cluster", mock(PersistRepositoryConfiguration.class), 
false));
+        ScheduleContextFactory.newInstance(new ModeConfiguration("Cluster", 
mock(PersistRepositoryConfiguration.class), false));
         DatabaseDiscoveryRuleConfiguration config = new 
DatabaseDiscoveryRuleConfiguration(
                 Collections.singleton(new 
DatabaseDiscoveryDataSourceRuleConfiguration("name", 
Collections.singletonList("name"), "", "CORE.FIXTURE")),
                 Collections.singletonMap("ha_heartbeat", new 
DatabaseDiscoveryHeartBeatConfiguration(new Properties())),
@@ -55,6 +55,5 @@ public final class DatabaseDiscoveryRuleBuilderTest {
         
when(instanceContext.getInstance().getCurrentInstanceId()).thenReturn("foo_id");
         assertThat(builder.build(config, "test_schema",
                 Collections.singletonMap("name", new MockedDataSource()), 
Collections.emptyList(), instanceContext), 
instanceOf(DatabaseDiscoveryRule.class));
-        
ScheduleContextFactory.getInstance().getScheduleStrategy().remove("foo_id");
     }
 }
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/SnowflakeKeyGenerateAlgorithmTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/SnowflakeKeyGenerateAlgorithmTest.java
index 638bf09fc55..f32b0f72b52 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/SnowflakeKeyGenerateAlgorithmTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/SnowflakeKeyGenerateAlgorithmTest.java
@@ -21,6 +21,7 @@ import lombok.SneakyThrows;
 import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
 import org.apache.shardingsphere.infra.config.algorithm.InstanceAwareAlgorithm;
 import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
+import org.apache.shardingsphere.infra.schedule.ScheduleContext;
 import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
 import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
 import org.apache.shardingsphere.infra.instance.InstanceContext;
@@ -207,7 +208,7 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
     public void assertSetWorkerIdFailureWhenNegative() {
         SnowflakeKeyGenerateAlgorithm algorithm = 
(SnowflakeKeyGenerateAlgorithm) KeyGenerateAlgorithmFactory.newInstance(new 
AlgorithmConfiguration("SNOWFLAKE", new Properties()));
         InstanceContext instanceContext = new InstanceContext(new 
ComputeNodeInstance(mock(InstanceMetaData.class)), new 
WorkerIdGeneratorFixture(-1L),
-                new ModeConfiguration("Standalone", null, false), 
mock(LockContext.class), new EventBusContext());
+                new ModeConfiguration("Standalone", null, false), 
mock(LockContext.class), new EventBusContext(), mock(ScheduleContext.class));
         algorithm.setInstanceContext(instanceContext);
         algorithm.generateKey();
     }
@@ -223,7 +224,7 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
     public void assertSetWorkerIdFailureWhenOutOfRange() {
         SnowflakeKeyGenerateAlgorithm algorithm = 
(SnowflakeKeyGenerateAlgorithm) KeyGenerateAlgorithmFactory.newInstance(new 
AlgorithmConfiguration("SNOWFLAKE", new Properties()));
         InstanceContext instanceContext = new InstanceContext(new 
ComputeNodeInstance(mock(InstanceMetaData.class)), new 
WorkerIdGeneratorFixture(Long.MIN_VALUE),
-                new ModeConfiguration("Standalone", null, false), 
mock(LockContext.class), new EventBusContext());
+                new ModeConfiguration("Standalone", null, false), 
mock(LockContext.class), new EventBusContext(), mock(ScheduleContext.class));
         algorithm.setInstanceContext(instanceContext);
         algorithm.generateKey();
     }
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-plugin/shardingsphere-sharding-cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithmTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-plugin/shardingsphere-sharding-cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithmTest.java
index e53765b42dc..27f40865fdd 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-plugin/shardingsphere-sharding-cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithmTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-plugin/shardingsphere-sharding-cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithmTest.java
@@ -28,6 +28,7 @@ import 
org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
 import org.apache.shardingsphere.infra.instance.InstanceContext;
 import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData;
 import org.apache.shardingsphere.infra.lock.LockContext;
+import org.apache.shardingsphere.infra.schedule.ScheduleContext;
 import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
 import 
org.apache.shardingsphere.sharding.cosid.algorithm.keygen.fixture.WorkerIdGeneratorFixture;
 import org.apache.shardingsphere.sharding.factory.KeyGenerateAlgorithmFactory;
@@ -60,7 +61,7 @@ public final class CosIdSnowflakeKeyGenerateAlgorithmTest {
         CosIdSnowflakeKeyGenerateAlgorithm algorithm = 
(CosIdSnowflakeKeyGenerateAlgorithm) KeyGenerateAlgorithmFactory.newInstance(
                 new AlgorithmConfiguration("COSID_SNOWFLAKE", new 
Properties()));
         algorithm.setInstanceContext(new InstanceContext(new 
ComputeNodeInstance(mock(InstanceMetaData.class)), new 
WorkerIdGeneratorFixture(FIXTURE_WORKER_ID),
-                new ModeConfiguration("Standalone", null, false), 
mock(LockContext.class), eventBusContext));
+                new ModeConfiguration("Standalone", null, false), 
mock(LockContext.class), eventBusContext, mock(ScheduleContext.class)));
         long firstActualKey = (Long) algorithm.generateKey();
         long secondActualKey = (Long) algorithm.generateKey();
         SnowflakeIdState firstActualState = 
snowflakeIdStateParser.parse(firstActualKey);
@@ -76,7 +77,7 @@ public final class CosIdSnowflakeKeyGenerateAlgorithmTest {
     public void assertGenerateKeyModUniformity() {
         CosIdSnowflakeKeyGenerateAlgorithm algorithm = 
(CosIdSnowflakeKeyGenerateAlgorithm) 
KeyGenerateAlgorithmFactory.newInstance(new 
AlgorithmConfiguration("COSID_SNOWFLAKE", new Properties()));
         algorithm.setInstanceContext(new InstanceContext(new 
ComputeNodeInstance(mock(InstanceMetaData.class)), new 
WorkerIdGeneratorFixture(FIXTURE_WORKER_ID),
-                new ModeConfiguration("Standalone", null, false), 
mock(LockContext.class), eventBusContext));
+                new ModeConfiguration("Standalone", null, false), 
mock(LockContext.class), eventBusContext, mock(ScheduleContext.class)));
         int divisor = 4;
         int total = 99999;
         int avg = total / divisor;
@@ -120,7 +121,8 @@ public final class CosIdSnowflakeKeyGenerateAlgorithmTest {
         CosIdSnowflakeKeyGenerateAlgorithm algorithm = 
(CosIdSnowflakeKeyGenerateAlgorithm) KeyGenerateAlgorithmFactory.newInstance(
                 new AlgorithmConfiguration("COSID_SNOWFLAKE", props));
         algorithm.setInstanceContext(new InstanceContext(new 
ComputeNodeInstance(mock(InstanceMetaData.class)),
-                new WorkerIdGeneratorFixture(FIXTURE_WORKER_ID), new 
ModeConfiguration("Standalone", null, false), mock(LockContext.class), 
eventBusContext));
+                new WorkerIdGeneratorFixture(FIXTURE_WORKER_ID), new 
ModeConfiguration("Standalone", null, false),
+                mock(LockContext.class), eventBusContext, 
mock(ScheduleContext.class)));
         Comparable<?> actualKey = algorithm.generateKey();
         assertThat(actualKey, instanceOf(String.class));
         String actualStringKey = (String) actualKey;
@@ -141,7 +143,7 @@ public final class CosIdSnowflakeKeyGenerateAlgorithmTest {
         CosIdSnowflakeKeyGenerateAlgorithm algorithm = 
(CosIdSnowflakeKeyGenerateAlgorithm) KeyGenerateAlgorithmFactory.newInstance(
                 new AlgorithmConfiguration("COSID_SNOWFLAKE", new 
Properties()));
         algorithm.setInstanceContext(new InstanceContext(new 
ComputeNodeInstance(mock(InstanceMetaData.class)), new 
WorkerIdGeneratorFixture(-1),
-                new ModeConfiguration("Standalone", null, false), 
mock(LockContext.class), eventBusContext));
+                new ModeConfiguration("Standalone", null, false), 
mock(LockContext.class), eventBusContext, mock(ScheduleContext.class)));
         algorithm.generateKey();
     }
     
@@ -150,7 +152,7 @@ public final class CosIdSnowflakeKeyGenerateAlgorithmTest {
         CosIdSnowflakeKeyGenerateAlgorithm algorithm = 
(CosIdSnowflakeKeyGenerateAlgorithm) KeyGenerateAlgorithmFactory.newInstance(
                 new AlgorithmConfiguration("COSID_SNOWFLAKE", new 
Properties()));
         algorithm.setInstanceContext(new InstanceContext(new 
ComputeNodeInstance(mock(InstanceMetaData.class)), new 
WorkerIdGeneratorFixture(1024),
-                new ModeConfiguration("Standalone", null, false), 
mock(LockContext.class), eventBusContext));
+                new ModeConfiguration("Standalone", null, false), 
mock(LockContext.class), eventBusContext, mock(ScheduleContext.class)));
         algorithm.generateKey();
     }
 }
diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java
index e5241e2a7fa..0931e50f77f 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.infra.instance;
 import lombok.AccessLevel;
 import lombok.Getter;
 import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
+import org.apache.shardingsphere.infra.schedule.ScheduleContext;
 import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
 import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData;
 import org.apache.shardingsphere.infra.instance.metadata.InstanceType;
@@ -50,15 +51,19 @@ public final class InstanceContext {
     
     private final EventBusContext eventBusContext;
     
+    private final ScheduleContext scheduleContext;
+    
     private final Collection<ComputeNodeInstance> allClusterInstances = new 
LinkedList<>();
     
     public InstanceContext(final ComputeNodeInstance instance, final 
WorkerIdGenerator workerIdGenerator,
-                           final ModeConfiguration modeConfiguration, final 
LockContext lockContext, final EventBusContext eventBusContext) {
+                           final ModeConfiguration modeConfiguration, final 
LockContext lockContext,
+                           final EventBusContext eventBusContext, final 
ScheduleContext scheduleContext) {
         this.instance = instance;
         this.workerIdGenerator = workerIdGenerator;
         this.modeConfiguration = modeConfiguration;
         this.lockContext = lockContext;
         this.eventBusContext = eventBusContext;
+        this.scheduleContext = scheduleContext;
     }
     
     /**
diff --git 
a/shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/model/CronJob.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/schedule/CronJob.java
similarity index 95%
rename from 
shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/model/CronJob.java
rename to 
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/schedule/CronJob.java
index 9c56aa60524..04c0089687f 100644
--- 
a/shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/model/CronJob.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/schedule/CronJob.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.schedule.core.model;
+package org.apache.shardingsphere.infra.schedule;
 
 import lombok.Getter;
 import lombok.RequiredArgsConstructor;
diff --git 
a/shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/strategy/ScheduleStrategy.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/schedule/ScheduleContext.java
similarity index 87%
rename from 
shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/strategy/ScheduleStrategy.java
rename to 
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/schedule/ScheduleContext.java
index 495a9a401ff..4f6e96cb2a8 100644
--- 
a/shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/strategy/ScheduleStrategy.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/schedule/ScheduleContext.java
@@ -15,14 +15,12 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.schedule.core.strategy;
-
-import org.apache.shardingsphere.schedule.core.model.CronJob;
+package org.apache.shardingsphere.infra.schedule;
 
 /**
  * Schedule Strategy.
  */
-public interface ScheduleStrategy {
+public interface ScheduleContext {
     
     /**
      * Start schedule.
diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/instance/InstanceContextTest.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/instance/InstanceContextTest.java
index 566f0aa8580..5b0e5c3f6b5 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/instance/InstanceContextTest.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/instance/InstanceContextTest.java
@@ -18,6 +18,7 @@
 package org.apache.shardingsphere.infra.instance;
 
 import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
+import org.apache.shardingsphere.infra.schedule.ScheduleContext;
 import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
 import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData;
 import 
org.apache.shardingsphere.infra.instance.fixture.WorkerIdGeneratorFixture;
@@ -53,7 +54,8 @@ public final class InstanceContextTest {
     public void assertUpdateInstanceStatus() {
         InstanceMetaData instanceMetaData = mock(InstanceMetaData.class);
         when(instanceMetaData.getId()).thenReturn("foo_instance_id");
-        InstanceContext context = new InstanceContext(new 
ComputeNodeInstance(instanceMetaData), new 
WorkerIdGeneratorFixture(Long.MIN_VALUE), modeConfig, lockContext, 
eventBusContext);
+        InstanceContext context = new InstanceContext(new 
ComputeNodeInstance(instanceMetaData), new 
WorkerIdGeneratorFixture(Long.MIN_VALUE),
+                modeConfig, lockContext, eventBusContext, 
mock(ScheduleContext.class));
         StateType actual = context.getInstance().getState().getCurrentState();
         assertThat(actual, is(StateType.OK));
         context.updateInstanceStatus(instanceMetaData.getId(), 
Collections.singleton(StateType.CIRCUIT_BREAK.name()));
@@ -68,13 +70,15 @@ public final class InstanceContextTest {
     public void assertGetWorkerId() {
         ComputeNodeInstance computeNodeInstance = 
mock(ComputeNodeInstance.class);
         when(computeNodeInstance.getWorkerId()).thenReturn(0L);
-        InstanceContext context = new InstanceContext(computeNodeInstance, new 
WorkerIdGeneratorFixture(Long.MIN_VALUE), modeConfig, lockContext, 
eventBusContext);
+        InstanceContext context = new InstanceContext(computeNodeInstance, new 
WorkerIdGeneratorFixture(Long.MIN_VALUE), modeConfig,
+                lockContext, eventBusContext, mock(ScheduleContext.class));
         assertThat(context.getWorkerId(), is(0L));
     }
     
     @Test
     public void assertGenerateWorkerId() {
-        InstanceContext context = new InstanceContext(new 
ComputeNodeInstance(mock(InstanceMetaData.class)), new 
WorkerIdGeneratorFixture(Long.MIN_VALUE), modeConfig, lockContext, 
eventBusContext);
+        InstanceContext context = new InstanceContext(new 
ComputeNodeInstance(mock(InstanceMetaData.class)), new 
WorkerIdGeneratorFixture(Long.MIN_VALUE), modeConfig,
+                lockContext, eventBusContext, mock(ScheduleContext.class));
         long actual = context.generateWorkerId(new Properties());
         assertThat(actual, is(Long.MIN_VALUE));
     }
@@ -83,7 +87,8 @@ public final class InstanceContextTest {
     public void assertUpdateLabel() {
         InstanceMetaData instanceMetaData = mock(InstanceMetaData.class);
         when(instanceMetaData.getId()).thenReturn("foo_instance_id");
-        InstanceContext context = new InstanceContext(new 
ComputeNodeInstance(instanceMetaData), new 
WorkerIdGeneratorFixture(Long.MIN_VALUE), modeConfig, lockContext, 
eventBusContext);
+        InstanceContext context = new InstanceContext(new 
ComputeNodeInstance(instanceMetaData), new 
WorkerIdGeneratorFixture(Long.MIN_VALUE), modeConfig,
+                lockContext, eventBusContext, mock(ScheduleContext.class));
         Set<String> expected = new LinkedHashSet<>(Arrays.asList("label_1", 
"label_2"));
         context.updateLabel("foo_instance_id", expected);
         Collection<String> actual = context.getInstance().getLabels();
@@ -93,31 +98,35 @@ public final class InstanceContextTest {
     @Test
     public void assertGetInstance() {
         ComputeNodeInstance expected = new 
ComputeNodeInstance(mock(InstanceMetaData.class));
-        InstanceContext context = new InstanceContext(expected, new 
WorkerIdGeneratorFixture(Long.MIN_VALUE), modeConfig, lockContext, 
eventBusContext);
+        InstanceContext context = new InstanceContext(expected, new 
WorkerIdGeneratorFixture(Long.MIN_VALUE), modeConfig,
+                lockContext, eventBusContext, mock(ScheduleContext.class));
         ComputeNodeInstance actual = context.getInstance();
         assertThat(actual, is(expected));
     }
     
     @Test
     public void assertGetState() {
-        InstanceContext context = new InstanceContext(new 
ComputeNodeInstance(mock(InstanceMetaData.class)), new 
WorkerIdGeneratorFixture(Long.MIN_VALUE), modeConfig, lockContext, 
eventBusContext);
+        InstanceContext context = new InstanceContext(new 
ComputeNodeInstance(mock(InstanceMetaData.class)), new 
WorkerIdGeneratorFixture(Long.MIN_VALUE), modeConfig,
+                lockContext, eventBusContext, mock(ScheduleContext.class));
         StateContext actual = context.getInstance().getState();
         assertNotNull(actual);
     }
     
     @Test
     public void assertGetModeConfiguration() {
-        InstanceContext context = new InstanceContext(new 
ComputeNodeInstance(mock(InstanceMetaData.class)), new 
WorkerIdGeneratorFixture(Long.MIN_VALUE), modeConfig, lockContext, 
eventBusContext);
+        InstanceContext context = new InstanceContext(new 
ComputeNodeInstance(mock(InstanceMetaData.class)), new 
WorkerIdGeneratorFixture(Long.MIN_VALUE), modeConfig,
+                lockContext, eventBusContext, mock(ScheduleContext.class));
         ModeConfiguration actual = context.getModeConfiguration();
         assertThat(actual, is(modeConfig));
     }
     
     @Test
     public void assertIsCluster() {
-        InstanceContext context = new InstanceContext(new 
ComputeNodeInstance(mock(InstanceMetaData.class)), new 
WorkerIdGeneratorFixture(Long.MIN_VALUE), modeConfig, lockContext, 
eventBusContext);
+        InstanceContext context = new InstanceContext(new 
ComputeNodeInstance(mock(InstanceMetaData.class)), new 
WorkerIdGeneratorFixture(Long.MIN_VALUE), modeConfig,
+                lockContext, eventBusContext, mock(ScheduleContext.class));
         assertFalse(context.isCluster());
         InstanceContext clusterContext = new InstanceContext(new 
ComputeNodeInstance(mock(InstanceMetaData.class)), new 
WorkerIdGeneratorFixture(Long.MIN_VALUE),
-                new ModeConfiguration("Cluster", null, false), lockContext, 
eventBusContext);
+                new ModeConfiguration("Cluster", null, false), lockContext, 
eventBusContext, mock(ScheduleContext.class));
         assertTrue(clusterContext.isCluster());
     }
 }
diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java
index 9fe5d35fb78..0283ba64c30 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.infra.rule.builder.global;
 import lombok.SneakyThrows;
 import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
 import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import org.apache.shardingsphere.infra.schedule.ScheduleContext;
 import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
 import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
 import org.apache.shardingsphere.infra.instance.InstanceContext;
@@ -62,7 +63,7 @@ public final class GlobalRulesBuilderTest {
     private InstanceContext buildInstanceContext() {
         ComputeNodeInstance computeNodeInstance = new ComputeNodeInstance(new 
JDBCInstanceMetaData(UUID.randomUUID().toString()));
         ModeConfiguration modeConfiguration = new 
ModeConfiguration("Standalone", null, false);
-        return new InstanceContext(computeNodeInstance, 
createWorkerIdGenerator(), modeConfiguration, mock(LockContext.class), new 
EventBusContext());
+        return new InstanceContext(computeNodeInstance, 
createWorkerIdGenerator(), modeConfiguration, mock(LockContext.class), new 
EventBusContext(), mock(ScheduleContext.class));
     }
     
     @SneakyThrows
diff --git 
a/shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/ScheduleContextFactory.java
 
b/shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/ScheduleContextFactory.java
index 1855f19cfb6..04d9e103ee2 100644
--- 
a/shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/ScheduleContextFactory.java
+++ 
b/shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/ScheduleContextFactory.java
@@ -21,12 +21,9 @@ import lombok.AccessLevel;
 import lombok.Getter;
 import lombok.NoArgsConstructor;
 import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
-import org.apache.shardingsphere.schedule.core.strategy.ScheduleStrategy;
-import 
org.apache.shardingsphere.schedule.core.strategy.type.ClusterScheduleStrategy;
-import 
org.apache.shardingsphere.schedule.core.strategy.type.StandaloneScheduleStrategy;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
+import org.apache.shardingsphere.infra.schedule.ScheduleContext;
+import org.apache.shardingsphere.schedule.core.context.ClusterScheduleContext;
+import 
org.apache.shardingsphere.schedule.core.context.StandaloneScheduleContext;
 
 /**
  * Schedule context factory.
@@ -35,38 +32,15 @@ import java.util.concurrent.ConcurrentHashMap;
 @Getter
 public final class ScheduleContextFactory {
     
-    private static final ScheduleContextFactory INSTANCE = new 
ScheduleContextFactory();
-    
-    private final Map<String, ScheduleStrategy> scheduleStrategy = new 
ConcurrentHashMap<>();
-    
     /**
-     * Get instance.
+     * Create new instance of schedule context.
      *
-     * @return singleton instance
-     */
-    public static ScheduleContextFactory getInstance() {
-        return INSTANCE;
-    }
-    
-    /**
-     * Init schedule context.
-     * 
-     * @param instanceId instance id
      * @param modeConfig mode configuration
+     * @return Schedule context instance
      */
-    public void init(final String instanceId, final ModeConfiguration 
modeConfig) {
-        scheduleStrategy.put(instanceId, 
"Cluster".equalsIgnoreCase(modeConfig.getType()) && 
"ZooKeeper".equalsIgnoreCase(modeConfig.getRepository().getType())
-                ? new 
ClusterScheduleStrategy(modeConfig.getRepository().getProps().getProperty("server-lists"),
 modeConfig.getRepository().getProps().getProperty("namespace"))
-                : new StandaloneScheduleStrategy());
-    }
-    
-    /**
-     * Get schedule strategy.
-     * 
-     * @param instanceId instance id
-     * @return get schedule strategy
-     */
-    public ScheduleStrategy get(final String instanceId) {
-        return scheduleStrategy.get(instanceId);
+    public static ScheduleContext newInstance(final ModeConfiguration 
modeConfig) {
+        return "Cluster".equalsIgnoreCase(modeConfig.getType()) && 
"ZooKeeper".equalsIgnoreCase(modeConfig.getRepository().getType())
+                ? new 
ClusterScheduleContext(modeConfig.getRepository().getProps().getProperty("server-lists"),
 modeConfig.getRepository().getProps().getProperty("namespace"))
+                : new StandaloneScheduleContext();
     }
 }
diff --git 
a/shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/strategy/type/ClusterScheduleStrategy.java
 
b/shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/context/ClusterScheduleContext.java
similarity index 93%
rename from 
shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/strategy/type/ClusterScheduleStrategy.java
rename to 
shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/context/ClusterScheduleContext.java
index 16b06d33f18..53d7052220c 100644
--- 
a/shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/strategy/type/ClusterScheduleStrategy.java
+++ 
b/shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/context/ClusterScheduleContext.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.schedule.core.strategy.type;
+package org.apache.shardingsphere.schedule.core.context;
 
 import com.google.common.base.Preconditions;
 import lombok.RequiredArgsConstructor;
@@ -30,9 +30,9 @@ import 
org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
 import 
org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperConfiguration;
 import 
org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter;
 import org.apache.shardingsphere.elasticjob.simple.job.SimpleJob;
-import org.apache.shardingsphere.schedule.core.model.CronJob;
+import org.apache.shardingsphere.infra.schedule.CronJob;
+import org.apache.shardingsphere.infra.schedule.ScheduleContext;
 import org.apache.shardingsphere.schedule.core.model.JobParameter;
-import org.apache.shardingsphere.schedule.core.strategy.ScheduleStrategy;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -40,11 +40,11 @@ import java.util.Optional;
 import java.util.function.Consumer;
 
 /**
- * Cluster schedule strategy.
+ * Cluster schedule context.
  */
 @RequiredArgsConstructor
 @Slf4j
-public final class ClusterScheduleStrategy implements ScheduleStrategy {
+public final class ClusterScheduleContext implements ScheduleContext {
     
     private static final Map<String, ScheduleJobBootstrap> 
SCHEDULE_JOB_BOOTSTRAP_MAP = new HashMap<>();
     
diff --git 
a/shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/strategy/type/StandaloneScheduleStrategy.java
 
b/shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/context/StandaloneScheduleContext.java
similarity index 76%
rename from 
shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/strategy/type/StandaloneScheduleStrategy.java
rename to 
shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/context/StandaloneScheduleContext.java
index d54f8bd3d38..ca0a213691c 100644
--- 
a/shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/strategy/type/StandaloneScheduleStrategy.java
+++ 
b/shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/context/StandaloneScheduleContext.java
@@ -15,15 +15,15 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.schedule.core.strategy.type;
+package org.apache.shardingsphere.schedule.core.context;
 
-import org.apache.shardingsphere.schedule.core.model.CronJob;
-import org.apache.shardingsphere.schedule.core.strategy.ScheduleStrategy;
+import org.apache.shardingsphere.infra.schedule.CronJob;
+import org.apache.shardingsphere.infra.schedule.ScheduleContext;
 
 /**
- * Standalone schedule strategy.
+ * Standalone schedule context.
  */
-public final class StandaloneScheduleStrategy implements ScheduleStrategy {
+public final class StandaloneScheduleContext implements ScheduleContext {
     
     @Override
     public void startSchedule(final CronJob job) {
diff --git 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
index 6de5b24631a..1bf6c2d4921 100644
--- 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
+++ 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
@@ -44,7 +44,6 @@ public final class ClusterContextManagerBuilder implements 
ContextManagerBuilder
     
     @Override
     public ContextManager build(final ContextManagerBuilderParameter 
parameter) throws SQLException {
-        
ScheduleContextFactory.getInstance().init(parameter.getInstanceMetaData().getId(),
 parameter.getModeConfiguration());
         ClusterPersistRepository repository = 
ClusterPersistRepositoryFactory.getInstance((ClusterPersistRepositoryConfiguration)
 parameter.getModeConfiguration().getRepository());
         MetaDataPersistService persistService = new 
MetaDataPersistService(repository);
         persistConfigurations(persistService, parameter);
@@ -66,7 +65,8 @@ public final class ClusterContextManagerBuilder implements 
ContextManagerBuilder
     
     private InstanceContext buildInstanceContext(final RegistryCenter 
registryCenter, final ContextManagerBuilderParameter parameter) {
         return new InstanceContext(new 
ComputeNodeInstance(parameter.getInstanceMetaData()), new 
ClusterWorkerIdGenerator(registryCenter, parameter.getInstanceMetaData()),
-                parameter.getModeConfiguration(), new 
ShardingSphereLockContext(registryCenter.getLockPersistService()), 
registryCenter.getEventBusContext());
+                parameter.getModeConfiguration(), new 
ShardingSphereLockContext(registryCenter.getLockPersistService()),
+                registryCenter.getEventBusContext(), 
ScheduleContextFactory.newInstance(parameter.getModeConfiguration()));
     }
     
     private void persistMetaData(final MetaDataContexts metaDataContexts) {
diff --git 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java
 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java
index dbac328b1ee..698909d1ab5 100644
--- 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java
+++ 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java
@@ -43,7 +43,6 @@ public final class StandaloneContextManagerBuilder implements 
ContextManagerBuil
     
     @Override
     public ContextManager build(final ContextManagerBuilderParameter 
parameter) throws SQLException {
-        
ScheduleContextFactory.getInstance().init(parameter.getInstanceMetaData().getId(),
 parameter.getModeConfiguration());
         StandalonePersistRepository repository = 
StandalonePersistRepositoryFactory.getInstance(parameter.getModeConfiguration().getRepository());
         MetaDataPersistService persistService = new 
MetaDataPersistService(repository);
         persistConfigurations(persistService, parameter);
@@ -61,7 +60,8 @@ public final class StandaloneContextManagerBuilder implements 
ContextManagerBuil
     
     private InstanceContext buildInstanceContext(final 
ContextManagerBuilderParameter parameter) {
         return new InstanceContext(new 
ComputeNodeInstance(parameter.getInstanceMetaData()),
-                new StandaloneWorkerIdGenerator(), 
parameter.getModeConfiguration(), new ShardingSphereLockContext(new 
StandaloneLockPersistService()), new EventBusContext());
+                new StandaloneWorkerIdGenerator(), 
parameter.getModeConfiguration(), new ShardingSphereLockContext(new 
StandaloneLockPersistService()),
+                new EventBusContext(), 
ScheduleContextFactory.newInstance(parameter.getModeConfiguration()));
     }
     
     @Override

Reply via email to