From 8a196e0616b53897695952f79ec6b684eb810a56 Mon Sep 17 00:00:00 2001 From: zhangliang Date: Thu, 9 Nov 2023 16:26:49 +0800 Subject: [PATCH] Remove AbstractJobType --- .../common/job/type/AbstractJobType.java | 38 ------------------- .../common/job/type/JobCodeRegistry.java | 5 ++- .../common/job/type/FixtureJobType.java | 12 ++++-- .../pipeline/cdc/api/job/type/CDCJobType.java | 14 ++++--- .../ConsistencyCheckJobType.java | 14 +++++-- .../scenario/migration/MigrationJobType.java | 14 +++++-- 6 files changed, 41 insertions(+), 56 deletions(-) delete mode 100644 kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/common/job/type/AbstractJobType.java diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/common/job/type/AbstractJobType.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/common/job/type/AbstractJobType.java deleted file mode 100644 index 8a6610bb34a09..0000000000000 --- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/common/job/type/AbstractJobType.java +++ /dev/null @@ -1,38 +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.data.pipeline.common.job.type; - -import com.google.common.base.Preconditions; -import lombok.Getter; - -/** - * Abstract job type. - */ -@Getter -public abstract class AbstractJobType implements JobType { - - private final String type; - - private final String code; - - protected AbstractJobType(final String type, final String code) { - this.type = type; - Preconditions.checkArgument(2 == code.length(), "code length is not 2"); - this.code = code; - } -} diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/common/job/type/JobCodeRegistry.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/common/job/type/JobCodeRegistry.java index 6d198e161443d..a9e849078286f 100644 --- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/common/job/type/JobCodeRegistry.java +++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/common/job/type/JobCodeRegistry.java @@ -36,7 +36,10 @@ public final class JobCodeRegistry { private static final Map JOB_CODE_AND_TYPE_MAP = new HashMap<>(); static { - ShardingSphereServiceLoader.getServiceInstances(JobType.class).forEach(each -> JOB_CODE_AND_TYPE_MAP.put(each.getCode(), each.getType())); + for (JobType each : ShardingSphereServiceLoader.getServiceInstances(JobType.class)) { + Preconditions.checkArgument(2 == each.getCode().length(), "Job type code length is not 2."); + JOB_CODE_AND_TYPE_MAP.put(each.getCode(), each.getType()); + } } /** diff --git a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/common/job/type/FixtureJobType.java b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/common/job/type/FixtureJobType.java index 1e905f0bfc28a..a1976f940ab06 100644 --- a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/common/job/type/FixtureJobType.java +++ b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/common/job/type/FixtureJobType.java @@ -20,11 +20,15 @@ /** * Fixture job type. */ -public final class FixtureJobType extends AbstractJobType { +public final class FixtureJobType implements JobType { - public static final String TYPE_CODE = "00"; + @Override + public String getCode() { + return "00"; + } - public FixtureJobType() { - super("FIXTURE", TYPE_CODE); + @Override + public String getType() { + return "FIXTURE"; } } diff --git a/kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/api/job/type/CDCJobType.java b/kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/api/job/type/CDCJobType.java index b545d63180f94..95cfcbdb538fb 100644 --- a/kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/api/job/type/CDCJobType.java +++ b/kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/api/job/type/CDCJobType.java @@ -17,16 +17,20 @@ package org.apache.shardingsphere.data.pipeline.cdc.api.job.type; -import org.apache.shardingsphere.data.pipeline.common.job.type.AbstractJobType; +import org.apache.shardingsphere.data.pipeline.common.job.type.JobType; /** * CDC job type. */ -public final class CDCJobType extends AbstractJobType { +public final class CDCJobType implements JobType { - public static final String TYPE_CODE = "03"; + @Override + public String getCode() { + return "03"; + } - public CDCJobType() { - super("STREAMING", TYPE_CODE); + @Override + public String getType() { + return "STREAMING"; } } diff --git a/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/ConsistencyCheckJobType.java b/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/ConsistencyCheckJobType.java index d42ee9a6ef16c..ce87dac4dfa07 100644 --- a/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/ConsistencyCheckJobType.java +++ b/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/ConsistencyCheckJobType.java @@ -17,16 +17,22 @@ package org.apache.shardingsphere.data.pipeline.scenario.consistencycheck; -import org.apache.shardingsphere.data.pipeline.common.job.type.AbstractJobType; +import org.apache.shardingsphere.data.pipeline.common.job.type.JobType; /** * Consistency check job type. */ -public final class ConsistencyCheckJobType extends AbstractJobType { +public final class ConsistencyCheckJobType implements JobType { public static final String TYPE_CODE = "02"; - public ConsistencyCheckJobType() { - super("CONSISTENCY_CHECK", TYPE_CODE); + @Override + public String getCode() { + return TYPE_CODE; + } + + @Override + public String getType() { + return "CONSISTENCY_CHECK"; } } diff --git a/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationJobType.java b/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationJobType.java index f0c979e9f51e1..92d305bca0f36 100644 --- a/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationJobType.java +++ b/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationJobType.java @@ -17,16 +17,22 @@ package org.apache.shardingsphere.data.pipeline.scenario.migration; -import org.apache.shardingsphere.data.pipeline.common.job.type.AbstractJobType; +import org.apache.shardingsphere.data.pipeline.common.job.type.JobType; /** * Migration job type. */ -public final class MigrationJobType extends AbstractJobType { +public final class MigrationJobType implements JobType { public static final String TYPE_CODE = "01"; - public MigrationJobType() { - super("MIGRATION", TYPE_CODE); + @Override + public String getCode() { + return TYPE_CODE; + } + + @Override + public String getType() { + return "MIGRATION"; } }