TeslaCN commented on a change in pull request #1476:
URL:
https://github.com/apache/shardingsphere-elasticjob/pull/1476#discussion_r492432442
##########
File path:
elasticjob-api/src/main/java/org/apache/shardingsphere/elasticjob/api/JobConfiguration.java
##########
@@ -106,6 +111,8 @@ public static Builder newBuilder(final String jobName,
final int shardingTotalCo
private String jobExecutorServiceHandlerType;
private String jobErrorHandlerType;
+
+ private final Collection<String> jobListenerTypes = new ArrayList<>();
Review comment:
Collection is unordered. Consider HashSet or other?
##########
File path:
elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/JobScheduler.java
##########
@@ -71,46 +68,44 @@
@Getter
private final JobScheduleController jobScheduleController;
- public JobScheduler(final CoordinatorRegistryCenter regCenter, final
ElasticJob elasticJob, final JobConfiguration jobConfig, final
ElasticJobListener... elasticJobListeners) {
- this(regCenter, elasticJob, jobConfig, null, elasticJobListeners);
+ public JobScheduler(final CoordinatorRegistryCenter regCenter, final
ElasticJob elasticJob, final JobConfiguration jobConfig) {
+ this(regCenter, elasticJob, jobConfig, null);
}
- public JobScheduler(final CoordinatorRegistryCenter regCenter, final
ElasticJob elasticJob, final JobConfiguration jobConfig, final
TracingConfiguration<?> tracingConfig,
- final ElasticJobListener... elasticJobListeners) {
+ public JobScheduler(final CoordinatorRegistryCenter regCenter, final
ElasticJob elasticJob, final JobConfiguration jobConfig, final
TracingConfiguration<?> tracingConfig) {
this.regCenter = regCenter;
- this.elasticJob = elasticJob;
elasticJobType = null;
- this.elasticJobListeners = Arrays.asList(elasticJobListeners);
- setUpFacade = new SetUpFacade(regCenter, jobConfig.getJobName(),
this.elasticJobListeners);
+ final Collection<ElasticJobListener> elasticJobListeners =
jobConfig.getJobListenerTypes().stream()
+ .map(type ->
ElasticJobListenerFactory.getListener(type)).collect(Collectors.toList());
Review comment:
I think replace lambda with method reference
'ElasticJobListenerFactory::getListener' is more elegant.
##########
File path:
elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/JobScheduler.java
##########
@@ -71,46 +68,44 @@
@Getter
private final JobScheduleController jobScheduleController;
- public JobScheduler(final CoordinatorRegistryCenter regCenter, final
ElasticJob elasticJob, final JobConfiguration jobConfig, final
ElasticJobListener... elasticJobListeners) {
- this(regCenter, elasticJob, jobConfig, null, elasticJobListeners);
+ public JobScheduler(final CoordinatorRegistryCenter regCenter, final
ElasticJob elasticJob, final JobConfiguration jobConfig) {
+ this(regCenter, elasticJob, jobConfig, null);
}
- public JobScheduler(final CoordinatorRegistryCenter regCenter, final
ElasticJob elasticJob, final JobConfiguration jobConfig, final
TracingConfiguration<?> tracingConfig,
- final ElasticJobListener... elasticJobListeners) {
+ public JobScheduler(final CoordinatorRegistryCenter regCenter, final
ElasticJob elasticJob, final JobConfiguration jobConfig, final
TracingConfiguration<?> tracingConfig) {
this.regCenter = regCenter;
- this.elasticJob = elasticJob;
elasticJobType = null;
- this.elasticJobListeners = Arrays.asList(elasticJobListeners);
- setUpFacade = new SetUpFacade(regCenter, jobConfig.getJobName(),
this.elasticJobListeners);
+ final Collection<ElasticJobListener> elasticJobListeners =
jobConfig.getJobListenerTypes().stream()
+ .map(type ->
ElasticJobListenerFactory.getListener(type)).collect(Collectors.toList());
+ setUpFacade = new SetUpFacade(regCenter, jobConfig.getJobName(),
elasticJobListeners);
schedulerFacade = new SchedulerFacade(regCenter,
jobConfig.getJobName());
- jobFacade = new LiteJobFacade(regCenter, jobConfig.getJobName(),
this.elasticJobListeners, tracingConfig);
+ jobFacade = new LiteJobFacade(regCenter, jobConfig.getJobName(),
elasticJobListeners, tracingConfig);
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,
this.elasticJobListeners);
+ setGuaranteeServiceForElasticJobListeners(regCenter,
elasticJobListeners);
jobScheduleController = createJobScheduleController();
}
- public JobScheduler(final CoordinatorRegistryCenter regCenter, final
String elasticJobType, final JobConfiguration jobConfig, final
ElasticJobListener... elasticJobListeners) {
- this(regCenter, elasticJobType, jobConfig, null, elasticJobListeners);
+ 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,
- final ElasticJobListener... elasticJobListeners) {
+ public JobScheduler(final CoordinatorRegistryCenter regCenter, final
String elasticJobType, final JobConfiguration jobConfig, final
TracingConfiguration<?> tracingConfig) {
this.regCenter = regCenter;
- elasticJob = null;
this.elasticJobType = elasticJobType;
- this.elasticJobListeners = Arrays.asList(elasticJobListeners);
- setUpFacade = new SetUpFacade(regCenter, jobConfig.getJobName(),
this.elasticJobListeners);
+ final Collection<ElasticJobListener> elasticJobListeners =
jobConfig.getJobListenerTypes().stream()
+ .map(type ->
ElasticJobListenerFactory.getListener(type)).collect(Collectors.toList());
Review comment:
I think replace lambda with method reference
'ElasticJobListenerFactory::getListener' is more elegant.
##########
File path:
elasticjob-lite/elasticjob-lite-core/src/test/resources/META-INF/services/org.apache.shardingsphere.elasticjob.infra.listener.ElasticJobListener
##########
@@ -0,0 +1,21 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.elasticjob.lite.api.listener.fixture.TestDistributeOnceElasticJobListener
+org.apache.shardingsphere.elasticjob.lite.api.listener.fixture.TestElasticJobListener
+org.apache.shardingsphere.elasticjob.lite.integrate.listener.TestDistributeOnceElasticJobListener
+org.apache.shardingsphere.elasticjob.lite.integrate.listener.TestElasticJobListener
Review comment:
Need a blank line.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]