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 2020/10/19 13:25:53 UTC

[shardingsphere-elasticjob] branch master updated: Remove useless constructor of JobScheduler (#1611)

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-elasticjob.git


The following commit(s) were added to refs/heads/master by this push:
     new 8eabb3d  Remove useless constructor of JobScheduler (#1611)
8eabb3d is described below

commit 8eabb3d33c707bf235ec0391fa4e0dfc31d6f121
Author: Liang Zhang <te...@163.com>
AuthorDate: Mon Oct 19 21:25:41 2020 +0800

    Remove useless constructor of JobScheduler (#1611)
    
    * Remove useless constructor of JobScheduler
    
    * refactor JobScheduler
---
 .../lite/internal/schedule/JobScheduler.java       | 37 ++++++++++------------
 1 file changed, 17 insertions(+), 20 deletions(-)

diff --git a/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/JobScheduler.java b/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/JobScheduler.java
index 9b5b3af..bbe16e4 100644
--- a/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/JobScheduler.java
+++ b/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/JobScheduler.java
@@ -72,41 +72,38 @@ public final class JobScheduler {
     public JobScheduler(final CoordinatorRegistryCenter regCenter, final ElasticJob elasticJob, final JobConfiguration jobConfig) {
         this.regCenter = regCenter;
         elasticJobType = null;
-        final Collection<ElasticJobListener> elasticJobListeners = jobConfig.getJobListenerTypes().stream()
-                .map(type -> ElasticJobListenerFactory.createListener(type)
-                        .orElseThrow(() -> new IllegalArgumentException(String.format("Can not find job listener type '%s'.", type))))
-                .collect(Collectors.toList());
-        setUpFacade = new SetUpFacade(regCenter, jobConfig.getJobName(), elasticJobListeners);
+        Collection<ElasticJobListener> jobListeners = getElasticJobListeners(jobConfig);
+        setUpFacade = new SetUpFacade(regCenter, jobConfig.getJobName(), jobListeners);
         schedulerFacade = new SchedulerFacade(regCenter, jobConfig.getJobName());
-        jobFacade = new LiteJobFacade(regCenter, jobConfig.getJobName(), elasticJobListeners, findTracingConfiguration(jobConfig).orElse(null));
+        jobFacade = new LiteJobFacade(regCenter, jobConfig.getJobName(), jobListeners, findTracingConfiguration(jobConfig).orElse(null));
         jobExecutor = null == elasticJob ? new ElasticJobExecutor(elasticJobType, jobConfig, jobFacade) : new ElasticJobExecutor(elasticJob, jobConfig, jobFacade);
         String jobClassName = JobClassNameProviderFactory.getProvider().getJobClassName(elasticJob);
         this.jobConfig = setUpFacade.setUpJobConfiguration(jobClassName, jobConfig);
-        setGuaranteeServiceForElasticJobListeners(regCenter, elasticJobListeners);
+        setGuaranteeServiceForElasticJobListeners(regCenter, jobListeners);
         jobScheduleController = createJobScheduleController();
     }
     
     public JobScheduler(final CoordinatorRegistryCenter regCenter, final String elasticJobType, final JobConfiguration jobConfig) {
-        this(regCenter, elasticJobType, jobConfig, null);
-    }
-    
-    public JobScheduler(final CoordinatorRegistryCenter regCenter, final String elasticJobType, final JobConfiguration jobConfig, final TracingConfiguration<?> tracingConfig) {
         this.regCenter = regCenter;
         this.elasticJobType = elasticJobType;
-        final Collection<ElasticJobListener> elasticJobListeners = jobConfig.getJobListenerTypes().stream()
-                .map(type -> ElasticJobListenerFactory.createListener(type).orElseThrow(() -> new IllegalArgumentException(String.format("Can not find job listener type '%s'.", type))))
-                .collect(Collectors.toList());
-        setUpFacade = new SetUpFacade(regCenter, jobConfig.getJobName(), elasticJobListeners);
+        Collection<ElasticJobListener> jobListeners = getElasticJobListeners(jobConfig);
+        setUpFacade = new SetUpFacade(regCenter, jobConfig.getJobName(), jobListeners);
         schedulerFacade = new SchedulerFacade(regCenter, jobConfig.getJobName());
-        jobFacade = new LiteJobFacade(regCenter, jobConfig.getJobName(), elasticJobListeners, tracingConfig);
+        jobFacade = new LiteJobFacade(regCenter, jobConfig.getJobName(), jobListeners, findTracingConfiguration(jobConfig).orElse(null));
         jobExecutor = new ElasticJobExecutor(elasticJobType, jobConfig, jobFacade);
         this.jobConfig = setUpFacade.setUpJobConfiguration(elasticJobType, jobConfig);
-        setGuaranteeServiceForElasticJobListeners(regCenter, elasticJobListeners);
+        setGuaranteeServiceForElasticJobListeners(regCenter, jobListeners);
         jobScheduleController = createJobScheduleController();
     }
-    
-    private Optional<TracingConfiguration> findTracingConfiguration(final JobConfiguration jobConfig) {
-        return jobConfig.getExtraConfigurations().stream().filter(each -> each instanceof TracingConfiguration).findFirst().map(extraConfig -> (TracingConfiguration) extraConfig);
+
+    private Collection<ElasticJobListener> getElasticJobListeners(final JobConfiguration jobConfig) {
+        return jobConfig.getJobListenerTypes().stream()
+                .map(type -> ElasticJobListenerFactory.createListener(type).orElseThrow(() -> new IllegalArgumentException(String.format("Can not find job listener type '%s'.", type))))
+                .collect(Collectors.toList());
+    }
+
+    private Optional<TracingConfiguration<?>> findTracingConfiguration(final JobConfiguration jobConfig) {
+        return jobConfig.getExtraConfigurations().stream().filter(each -> each instanceof TracingConfiguration).findFirst().map(extraConfig -> (TracingConfiguration<?>) extraConfig);
     }
     
     private void setGuaranteeServiceForElasticJobListeners(final CoordinatorRegistryCenter regCenter, final Collection<ElasticJobListener> elasticJobListeners) {