diff --git a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/ReflectUtil.java b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/ReflectUtil.java index 7c4d55d7..1e18e84f 100644 --- a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/ReflectUtil.java +++ b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/ReflectUtil.java @@ -266,9 +266,8 @@ public class ReflectUtil { } /** - * Find field by fieldName and fieldType - * - * @param obj target obj + * find field by fieldName and fieldType + * @param obj target obj * @param filedName filedName * @param fieldType fieldType * @return target field or null diff --git a/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/adpter/DynamicThreadPoolAdapterChoose.java b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/adpter/DynamicThreadPoolAdapterChoose.java index 55541893..83ca0f63 100644 --- a/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/adpter/DynamicThreadPoolAdapterChoose.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/adpter/DynamicThreadPoolAdapterChoose.java @@ -17,9 +17,12 @@ package cn.hippo4j.core.executor.support.adpter; +import cn.hippo4j.common.spi.DynamicThreadPoolServiceLoader; import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; +import cn.hippo4j.core.executor.support.spi.DynamicThreadPoolAdapterSPI; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Optional; import java.util.concurrent.Executor; @@ -36,6 +39,7 @@ public class DynamicThreadPoolAdapterChoose { DYNAMIC_THREAD_POOL_ADAPTERS.add(new TransmittableThreadLocalExecutorServiceAdapter()); DYNAMIC_THREAD_POOL_ADAPTERS.add(new ThreadPoolTaskExecutorAdapter()); DYNAMIC_THREAD_POOL_ADAPTERS.add(new ZipkinExecutorAdapter()); + loadCustomerAdapter(); } /** @@ -75,4 +79,18 @@ public class DynamicThreadPoolAdapterChoose { dynamicThreadPoolAdapterOptional.get().replace(executor, dynamicThreadPoolExecutor); } } + + /** + * load SPI customer adapter + */ + private static void loadCustomerAdapter() { + DynamicThreadPoolServiceLoader.register(DynamicThreadPoolAdapterSPI.class); + Collection instances = DynamicThreadPoolServiceLoader.getSingletonServiceInstances(DynamicThreadPoolAdapterSPI.class); + for (DynamicThreadPoolAdapterSPI instance : instances) { + DynamicThreadPoolAdapter adapter = instance.adapter(); + if (adapter != null) { + DYNAMIC_THREAD_POOL_ADAPTERS.add(adapter); + } + } + } } diff --git a/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/spi/DynamicThreadPoolAdapterSPI.java b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/spi/DynamicThreadPoolAdapterSPI.java new file mode 100644 index 00000000..9d0601c1 --- /dev/null +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/spi/DynamicThreadPoolAdapterSPI.java @@ -0,0 +1,26 @@ +/* + * 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. + */ + +package cn.hippo4j.core.executor.support.spi; + +import cn.hippo4j.core.executor.support.adpter.DynamicThreadPoolAdapter; + +public interface DynamicThreadPoolAdapterSPI { + + String name(); + DynamicThreadPoolAdapter adapter(); +}