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:38:30 UTC

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

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



##########
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:
       Very nice suggestion!  I will correct it soon.




----------------------------------------------------------------
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