refactor: Update packageNames and classNames, mark ServiceLoader deprecated.

pull/1102/head
yanrongzhen 3 years ago
parent 9931c2834b
commit b4563fbd8a

@ -17,7 +17,7 @@
package cn.hippo4j.common.executor.support; package cn.hippo4j.common.executor.support;
import cn.hippo4j.common.spi.DynamicThreadPoolServiceLoader; import cn.hippo4j.common.extension.support.ServiceLoaderRegistry;
import lombok.Getter; import lombok.Getter;
import java.util.Collection; import java.util.Collection;
@ -194,12 +194,12 @@ public enum BlockingQueueTypeEnum {
private static final int DEFAULT_CAPACITY = 1024; private static final int DEFAULT_CAPACITY = 1024;
static { static {
DynamicThreadPoolServiceLoader.register(CustomBlockingQueue.class); ServiceLoaderRegistry.register(CustomBlockingQueue.class);
} }
private static <T> BlockingQueue<T> customOrDefaultQueue(Integer capacity, Predicate<CustomBlockingQueue> predicate) { private static <T> BlockingQueue<T> customOrDefaultQueue(Integer capacity, Predicate<CustomBlockingQueue> predicate) {
Collection<CustomBlockingQueue> customBlockingQueues = DynamicThreadPoolServiceLoader Collection<CustomBlockingQueue> customBlockingQueues = ServiceLoaderRegistry
.getSingletonServiceInstances(CustomBlockingQueue.class); .getSingletonServiceInstances(CustomBlockingQueue.class);
return customBlockingQueues.stream() return customBlockingQueues.stream()

@ -17,7 +17,7 @@
package cn.hippo4j.common.executor.support; package cn.hippo4j.common.executor.support;
import cn.hippo4j.common.spi.DynamicThreadPoolServiceLoader; import cn.hippo4j.common.extension.support.ServiceLoaderRegistry;
import lombok.Getter; import lombok.Getter;
import java.util.Collection; import java.util.Collection;
@ -59,7 +59,7 @@ public enum RejectedPolicyTypeEnum {
} }
static { static {
DynamicThreadPoolServiceLoader.register(CustomRejectedExecutionHandler.class); ServiceLoaderRegistry.register(CustomRejectedExecutionHandler.class);
} }
public static RejectedExecutionHandler createPolicy(String name) { public static RejectedExecutionHandler createPolicy(String name) {
@ -70,7 +70,7 @@ public enum RejectedPolicyTypeEnum {
if (rejectedTypeEnum != null) { if (rejectedTypeEnum != null) {
return rejectedTypeEnum.rejectedHandler; return rejectedTypeEnum.rejectedHandler;
} }
Collection<CustomRejectedExecutionHandler> customRejectedExecutionHandlers = DynamicThreadPoolServiceLoader Collection<CustomRejectedExecutionHandler> customRejectedExecutionHandlers = ServiceLoaderRegistry
.getSingletonServiceInstances(CustomRejectedExecutionHandler.class); .getSingletonServiceInstances(CustomRejectedExecutionHandler.class);
Optional<RejectedExecutionHandler> customRejected = customRejectedExecutionHandlers.stream() Optional<RejectedExecutionHandler> customRejected = customRejectedExecutionHandlers.stream()
.filter(each -> Objects.equals(name, each.getName())) .filter(each -> Objects.equals(name, each.getName()))
@ -85,7 +85,7 @@ public enum RejectedPolicyTypeEnum {
.map(each -> each.rejectedHandler) .map(each -> each.rejectedHandler)
.findFirst(); .findFirst();
RejectedExecutionHandler resultRejected = rejectedTypeEnum.orElseGet(() -> { RejectedExecutionHandler resultRejected = rejectedTypeEnum.orElseGet(() -> {
Collection<CustomRejectedExecutionHandler> customRejectedExecutionHandlers = DynamicThreadPoolServiceLoader Collection<CustomRejectedExecutionHandler> customRejectedExecutionHandlers = ServiceLoaderRegistry
.getSingletonServiceInstances(CustomRejectedExecutionHandler.class); .getSingletonServiceInstances(CustomRejectedExecutionHandler.class);
Optional<RejectedExecutionHandler> customRejected = customRejectedExecutionHandlers.stream() Optional<RejectedExecutionHandler> customRejected = customRejectedExecutionHandlers.stream()
.filter(each -> Objects.equals(type, each.getType())) .filter(each -> Objects.equals(type, each.getType()))

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.common.spi.annotation; package cn.hippo4j.common.extension.annotation;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
@ -27,5 +27,6 @@ import java.lang.annotation.Target;
*/ */
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Deprecated
public @interface SingletonSPI { public @interface SingletonSPI {
} }

@ -20,7 +20,6 @@ package cn.hippo4j.common.extension.support;
import cn.hippo4j.common.extension.IExtension; import cn.hippo4j.common.extension.IExtension;
import cn.hippo4j.common.extension.reducer.Reducer; import cn.hippo4j.common.extension.reducer.Reducer;
import cn.hippo4j.common.extension.reducer.Reducers; import cn.hippo4j.common.extension.reducer.Reducers;
import cn.hippo4j.common.spi.DynamicThreadPoolServiceLoader;
import cn.hippo4j.common.toolkit.Assert; import cn.hippo4j.common.toolkit.Assert;
import cn.hippo4j.common.toolkit.CollectionUtil; import cn.hippo4j.common.toolkit.CollectionUtil;
@ -50,7 +49,7 @@ public class ExtensionInvoker {
List<IExtension> implementations = registry.find(targetClz); List<IExtension> implementations = registry.find(targetClz);
if (CollectionUtil.isEmpty(implementations)) { if (CollectionUtil.isEmpty(implementations)) {
implementations = new ArrayList<>(DynamicThreadPoolServiceLoader.getSingletonServiceInstances(targetClz)); implementations = new ArrayList<>(ServiceLoaderRegistry.getSingletonServiceInstances(targetClz));
} }
Assert.notEmpty(implementations, "can not find any extension realizations with interface: " + targetClz.getName()); Assert.notEmpty(implementations, "can not find any extension realizations with interface: " + targetClz.getName());

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.common.spi; package cn.hippo4j.common.extension.support;
/** /**
* Service loader instantiation exception. * Service loader instantiation exception.

@ -15,9 +15,10 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.common.spi; package cn.hippo4j.common.extension.support;
import cn.hippo4j.common.spi.annotation.SingletonSPI; import cn.hippo4j.common.extension.annotation.SingletonSPI;
import cn.hippo4j.common.extension.support.ServiceLoaderInstantiationException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.Collection; import java.util.Collection;
@ -29,9 +30,10 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
* Dynamic thread-pool service loader. * Dynamic thread-pool SPI service loader.
*/ */
public class DynamicThreadPoolServiceLoader { @Deprecated
public class ServiceLoaderRegistry {
/** /**
* safe container * safe container
@ -40,7 +42,7 @@ public class DynamicThreadPoolServiceLoader {
*/ */
private static final Map<Class<?>, Collection<?>> SERVICES = new ConcurrentHashMap<>(); private static final Map<Class<?>, Collection<?>> SERVICES = new ConcurrentHashMap<>();
private DynamicThreadPoolServiceLoader() { private ServiceLoaderRegistry() {
} }
/** /**

@ -27,13 +27,10 @@ import cn.hippo4j.common.extension.reducer.Reducers;
import cn.hippo4j.common.extension.spi.IOldSpi; import cn.hippo4j.common.extension.spi.IOldSpi;
import cn.hippo4j.common.extension.support.ExtensionInvoker; import cn.hippo4j.common.extension.support.ExtensionInvoker;
import cn.hippo4j.common.extension.support.ExtensionRegistry; import cn.hippo4j.common.extension.support.ExtensionRegistry;
import cn.hippo4j.common.spi.DynamicThreadPoolServiceLoader; import cn.hippo4j.common.extension.support.ServiceLoaderRegistry;
import org.assertj.core.util.Lists; import org.assertj.core.util.Lists;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -49,7 +46,7 @@ public class ExtensionInvokerTest {
ExtensionRegistry.getInstance().register(new AnyMatchExtImplA()); ExtensionRegistry.getInstance().register(new AnyMatchExtImplA());
ExtensionRegistry.getInstance().register(new AnyMatchExtImplB()); ExtensionRegistry.getInstance().register(new AnyMatchExtImplB());
DynamicThreadPoolServiceLoader.register(IOldSpi.class); ServiceLoaderRegistry.register(IOldSpi.class);
} }
@Test @Test
public void test() { public void test() {

@ -19,6 +19,7 @@ package cn.hippo4j.common.spi;
import java.util.Collection; import java.util.Collection;
import cn.hippo4j.common.extension.support.ServiceLoaderRegistry;
import org.junit.Test; import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
@ -28,46 +29,46 @@ import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
/** /**
* test {@link DynamicThreadPoolServiceLoader} * test {@link ServiceLoaderRegistry}
*/ */
public final class DynamicThreadPoolServiceLoaderTest { public final class DynamicThreadPoolServiceLoaderTest {
@Test @Test
public void assertRegister() { public void assertRegister() {
DynamicThreadPoolServiceLoader.register(Collection.class); ServiceLoaderRegistry.register(Collection.class);
Collection<?> collections = DynamicThreadPoolServiceLoader.getSingletonServiceInstances(Collection.class); Collection<?> collections = ServiceLoaderRegistry.getSingletonServiceInstances(Collection.class);
assertTrue(collections.isEmpty()); assertTrue(collections.isEmpty());
} }
@Test @Test
public void assertGetSingletonServiceInstances() { public void assertGetSingletonServiceInstances() {
DynamicThreadPoolServiceLoader.register(TestSingletonInterfaceSPI.class); ServiceLoaderRegistry.register(TestSingletonInterfaceSPI.class);
Collection<TestSingletonInterfaceSPI> instances = DynamicThreadPoolServiceLoader.getSingletonServiceInstances(TestSingletonInterfaceSPI.class); Collection<TestSingletonInterfaceSPI> instances = ServiceLoaderRegistry.getSingletonServiceInstances(TestSingletonInterfaceSPI.class);
assertThat(instances.size(), equalTo(1)); assertThat(instances.size(), equalTo(1));
assertThat(instances.iterator().next(), is(DynamicThreadPoolServiceLoader.getSingletonServiceInstances(TestSingletonInterfaceSPI.class).iterator().next())); assertThat(instances.iterator().next(), is(ServiceLoaderRegistry.getSingletonServiceInstances(TestSingletonInterfaceSPI.class).iterator().next()));
} }
@Test @Test
public void assertNewServiceInstances() { public void assertNewServiceInstances() {
DynamicThreadPoolServiceLoader.register(TestSingletonInterfaceSPI.class); ServiceLoaderRegistry.register(TestSingletonInterfaceSPI.class);
Collection<TestSingletonInterfaceSPI> instances = DynamicThreadPoolServiceLoader.newServiceInstances(TestSingletonInterfaceSPI.class); Collection<TestSingletonInterfaceSPI> instances = ServiceLoaderRegistry.newServiceInstances(TestSingletonInterfaceSPI.class);
assertThat(instances.size(), equalTo(1)); assertThat(instances.size(), equalTo(1));
assertThat(instances.iterator().next(), not(DynamicThreadPoolServiceLoader.getSingletonServiceInstances(TestSingletonInterfaceSPI.class).iterator().next())); assertThat(instances.iterator().next(), not(ServiceLoaderRegistry.getSingletonServiceInstances(TestSingletonInterfaceSPI.class).iterator().next()));
} }
@Test @Test
public void assertGetServiceInstancesWhenIsSingleton() { public void assertGetServiceInstancesWhenIsSingleton() {
DynamicThreadPoolServiceLoader.register(TestSingletonInterfaceSPI.class); ServiceLoaderRegistry.register(TestSingletonInterfaceSPI.class);
Collection<TestSingletonInterfaceSPI> instances = DynamicThreadPoolServiceLoader.getServiceInstances(TestSingletonInterfaceSPI.class); Collection<TestSingletonInterfaceSPI> instances = ServiceLoaderRegistry.getServiceInstances(TestSingletonInterfaceSPI.class);
assertThat(instances.iterator().next(), is(DynamicThreadPoolServiceLoader.getSingletonServiceInstances(TestSingletonInterfaceSPI.class).iterator().next())); assertThat(instances.iterator().next(), is(ServiceLoaderRegistry.getSingletonServiceInstances(TestSingletonInterfaceSPI.class).iterator().next()));
} }
@Test @Test
public void assertGetServiceInstancesWhenNotSingleton() { public void assertGetServiceInstancesWhenNotSingleton() {
DynamicThreadPoolServiceLoader.register(TestInterfaceSPI.class); ServiceLoaderRegistry.register(TestInterfaceSPI.class);
Collection<TestInterfaceSPI> instances = DynamicThreadPoolServiceLoader.getServiceInstances(TestInterfaceSPI.class); Collection<TestInterfaceSPI> instances = ServiceLoaderRegistry.getServiceInstances(TestInterfaceSPI.class);
assertThat(instances.iterator().next(), not(DynamicThreadPoolServiceLoader.getSingletonServiceInstances(TestInterfaceSPI.class).iterator().next())); assertThat(instances.iterator().next(), not(ServiceLoaderRegistry.getSingletonServiceInstances(TestInterfaceSPI.class).iterator().next()));
} }
} }

@ -17,8 +17,10 @@
package cn.hippo4j.common.spi; package cn.hippo4j.common.spi;
import cn.hippo4j.common.extension.support.ServiceLoaderRegistry;
/** /**
* test {@link DynamicThreadPoolServiceLoader} * test {@link ServiceLoaderRegistry}
*/ */
public interface TestInterfaceSPI { public interface TestInterfaceSPI {
} }

@ -17,8 +17,10 @@
package cn.hippo4j.common.spi; package cn.hippo4j.common.spi;
import cn.hippo4j.common.extension.support.ServiceLoaderRegistry;
/** /**
* test {@link DynamicThreadPoolServiceLoader} * test {@link ServiceLoaderRegistry}
*/ */
public class TestInterfaceSPIImpl implements TestInterfaceSPI { public class TestInterfaceSPIImpl implements TestInterfaceSPI {
} }

@ -17,10 +17,11 @@
package cn.hippo4j.common.spi; package cn.hippo4j.common.spi;
import cn.hippo4j.common.spi.annotation.SingletonSPI; import cn.hippo4j.common.extension.annotation.SingletonSPI;
import cn.hippo4j.common.extension.support.ServiceLoaderRegistry;
/** /**
* test {@link DynamicThreadPoolServiceLoader} * test {@link ServiceLoaderRegistry}
*/ */
@SingletonSPI @SingletonSPI
public interface TestSingletonInterfaceSPI { public interface TestSingletonInterfaceSPI {

@ -17,8 +17,10 @@
package cn.hippo4j.common.spi; package cn.hippo4j.common.spi;
import cn.hippo4j.common.extension.support.ServiceLoaderRegistry;
/** /**
* test {@link DynamicThreadPoolServiceLoader} * test {@link ServiceLoaderRegistry}
*/ */
public class TestSingletonInterfaceSPIImpl implements TestSingletonInterfaceSPI { public class TestSingletonInterfaceSPIImpl implements TestSingletonInterfaceSPI {
} }

@ -17,7 +17,7 @@
package cn.hippo4j.core.executor.support.adpter; package cn.hippo4j.core.executor.support.adpter;
import cn.hippo4j.common.spi.DynamicThreadPoolServiceLoader; import cn.hippo4j.common.extension.support.ServiceLoaderRegistry;
import cn.hippo4j.common.toolkit.CollectionUtil; import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; import cn.hippo4j.core.executor.DynamicThreadPoolExecutor;
import cn.hippo4j.core.executor.support.spi.DynamicThreadPoolAdapterSPI; import cn.hippo4j.core.executor.support.spi.DynamicThreadPoolAdapterSPI;
@ -85,8 +85,8 @@ public class DynamicThreadPoolAdapterChoose {
* Load SPI customer adapter. * Load SPI customer adapter.
*/ */
private static void loadCustomerAdapter() { private static void loadCustomerAdapter() {
DynamicThreadPoolServiceLoader.register(DynamicThreadPoolAdapterSPI.class); ServiceLoaderRegistry.register(DynamicThreadPoolAdapterSPI.class);
Collection<DynamicThreadPoolAdapterSPI> instances = DynamicThreadPoolServiceLoader.getSingletonServiceInstances(DynamicThreadPoolAdapterSPI.class); Collection<DynamicThreadPoolAdapterSPI> instances = ServiceLoaderRegistry.getSingletonServiceInstances(DynamicThreadPoolAdapterSPI.class);
if (CollectionUtil.isEmpty(instances)) { if (CollectionUtil.isEmpty(instances)) {
return; return;
} }

@ -19,7 +19,7 @@ package cn.hippo4j.core.toolkit;
import cn.hippo4j.common.api.ClientNetworkService; import cn.hippo4j.common.api.ClientNetworkService;
import cn.hippo4j.common.config.ApplicationContextHolder; import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.common.spi.DynamicThreadPoolServiceLoader; import cn.hippo4j.common.extension.support.ServiceLoaderRegistry;
import cn.hippo4j.common.toolkit.CollectionUtil; import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.common.toolkit.IdUtil; import cn.hippo4j.common.toolkit.IdUtil;
import cn.hippo4j.common.toolkit.Joiner; import cn.hippo4j.common.toolkit.Joiner;
@ -39,7 +39,7 @@ import static cn.hippo4j.common.constant.Constants.IDENTIFY_SLICER_SYMBOL;
public class IdentifyUtil { public class IdentifyUtil {
static { static {
DynamicThreadPoolServiceLoader.register(ClientNetworkService.class); ServiceLoaderRegistry.register(ClientNetworkService.class);
} }
/** /**
@ -63,7 +63,7 @@ public class IdentifyUtil {
if (StringUtil.isNotBlank(IDENTIFY)) { if (StringUtil.isNotBlank(IDENTIFY)) {
return IDENTIFY; return IDENTIFY;
} }
String[] customerNetwork = DynamicThreadPoolServiceLoader.getSingletonServiceInstances(ClientNetworkService.class) String[] customerNetwork = ServiceLoaderRegistry.getSingletonServiceInstances(ClientNetworkService.class)
.stream().findFirst().map(each -> each.getNetworkIpPort(environment)).orElse(null); .stream().findFirst().map(each -> each.getNetworkIpPort(environment)).orElse(null);
String ip; String ip;
String port; String port;

@ -27,7 +27,7 @@ import java.util.concurrent.TimeUnit;
import cn.hippo4j.common.config.ApplicationContextHolder; import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.common.design.builder.ThreadFactoryBuilder; import cn.hippo4j.common.design.builder.ThreadFactoryBuilder;
import cn.hippo4j.common.spi.DynamicThreadPoolServiceLoader; import cn.hippo4j.common.extension.support.ServiceLoaderRegistry;
import cn.hippo4j.common.toolkit.StringUtil; import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.config.springboot.starter.config.BootstrapConfigProperties; import cn.hippo4j.config.springboot.starter.config.BootstrapConfigProperties;
import cn.hippo4j.config.springboot.starter.config.MonitorProperties; import cn.hippo4j.config.springboot.starter.config.MonitorProperties;
@ -74,7 +74,7 @@ public class ThreadPoolMonitorExecutor implements ApplicationRunner, DisposableB
List<String> collectTypes = Arrays.asList(monitor.getCollectTypes().split(",")); List<String> collectTypes = Arrays.asList(monitor.getCollectTypes().split(","));
ApplicationContextHolder.getBeansOfType(ThreadPoolMonitor.class).forEach((beanName, bean) -> threadPoolMonitors.add(bean)); ApplicationContextHolder.getBeansOfType(ThreadPoolMonitor.class).forEach((beanName, bean) -> threadPoolMonitors.add(bean));
Collection<DynamicThreadPoolMonitor> dynamicThreadPoolMonitors = Collection<DynamicThreadPoolMonitor> dynamicThreadPoolMonitors =
DynamicThreadPoolServiceLoader.getSingletonServiceInstances(DynamicThreadPoolMonitor.class); ServiceLoaderRegistry.getSingletonServiceInstances(DynamicThreadPoolMonitor.class);
dynamicThreadPoolMonitors.stream().filter(each -> collectTypes.contains(each.getType())).forEach(each -> threadPoolMonitors.add(each)); dynamicThreadPoolMonitors.stream().filter(each -> collectTypes.contains(each.getType())).forEach(each -> threadPoolMonitors.add(each));
// Execute dynamic thread pool monitoring component. // Execute dynamic thread pool monitoring component.
collectScheduledExecutor.scheduleWithFixedDelay( collectScheduledExecutor.scheduleWithFixedDelay(

@ -21,7 +21,7 @@ import cn.hippo4j.adapter.base.ThreadPoolAdapter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter; import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterState; import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
import cn.hippo4j.common.api.ClientNetworkService; import cn.hippo4j.common.api.ClientNetworkService;
import cn.hippo4j.common.spi.DynamicThreadPoolServiceLoader; import cn.hippo4j.common.extension.support.ServiceLoaderRegistry;
import cn.hippo4j.common.toolkit.StringUtil; import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.common.web.base.Result; import cn.hippo4j.common.web.base.Result;
import cn.hippo4j.common.web.base.Results; import cn.hippo4j.common.web.base.Results;
@ -59,7 +59,7 @@ public class ThreadPoolAdapterController {
ThreadPoolAdapterState threadPoolState = each.getThreadPoolState(requestParameter.getThreadPoolKey()); ThreadPoolAdapterState threadPoolState = each.getThreadPoolState(requestParameter.getThreadPoolKey());
String active = environment.getProperty("spring.profiles.active", "UNKNOWN"); String active = environment.getProperty("spring.profiles.active", "UNKNOWN");
threadPoolState.setActive(active.toUpperCase()); threadPoolState.setActive(active.toUpperCase());
String[] customerNetwork = DynamicThreadPoolServiceLoader.getSingletonServiceInstances(ClientNetworkService.class) String[] customerNetwork = ServiceLoaderRegistry.getSingletonServiceInstances(ClientNetworkService.class)
.stream().findFirst().map(network -> network.getNetworkIpPort(environment)).orElse(null); .stream().findFirst().map(network -> network.getNetworkIpPort(environment)).orElse(null);
String clientAddress; String clientAddress;
if (customerNetwork != null) { if (customerNetwork != null) {

@ -20,7 +20,7 @@ package cn.hippo4j.springboot.starter.monitor;
import cn.hippo4j.common.config.ApplicationContextHolder; import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.common.design.builder.ThreadFactoryBuilder; import cn.hippo4j.common.design.builder.ThreadFactoryBuilder;
import cn.hippo4j.common.monitor.Message; import cn.hippo4j.common.monitor.Message;
import cn.hippo4j.common.spi.DynamicThreadPoolServiceLoader; import cn.hippo4j.common.extension.support.ServiceLoaderRegistry;
import cn.hippo4j.common.toolkit.CollectionUtil; import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.common.toolkit.StringUtil; import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.common.toolkit.ThreadUtil; import cn.hippo4j.common.toolkit.ThreadUtil;
@ -119,7 +119,7 @@ public class ReportingEventExecutor implements Runnable, CommandLineRunner, Disp
new Integer(collectType.split(",").length), new Integer(collectType.split(",").length),
ThreadFactoryBuilder.builder().daemon(true).prefix("client.scheduled.collect.data").build()); ThreadFactoryBuilder.builder().daemon(true).prefix("client.scheduled.collect.data").build());
Collection<ThreadPoolMonitor> dynamicThreadPoolMonitors = Collection<ThreadPoolMonitor> dynamicThreadPoolMonitors =
DynamicThreadPoolServiceLoader.getSingletonServiceInstances(ThreadPoolMonitor.class); ServiceLoaderRegistry.getSingletonServiceInstances(ThreadPoolMonitor.class);
Map<String, ThreadPoolMonitor> threadPoolMonitorMap = ApplicationContextHolder.getBeansOfType(ThreadPoolMonitor.class); Map<String, ThreadPoolMonitor> threadPoolMonitorMap = ApplicationContextHolder.getBeansOfType(ThreadPoolMonitor.class);
boolean customerDynamicThreadPoolMonitorFlag = CollectionUtil.isNotEmpty(dynamicThreadPoolMonitors) || CollectionUtil.isNotEmpty(threadPoolMonitorMap); boolean customerDynamicThreadPoolMonitorFlag = CollectionUtil.isNotEmpty(dynamicThreadPoolMonitors) || CollectionUtil.isNotEmpty(threadPoolMonitorMap);
if (customerDynamicThreadPoolMonitorFlag) { if (customerDynamicThreadPoolMonitorFlag) {

@ -19,7 +19,7 @@ package cn.hippo4j.springboot.starter.provider;
import cn.hippo4j.common.api.ClientNetworkService; import cn.hippo4j.common.api.ClientNetworkService;
import cn.hippo4j.common.model.InstanceInfo; import cn.hippo4j.common.model.InstanceInfo;
import cn.hippo4j.common.spi.DynamicThreadPoolServiceLoader; import cn.hippo4j.common.extension.support.ServiceLoaderRegistry;
import cn.hippo4j.common.toolkit.ContentUtil; import cn.hippo4j.common.toolkit.ContentUtil;
import cn.hippo4j.core.toolkit.IdentifyUtil; import cn.hippo4j.core.toolkit.IdentifyUtil;
import cn.hippo4j.core.toolkit.inet.InetUtils; import cn.hippo4j.core.toolkit.inet.InetUtils;
@ -40,7 +40,7 @@ import static cn.hippo4j.core.toolkit.IdentifyUtil.CLIENT_IDENTIFICATION_VALUE;
public final class InstanceInfoProviderFactory { public final class InstanceInfoProviderFactory {
static { static {
DynamicThreadPoolServiceLoader.register(ClientNetworkService.class); ServiceLoaderRegistry.register(ClientNetworkService.class);
} }
/** /**
@ -69,7 +69,7 @@ public final class InstanceInfoProviderFactory {
.setIpApplicationName(CloudCommonIdUtil.getIpApplicationName(environment, inetUtils)) .setIpApplicationName(CloudCommonIdUtil.getIpApplicationName(environment, inetUtils))
.setHostName(InetAddress.getLocalHost().getHostAddress()).setAppName(applicationName) .setHostName(InetAddress.getLocalHost().getHostAddress()).setAppName(applicationName)
.setPort(port).setClientBasePath(contextPath).setGroupKey(ContentUtil.getGroupKey(itemId, namespace)); .setPort(port).setClientBasePath(contextPath).setGroupKey(ContentUtil.getGroupKey(itemId, namespace));
String[] customerNetwork = DynamicThreadPoolServiceLoader.getSingletonServiceInstances(ClientNetworkService.class) String[] customerNetwork = ServiceLoaderRegistry.getSingletonServiceInstances(ClientNetworkService.class)
.stream().findFirst().map(each -> each.getNetworkIpPort(environment)).orElse(null); .stream().findFirst().map(each -> each.getNetworkIpPort(environment)).orElse(null);
String callBackUrl = new StringBuilder().append(Optional.ofNullable(customerNetwork).map(each -> each[0]).orElse(instanceInfo.getHostName())).append(":") String callBackUrl = new StringBuilder().append(Optional.ofNullable(customerNetwork).map(each -> each[0]).orElse(instanceInfo.getHostName())).append(":")
.append(Optional.ofNullable(customerNetwork).map(each -> each[1]).orElse(port)).append(instanceInfo.getClientBasePath()) .append(Optional.ofNullable(customerNetwork).map(each -> each[1]).orElse(port)).append(instanceInfo.getClientBasePath())

Loading…
Cancel
Save