Merge branch '1.4.3-upgrade' into develop

# Conflicts:
#	hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/ReflectUtil.java
#	hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/adpter/DynamicThreadPoolAdapterChoose.java
pull/1052/head
chen.ma 2 years ago
commit d54c42ef28

@ -147,8 +147,8 @@ public class ReflectUtil {
}
/**
* find the method associated with the method name<br>
* if find multiple, return the first, parameter is equivocal
* Find the method associated with the method name<br>
* if find multiple, return the first, parameter is equivocal.
*
* @param clazz the class
* @param methodName retrieves the method name
@ -170,7 +170,7 @@ public class ReflectUtil {
}
/**
* find the method associated with the method name
* Find the method associated with the method name.
*
* @param clazz the class
* @param methodName retrieves the method name
@ -190,7 +190,7 @@ public class ReflectUtil {
/**
* Cast the value to the type <br>
* If a ClassCastException occurs, return null
* If a ClassCastException occurs, return null.
*
* @param clazz Cast class
* @param value The cast value
@ -205,7 +205,7 @@ public class ReflectUtil {
}
/**
* the default value is obtained if it is a primitive type, and NULL if it is not
* The default value is obtained if it is a primitive type, and NULL if it is not.
*
* @param clazz clazz
* @return default value
@ -235,7 +235,7 @@ public class ReflectUtil {
}
/**
* invoke
* Invoke.
*
* @param obj the obj
* @param method the method
@ -252,7 +252,7 @@ public class ReflectUtil {
}
/**
* get instance
* Get instance.
*
* @param cls the class
* @return new Instance
@ -266,7 +266,7 @@ public class ReflectUtil {
}
/**
* Find field by fieldName and fieldType
* Find field by fieldName and field-type.
*
* @param obj target obj
* @param filedName filedName

@ -17,9 +17,13 @@
package cn.hippo4j.core.executor.support.adpter;
import cn.hippo4j.common.spi.DynamicThreadPoolServiceLoader;
import cn.hippo4j.common.toolkit.CollectionUtil;
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 +40,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 +80,21 @@ public class DynamicThreadPoolAdapterChoose {
dynamicThreadPoolAdapterOptional.get().replace(executor, dynamicThreadPoolExecutor);
}
}
/**
* Load SPI customer adapter.
*/
private static void loadCustomerAdapter() {
DynamicThreadPoolServiceLoader.register(DynamicThreadPoolAdapterSPI.class);
Collection<DynamicThreadPoolAdapterSPI> instances = DynamicThreadPoolServiceLoader.getSingletonServiceInstances(DynamicThreadPoolAdapterSPI.class);
if (CollectionUtil.isEmpty(instances)) {
return;
}
for (DynamicThreadPoolAdapterSPI instance : instances) {
DynamicThreadPoolAdapter adapter = instance.adapter();
if (adapter != null) {
DYNAMIC_THREAD_POOL_ADAPTERS.add(adapter);
}
}
}
}

@ -0,0 +1,36 @@
/*
* 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;
/**
* Dynamic thread-pool adapter SPI.
*/
public interface DynamicThreadPoolAdapterSPI {
/**
* Name.
*/
String name();
/**
* Adapter.
*/
DynamicThreadPoolAdapter adapter();
}
Loading…
Cancel
Save