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:07:04 UTC
[GitHub] [shardingsphere-elasticjob] wwj-go opened a new pull request #1558: Refactor JobItemExecutorFactory
wwj-go opened a new pull request #1558:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/1558
Refactor `JobItemExecutorFactory`, uniformly use `ElasticJobServiceLoader `to load TypedSPI implementation classes. (#1557)
Fixes #1557.
----------------------------------------------------------------
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
[GitHub] [shardingsphere-elasticjob] wwj-go commented on a change in pull request #1558: Refactor JobItemExecutorFactory
Posted by GitBox <gi...@apache.org>.
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
[GitHub] [shardingsphere-elasticjob] TeslaCN commented on a change in pull request #1558: Refactor JobItemExecutorFactory
Posted by GitBox <gi...@apache.org>.
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
[GitHub] [shardingsphere-elasticjob] Technoboy- merged pull request #1558: Refactor JobItemExecutorFactory
Posted by GitBox <gi...@apache.org>.
Technoboy- merged pull request #1558:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/1558
----------------------------------------------------------------
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
[GitHub] [shardingsphere-elasticjob] codecov-io commented on pull request #1558: Refactor JobItemExecutorFactory
Posted by GitBox <gi...@apache.org>.
codecov-io commented on pull request #1558:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/1558#issuecomment-708399963
# [Codecov](https://codecov.io/gh/apache/shardingsphere-elasticjob/pull/1558?src=pr&el=h1) Report
> Merging [#1558](https://codecov.io/gh/apache/shardingsphere-elasticjob/pull/1558?src=pr&el=desc) into [master](https://codecov.io/gh/apache/shardingsphere-elasticjob/commit/2e181cb8a48afecbde7f38df6448d3d247836c0c?el=desc) will **decrease** coverage by `0.18%`.
> The diff coverage is `100.00%`.
[![Impacted file tree graph](https://codecov.io/gh/apache/shardingsphere-elasticjob/pull/1558/graphs/tree.svg?width=650&height=150&src=pr&token=8ZMVc4Yo4Z)](https://codecov.io/gh/apache/shardingsphere-elasticjob/pull/1558?src=pr&el=tree)
```diff
@@ Coverage Diff @@
## master #1558 +/- ##
============================================
- Coverage 85.14% 84.96% -0.19%
Complexity 101 101
============================================
Files 247 247
Lines 5683 5672 -11
Branches 890 885 -5
============================================
- Hits 4839 4819 -20
- Misses 530 535 +5
- Partials 314 318 +4
```
| [Impacted Files](https://codecov.io/gh/apache/shardingsphere-elasticjob/pull/1558?src=pr&el=tree) | Coverage Δ | Complexity Δ | |
|---|---|---|---|
| [...asticjob/executor/item/JobItemExecutorFactory.java](https://codecov.io/gh/apache/shardingsphere-elasticjob/pull/1558/diff?src=pr&el=tree#diff-ZWxhc3RpY2pvYi1leGVjdXRvci9lbGFzdGljam9iLWV4ZWN1dG9yLWtlcm5lbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvZWxhc3RpY2pvYi9leGVjdXRvci9pdGVtL0pvYkl0ZW1FeGVjdXRvckZhY3RvcnkuamF2YQ==) | `100.00% <100.00%> (ø)` | `0.00 <0.00> (ø)` | |
| [...ener/AbstractDistributeOnceElasticJobListener.java](https://codecov.io/gh/apache/shardingsphere-elasticjob/pull/1558/diff?src=pr&el=tree#diff-ZWxhc3RpY2pvYi1saXRlL2VsYXN0aWNqb2ItbGl0ZS1jb3JlL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9lbGFzdGljam9iL2xpdGUvYXBpL2xpc3RlbmVyL0Fic3RyYWN0RGlzdHJpYnV0ZU9uY2VFbGFzdGljSm9iTGlzdGVuZXIuamF2YQ==) | `74.07% <0.00%> (-7.41%)` | `0.00% <0.00%> (ø%)` | |
| [...e/shardingsphere/elasticjob/infra/env/IpUtils.java](https://codecov.io/gh/apache/shardingsphere-elasticjob/pull/1558/diff?src=pr&el=tree#diff-ZWxhc3RpY2pvYi1pbmZyYS9lbGFzdGljam9iLWluZnJhLWNvbW1vbi9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvZWxhc3RpY2pvYi9pbmZyYS9lbnYvSXBVdGlscy5qYXZh) | `60.00% <0.00%> (-4.62%)` | `0.00% <0.00%> (ø%)` | |
| [...ite/internal/election/ElectionListenerManager.java](https://codecov.io/gh/apache/shardingsphere-elasticjob/pull/1558/diff?src=pr&el=tree#diff-ZWxhc3RpY2pvYi1saXRlL2VsYXN0aWNqb2ItbGl0ZS1jb3JlL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9lbGFzdGljam9iL2xpdGUvaW50ZXJuYWwvZWxlY3Rpb24vRWxlY3Rpb25MaXN0ZW5lck1hbmFnZXIuamF2YQ==) | `92.00% <0.00%> (-4.00%)` | `0.00% <0.00%> (ø%)` | |
| [...ticjob/lite/internal/snapshot/SnapshotService.java](https://codecov.io/gh/apache/shardingsphere-elasticjob/pull/1558/diff?src=pr&el=tree#diff-ZWxhc3RpY2pvYi1saXRlL2VsYXN0aWNqb2ItbGl0ZS1jb3JlL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9lbGFzdGljam9iL2xpdGUvaW50ZXJuYWwvc25hcHNob3QvU25hcHNob3RTZXJ2aWNlLmphdmE=) | `80.95% <0.00%> (-1.59%)` | `1.00% <0.00%> (ø%)` | |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere-elasticjob/pull/1558?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere-elasticjob/pull/1558?src=pr&el=footer). Last update [2e181cb...1a430b4](https://codecov.io/gh/apache/shardingsphere-elasticjob/pull/1558?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
----------------------------------------------------------------
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