You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/10/14 11:21:21 UTC

[GitHub] [shardingsphere-elasticjob] TeslaCN commented on a change in pull request #1558: Refactor JobItemExecutorFactory

TeslaCN commented on a change in pull request #1558:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/1558#discussion_r504598163



##########
File path: elasticjob-executor/elasticjob-executor-kernel/src/main/java/org/apache/shardingsphere/elasticjob/executor/item/JobItemExecutorFactory.java
##########
@@ -23,32 +23,26 @@
 import org.apache.shardingsphere.elasticjob.infra.exception.JobConfigurationException;
 import org.apache.shardingsphere.elasticjob.executor.item.impl.ClassedJobItemExecutor;
 import org.apache.shardingsphere.elasticjob.executor.item.impl.TypedJobItemExecutor;
+import org.apache.shardingsphere.elasticjob.infra.spi.ElasticJobServiceLoader;
 
+import java.util.HashMap;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.ServiceLoader;
-import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * Job item executor factory.
  */
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
 public final class JobItemExecutorFactory {
     
-    private static final Map<Class, ClassedJobItemExecutor> CLASSED_EXECUTORS = new ConcurrentHashMap<>();
-    
-    private static final Map<String, TypedJobItemExecutor> TYPED_EXECUTORS = new ConcurrentHashMap<>();
+    private static final Map<Class, ClassedJobItemExecutor> CLASSED_EXECUTORS = new HashMap<>();
     
     static {
-        for (JobItemExecutor each : ServiceLoader.load(JobItemExecutor.class)) {
-            if (each instanceof ClassedJobItemExecutor) {
-                ClassedJobItemExecutor typedJobItemExecutor = (ClassedJobItemExecutor) each;
-                CLASSED_EXECUTORS.put(typedJobItemExecutor.getElasticJobClass(), typedJobItemExecutor);
-            }
-            if (each instanceof TypedJobItemExecutor) {
-                TypedJobItemExecutor typedJobItemExecutor = (TypedJobItemExecutor) each;
-                TYPED_EXECUTORS.put(typedJobItemExecutor.getType(), typedJobItemExecutor);
-            }
+        ElasticJobServiceLoader.registerTypedService(TypedJobItemExecutor.class);
+        for (JobItemExecutor each : ServiceLoader.load(ClassedJobItemExecutor.class)) {
+            ClassedJobItemExecutor typedJobItemExecutor = (ClassedJobItemExecutor) each;
+            CLASSED_EXECUTORS.put(typedJobItemExecutor.getElasticJobClass(), typedJobItemExecutor);

Review comment:
       Casting to ClassedJobItemExecutor is unnecessary.
   
   ```suggestion
           ServiceLoader.load(ClassedJobItemExecutor.class)).forEach(each -> CLASSED_EXECUTORS.put(each.getElasticJobClass(), each));           
   ```

##########
File path: elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/resources/META-INF/services/org.apache.shardingsphere.elasticjob.executor.item.impl.ClassedJobItemExecutor
##########
@@ -0,0 +1,17 @@
+#
+# 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.spring.boot.job.executor.CustomClassedJobExecutor

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:
users@infra.apache.org