You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/06/26 03:51:21 UTC
[shardingsphere] branch master updated: Refactor code format ModeScheduleContextFactory and ModeScheduleContext (#18601)
This is an automated email from the ASF dual-hosted git repository.
zhonghongsheng 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 c6331271507 Refactor code format ModeScheduleContextFactory and ModeScheduleContext (#18601)
c6331271507 is described below
commit c6331271507060fd616fa17c88d77fbf295733f1
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sun Jun 26 11:51:15 2022 +0800
Refactor code format ModeScheduleContextFactory and ModeScheduleContext (#18601)
---
.../schedule/core/api/ModeScheduleContext.java | 23 ++++++++------------
.../core/api/ModeScheduleContextFactory.java | 25 ++++++++++------------
2 files changed, 20 insertions(+), 28 deletions(-)
diff --git a/shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/api/ModeScheduleContext.java b/shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/api/ModeScheduleContext.java
index 21ad1c730fe..d4683618ef9 100644
--- a/shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/api/ModeScheduleContext.java
+++ b/shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/api/ModeScheduleContext.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.schedule.core.api;
+import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.concurrent.ConcurrentException;
@@ -38,10 +39,11 @@ import java.util.function.Consumer;
/**
* Mode schedule context, used for proxy and jdbc.
*/
+@RequiredArgsConstructor
@Slf4j
public final class ModeScheduleContext {
- private static final Map<String, ScheduleJobBootstrap> SCHEDULE_JOB_BOOTSTRAP_MAP = new HashMap<>(16, 1);
+ private static final Map<String, ScheduleJobBootstrap> SCHEDULE_JOB_BOOTSTRAP_MAP = new HashMap<>();
private final ModeConfiguration modeConfig;
@@ -53,10 +55,6 @@ public final class ModeScheduleContext {
}
};
- public ModeScheduleContext(final ModeConfiguration modeConfig) {
- this.modeConfig = modeConfig;
- }
-
private CoordinatorRegistryCenter initRegistryCenter(final ModeConfiguration modeConfig) {
if (null == modeConfig) {
return null;
@@ -92,11 +90,6 @@ public final class ModeScheduleContext {
return null;
}
- @SneakyThrows(ConcurrentException.class)
- private CoordinatorRegistryCenter getRegistryCenter() {
- return registryCenterLazyInitializer.get();
- }
-
/**
* Start cron job.
*
@@ -118,14 +111,16 @@ public final class ModeScheduleContext {
SCHEDULE_JOB_BOOTSTRAP_MAP.get(job.getJobName()).schedule();
}
+ @SneakyThrows(ConcurrentException.class)
+ private CoordinatorRegistryCenter getRegistryCenter() {
+ return registryCenterLazyInitializer.get();
+ }
+
+ @RequiredArgsConstructor
private static final class ConsumerSimpleJob implements SimpleJob {
private final Consumer<JobParameter> job;
- ConsumerSimpleJob(final Consumer<JobParameter> job) {
- this.job = job;
- }
-
@Override
public void execute(final ShardingContext shardingContext) {
job.accept(new JobParameter());
diff --git a/shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/api/ModeScheduleContextFactory.java b/shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/api/ModeScheduleContextFactory.java
index 1790d7aced7..c43e59453ec 100644
--- a/shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/api/ModeScheduleContextFactory.java
+++ b/shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/api/ModeScheduleContextFactory.java
@@ -37,6 +37,15 @@ public final class ModeScheduleContextFactory {
private final Map<String, ModeScheduleContext> modeScheduleContexts = new ConcurrentHashMap<>();
+ /**
+ * Get instance.
+ *
+ * @return singleton instance
+ */
+ public static ModeScheduleContextFactory getInstance() {
+ return INSTANCE;
+ }
+
/**
* Init mode schedule context.
*
@@ -48,24 +57,12 @@ public final class ModeScheduleContextFactory {
}
/**
- * Get mode schedule context of current instance.
+ * Get mode schedule context.
*
* @param instanceId instance id
- * @return mode schedule context
+ * @return got mode schedule context
*/
public Optional<ModeScheduleContext> get(final String instanceId) {
- if (modeScheduleContexts.values().isEmpty()) {
- return Optional.empty();
- }
return Optional.ofNullable(modeScheduleContexts.get(instanceId));
}
-
- /**
- * Get instance.
- *
- * @return singleton instance
- */
- public static ModeScheduleContextFactory getInstance() {
- return INSTANCE;
- }
}