Merge pull request #480 from mabaiwan/develop

hippo4j-core code naming and log optimization
pull/483/head
小马哥 2 years ago committed by GitHub
commit ed75b45bbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -29,7 +29,7 @@
<dependency> <dependency>
<groupId>com.aliyun</groupId> <groupId>com.aliyun</groupId>
<artifactId>alibaba-dingtalk-service-sdk</artifactId> <artifactId>alibaba-dingtalk-service-sdk</artifactId>
<!-- 用户反馈其中 javax.jms 无法下载, 未发现 log4j 用处, 暂且排除 --> <!-- User feedback that javax.jms cannot be downloaded, log4j is not found useful, so it is excluded for the time being. -->
<exclusions> <exclusions>
<exclusion> <exclusion>
<groupId>log4j</groupId> <groupId>log4j</groupId>

@ -19,9 +19,6 @@ package cn.hippo4j.core.config;
/** /**
* Bootstrap properties interface. * Bootstrap properties interface.
*
* @author chen.ma
* @date 2022/2/25 19:01
*/ */
public interface BootstrapPropertiesInterface { public interface BootstrapPropertiesInterface {

@ -22,21 +22,18 @@ import lombok.Data;
/** /**
* Config empty exception. * Config empty exception.
*
* @author chen.ma
* @date 2021/11/28 21:58
*/ */
@Data @Data
@AllArgsConstructor @AllArgsConstructor
public class ConfigEmptyException extends RuntimeException { public class ConfigEmptyException extends RuntimeException {
/** /**
* description * Description
*/ */
private String description; private String description;
/** /**
* action * Action
*/ */
private String action; private String action;
} }

@ -25,16 +25,13 @@ import org.springframework.context.annotation.Bean;
/** /**
* Util auto configuration. * Util auto configuration.
*
* @author Spencer Gibb
* @date 2021/11/12 21:34
*/ */
@EnableConfigurationProperties(InetUtilsProperties.class) @EnableConfigurationProperties(InetUtilsProperties.class)
public class UtilAutoConfiguration { public class UtilAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public InetUtils hippo4JInetUtils(InetUtilsProperties properties) { public InetUtils hippo4JInetUtils(InetUtilsProperties inetUtilsProperties) {
return new InetUtils(properties); return new InetUtils(inetUtilsProperties);
} }
} }

@ -30,9 +30,6 @@ import java.util.Objects;
/** /**
* Before check configuration. * Before check configuration.
*
* @author chen.ma
* @date 2021/11/28 22:44
*/ */
@Configuration @Configuration
@AllArgsConstructor @AllArgsConstructor

@ -23,9 +23,6 @@ import java.lang.annotation.*;
/** /**
* Annotation to activate dynamic threadPool related configuration. * Annotation to activate dynamic threadPool related configuration.
*
* @author chen.ma
* @date 2021/7/8 23:28
*/ */
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)

@ -22,9 +22,6 @@ import org.springframework.context.annotation.Configuration;
/** /**
* Marker configuration. * Marker configuration.
*
* @author chen.ma
* @date 2021/7/8 23:30
*/ */
@Configuration @Configuration
public class MarkerConfiguration { public class MarkerConfiguration {

@ -24,9 +24,6 @@ import java.lang.annotation.Target;
/** /**
* Dynamic thread pool. * Dynamic thread pool.
*
* @author chen.ma
* @date 2021/10/13 21:50
*/ */
@Target(ElementType.METHOD) @Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)

@ -27,10 +27,7 @@ import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
/** /**
* Dynamic threadPool wrapper. * Dynamic thread-pool wrapper.
*
* @author chen.ma
* @date 2021/6/20 16:55
*/ */
@Data @Data
public class DynamicThreadPoolWrapper implements DisposableBean { public class DynamicThreadPoolWrapper implements DisposableBean {

@ -41,10 +41,7 @@ import java.util.Objects;
import java.util.concurrent.*; import java.util.concurrent.*;
/** /**
* Thread pool alarm notify. * Thread-pool alarm notify.
*
* @author chen.ma
* @date 2021/8/15 14:13
*/ */
@Slf4j @Slf4j
@RequiredArgsConstructor @RequiredArgsConstructor
@ -108,9 +105,9 @@ public class ThreadPoolNotifyAlarmHandler implements Runnable, CommandLineRunner
return; return;
} }
ThreadPoolNotifyAlarm threadPoolNotifyAlarm = GlobalNotifyAlarmManage.get(threadPoolId); ThreadPoolNotifyAlarm threadPoolNotifyAlarm = GlobalNotifyAlarmManage.get(threadPoolId);
BlockingQueue blockIngQueue = threadPoolExecutor.getQueue(); BlockingQueue blockingQueue = threadPoolExecutor.getQueue();
int queueSize = blockIngQueue.size(); int queueSize = blockingQueue.size();
int capacity = queueSize + blockIngQueue.remainingCapacity(); int capacity = queueSize + blockingQueue.remainingCapacity();
int divide = CalculateUtil.divide(queueSize, capacity); int divide = CalculateUtil.divide(queueSize, capacity);
boolean isSend = threadPoolNotifyAlarm.getIsAlarm() boolean isSend = threadPoolNotifyAlarm.getIsAlarm()
&& divide > threadPoolNotifyAlarm.getCapacityAlarm(); && divide > threadPoolNotifyAlarm.getCapacityAlarm();

@ -24,9 +24,6 @@ import java.util.concurrent.ConcurrentHashMap;
/** /**
* Global notify alarm manage. * Global notify alarm manage.
*
* @author chen.ma
* @date 2022/2/24 20:12
*/ */
public class GlobalNotifyAlarmManage { public class GlobalNotifyAlarmManage {

@ -29,9 +29,6 @@ import java.util.concurrent.ThreadPoolExecutor;
/** /**
* Global thread-pool manage. * Global thread-pool manage.
*
* @author chen.ma
* @date 2021/6/20 15:57
*/ */
public class GlobalThreadPoolManage { public class GlobalThreadPoolManage {

@ -31,9 +31,6 @@ import java.util.concurrent.ThreadPoolExecutor;
/** /**
* Abstract threadPool runtime info. * Abstract threadPool runtime info.
*
* @author chen.ma
* @date 2021/12/7 19:44
*/ */
public abstract class AbstractThreadPoolRuntime { public abstract class AbstractThreadPoolRuntime {

@ -38,9 +38,6 @@ import static cn.hippo4j.core.toolkit.IdentifyUtil.CLIENT_IDENTIFICATION_VALUE;
/** /**
* Thread pool run state service. * Thread pool run state service.
*
* @author chen.ma
* @date 2021/7/12 21:25
*/ */
@Slf4j @Slf4j
@AllArgsConstructor @AllArgsConstructor

@ -27,9 +27,6 @@ import java.util.concurrent.atomic.AtomicInteger;
/** /**
* ThreadPool status handler. * ThreadPool status handler.
*
* @author chen.ma
* @date 2022/1/18 20:54
*/ */
@Slf4j @Slf4j
public class ThreadPoolStatusHandler { public class ThreadPoolStatusHandler {

@ -25,22 +25,15 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.core.task.TaskDecorator; import org.springframework.core.task.TaskDecorator;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.util.concurrent.locks.AbstractQueuedSynchronizer;
/** /**
* Abstract build threadPool template. * Abstract build threadPool template.
*
* @author chen.ma
* @date 2021/7/5 21:45
*/ */
@Slf4j @Slf4j
public class AbstractBuildThreadPoolTemplate { public class AbstractBuildThreadPoolTemplate {
/** /**
* 线. * Thread pool construction initialization parameters.
* <p>
* , , abstract.
* {@link AbstractQueuedSynchronizer#tryAcquire}
* *
* @return * @return
*/ */
@ -48,11 +41,6 @@ public class AbstractBuildThreadPoolTemplate {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
/**
* 线.
*
* @return
*/
public static ThreadPoolExecutor buildPool() { public static ThreadPoolExecutor buildPool() {
ThreadPoolInitParam initParam = initParam(); ThreadPoolInitParam initParam = initParam();
return buildPool(initParam); return buildPool(initParam);

@ -25,9 +25,6 @@ import java.util.concurrent.*;
/** /**
* Dynamic executor configuration support. * Dynamic executor configuration support.
*
* @author chen.ma
* @date 2021/11/28 12:17
*/ */
@Slf4j @Slf4j
public abstract class AbstractDynamicExecutorSupport extends ThreadPoolExecutor implements InitializingBean, DisposableBean { public abstract class AbstractDynamicExecutorSupport extends ThreadPoolExecutor implements InitializingBean, DisposableBean {

@ -22,21 +22,18 @@ import cn.hippo4j.core.executor.DynamicThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
* Common dynamic threadPool. * Common dynamic thread-pool.
*
* @author chen.ma
* @date 2021/6/16 22:35
*/ */
public class CommonDynamicThreadPool { public class CommonDynamicThreadPool {
public static DynamicThreadPoolExecutor getInstance(String threadPoolId) { public static DynamicThreadPoolExecutor getInstance(String threadPoolId) {
DynamicThreadPoolExecutor poolExecutor = (DynamicThreadPoolExecutor) ThreadPoolBuilder.builder() DynamicThreadPoolExecutor dynamicThreadPoolExecutor = (DynamicThreadPoolExecutor) ThreadPoolBuilder.builder()
.dynamicPool() .dynamicPool()
.threadFactory(threadPoolId) .threadFactory(threadPoolId)
.poolThreadSize(2, 4) .poolThreadSize(2, 4)
.keepAliveTime(60L, TimeUnit.SECONDS) .keepAliveTime(60L, TimeUnit.SECONDS)
.workQueue(QueueTypeEnum.RESIZABLE_LINKED_BLOCKING_QUEUE, 1024) .workQueue(QueueTypeEnum.RESIZABLE_LINKED_BLOCKING_QUEUE, 1024)
.build(); .build();
return poolExecutor; return dynamicThreadPoolExecutor;
} }
} }

@ -26,10 +26,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
/** /**
* Fast threadPool executor. * Fast thread-pool executor.
*
* @author chen.ma
* @date 2021/7/5 21:00
*/ */
@Slf4j @Slf4j
public class FastThreadPoolExecutor extends ThreadPoolExecutorTemplate { public class FastThreadPoolExecutor extends ThreadPoolExecutorTemplate {
@ -76,5 +73,4 @@ public class FastThreadPoolExecutor extends ThreadPoolExecutorTemplate {
throw t; throw t;
} }
} }
} }

@ -29,9 +29,6 @@ import java.util.stream.Stream;
/** /**
* Queue type enum. * Queue type enum.
*
* @author chen.ma
* @date 2021/6/25 12:30
*/ */
public enum QueueTypeEnum { public enum QueueTypeEnum {

@ -25,9 +25,6 @@ import java.util.concurrent.ThreadPoolExecutor;
/** /**
* Rejected policies. * Rejected policies.
*
* @author chen.ma
* @date 2021/7/5 21:23
*/ */
@Slf4j @Slf4j
public class RejectedPolicies { public class RejectedPolicies {

@ -29,9 +29,6 @@ import java.util.stream.Stream;
/** /**
* Reject policy type Enum. * Reject policy type Enum.
*
* @author chen.ma
* @date 2021/7/10 23:16
*/ */
public enum RejectedTypeEnum { public enum RejectedTypeEnum {

@ -24,10 +24,7 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
/** /**
* Resizable capacity linked-blocking-queue. * Resizable capacity linked-blocking-queue. Options Rabbitmq VariableLinkedBlockingQueue
*
* @author chen.ma
* @date 2021/6/20 14:24
*/ */
@Slf4j @Slf4j
public class ResizableCapacityLinkedBlockingQueue<E> extends LinkedBlockingQueue<E> { public class ResizableCapacityLinkedBlockingQueue<E> extends LinkedBlockingQueue<E> {
@ -38,9 +35,6 @@ public class ResizableCapacityLinkedBlockingQueue<E> extends LinkedBlockingQueue
public synchronized boolean setCapacity(Integer capacity) { public synchronized boolean setCapacity(Integer capacity) {
boolean successFlag = true; boolean successFlag = true;
/**
* TODO Rabbitmq VariableLinkedBlockingQueue
*/
try { try {
int oldCapacity = (int) ReflectUtil.getFieldValue(this, "capacity"); int oldCapacity = (int) ReflectUtil.getFieldValue(this, "capacity");
AtomicInteger count = (AtomicInteger) ReflectUtil.getFieldValue(this, "count"); AtomicInteger count = (AtomicInteger) ReflectUtil.getFieldValue(this, "count");
@ -54,7 +48,6 @@ public class ResizableCapacityLinkedBlockingQueue<E> extends LinkedBlockingQueue
log.error("Dynamic modification of blocking queue size failed.", ex); log.error("Dynamic modification of blocking queue size failed.", ex);
successFlag = false; successFlag = false;
} }
return successFlag; return successFlag;
} }

@ -23,9 +23,6 @@ import java.util.concurrent.TimeUnit;
/** /**
* Task queue. * Task queue.
*
* @author chen.ma
* @date 2021/7/5 21:00
*/ */
public class TaskQueue<R extends Runnable> extends LinkedBlockingQueue<Runnable> { public class TaskQueue<R extends Runnable> extends LinkedBlockingQueue<Runnable> {
@ -44,17 +41,18 @@ public class TaskQueue<R extends Runnable> extends LinkedBlockingQueue<Runnable>
@Override @Override
public boolean offer(Runnable runnable) { public boolean offer(Runnable runnable) {
int currentPoolThreadSize = executor.getPoolSize(); int currentPoolThreadSize = executor.getPoolSize();
// 如果有核心线程正在空闲, 将任务加入阻塞队列, 由核心线程进行处理任务 // If a core thread is idle, add the task to the blocking queue, and the core thread will process the task.
if (executor.getSubmittedTaskCount() < currentPoolThreadSize) { if (executor.getSubmittedTaskCount() < currentPoolThreadSize) {
return super.offer(runnable); return super.offer(runnable);
} }
// 当前线程池线程数量小于最大线程数, 返回false, 根据线程池源码, 会创建非核心线程 // The current number of threads in the thread pool is less than the maximum number of threads, and returns false.
// According to the thread pool source code, non-core threads will be created.
if (currentPoolThreadSize < executor.getMaximumPoolSize()) { if (currentPoolThreadSize < executor.getMaximumPoolSize()) {
return false; return false;
} }
// 如果当前线程池数量大于最大线程数, 任务加入阻塞队列 // If the current thread pool number is greater than the maximum number of threads, the task is added to the blocking queue.
return super.offer(runnable); return super.offer(runnable);
} }
@ -64,5 +62,4 @@ public class TaskQueue<R extends Runnable> extends LinkedBlockingQueue<Runnable>
} }
return super.offer(o, timeout, unit); return super.offer(o, timeout, unit);
} }
} }

@ -25,9 +25,6 @@ import java.util.concurrent.atomic.AtomicLong;
/** /**
* Thread-factory builder. * Thread-factory builder.
*
* @author chen.ma
* @date 2021/7/5 21:53
*/ */
public class ThreadFactoryBuilder implements Builder<ThreadFactory> { public class ThreadFactoryBuilder implements Builder<ThreadFactory> {

@ -27,9 +27,6 @@ import java.util.concurrent.*;
/** /**
* Thread-pool builder. * Thread-pool builder.
*
* @author chen.ma
* @date 2021/6/28 17:29
*/ */
public class ThreadPoolBuilder implements Builder<ThreadPoolExecutor> { public class ThreadPoolBuilder implements Builder<ThreadPoolExecutor> {

@ -23,9 +23,6 @@ import java.util.concurrent.*;
/** /**
* ThreadPool executor template. * ThreadPool executor template.
*
* @author chen.ma
* @date 2021/7/5 21:59
*/ */
public class ThreadPoolExecutorTemplate extends ThreadPoolExecutor { public class ThreadPoolExecutorTemplate extends ThreadPoolExecutor {

@ -18,7 +18,6 @@
package cn.hippo4j.core.handler; package cn.hippo4j.core.handler;
import cn.hippo4j.core.config.BootstrapPropertiesInterface; import cn.hippo4j.core.config.BootstrapPropertiesInterface;
import lombok.NonNull;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
@ -28,9 +27,6 @@ import org.springframework.boot.ansi.AnsiStyle;
/** /**
* Dynamic thread-pool print banner. * Dynamic thread-pool print banner.
*
* @author chen.ma
* @date 2021/6/20 16:34
*/ */
@Slf4j @Slf4j
@RequiredArgsConstructor @RequiredArgsConstructor

@ -28,9 +28,6 @@ import java.util.concurrent.atomic.AtomicLong;
/** /**
* Rejected proxy invocation handler. * Rejected proxy invocation handler.
*
* @author chen.ma
* @date 2022/2/17 19:45
*/ */
@AllArgsConstructor @AllArgsConstructor
public class RejectedProxyInvocationHandler implements InvocationHandler { public class RejectedProxyInvocationHandler implements InvocationHandler {

@ -23,9 +23,6 @@ import java.util.concurrent.atomic.AtomicLong;
/** /**
* Rejected proxy util. * Rejected proxy util.
*
* @author chen.ma
* @date 2022/2/22 21:56
*/ */
public class RejectedProxyUtil { public class RejectedProxyUtil {

@ -21,9 +21,6 @@ import java.util.concurrent.BlockingQueue;
/** /**
* Custom blocking-queue. * Custom blocking-queue.
*
* @author chen.ma
* @date 2021/7/11 00:51
*/ */
public interface CustomBlockingQueue { public interface CustomBlockingQueue {

@ -21,9 +21,6 @@ import java.util.concurrent.RejectedExecutionHandler;
/** /**
* Custom rejected execution handler. * Custom rejected execution handler.
*
* @author chen.ma
* @date 2021/7/10 23:51
*/ */
public interface CustomRejectedExecutionHandler { public interface CustomRejectedExecutionHandler {
@ -35,7 +32,7 @@ public interface CustomRejectedExecutionHandler {
Integer getType(); Integer getType();
/** /**
* Adapt hippo4j core rejected execution handler. * Adapt hippo-4j core rejected execution handler.
* *
* @return * @return
*/ */

@ -23,9 +23,6 @@ import java.util.stream.Collectors;
/** /**
* Dynamic thread-pool service loader. * Dynamic thread-pool service loader.
*
* @author chen.ma
* @date 2021/7/10 23:45
*/ */
public class DynamicThreadPoolServiceLoader { public class DynamicThreadPoolServiceLoader {

@ -19,9 +19,6 @@ package cn.hippo4j.core.spi;
/** /**
* Service loader instantiation exception. * Service loader instantiation exception.
*
* @author chen.ma
* @date 2021/7/10 23:48
*/ */
public class ServiceLoaderInstantiationException extends RuntimeException { public class ServiceLoaderInstantiationException extends RuntimeException {

@ -18,12 +18,12 @@
package cn.hippo4j.core.toolkit; package cn.hippo4j.core.toolkit;
import cn.hippo4j.common.config.ApplicationContextHolder; import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.common.toolkit.ThreadUtil;
import cn.hippo4j.core.toolkit.inet.InetUtils; import cn.hippo4j.core.toolkit.inet.InetUtils;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import lombok.SneakyThrows;
import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.ConfigurableEnvironment;
import java.util.ArrayList; import java.util.ArrayList;
@ -33,9 +33,6 @@ import static cn.hippo4j.common.constant.Constants.IDENTIFY_SLICER_SYMBOL;
/** /**
* Identify util. * Identify util.
*
* @author chen.ma
* @date 2021/12/5 22:25
*/ */
public class IdentifyUtil { public class IdentifyUtil {
@ -70,7 +67,6 @@ public class IdentifyUtil {
* *
* @return * @return
*/ */
@SneakyThrows
public static String getIdentify() { public static String getIdentify() {
while (StrUtil.isBlank(IDENTIFY)) { while (StrUtil.isBlank(IDENTIFY)) {
ConfigurableEnvironment environment = ApplicationContextHolder.getBean(ConfigurableEnvironment.class); ConfigurableEnvironment environment = ApplicationContextHolder.getBean(ConfigurableEnvironment.class);
@ -79,7 +75,7 @@ public class IdentifyUtil {
String identify = generate(environment, inetUtils); String identify = generate(environment, inetUtils);
return identify; return identify;
} }
Thread.sleep(500); ThreadUtil.sleep(500);
} }
return IDENTIFY; return IDENTIFY;
} }
@ -93,8 +89,7 @@ public class IdentifyUtil {
* @return * @return
*/ */
public static String getThreadPoolIdentify(String threadPoolId, String itemId, String namespace) { public static String getThreadPoolIdentify(String threadPoolId, String itemId, String namespace) {
ArrayList<String> params = Lists.newArrayList( ArrayList<String> params = Lists.newArrayList(threadPoolId, itemId, namespace, getIdentify());
threadPoolId, itemId, namespace, getIdentify());
return Joiner.on(GROUP_KEY_DELIMITER).join(params); return Joiner.on(GROUP_KEY_DELIMITER).join(params);
} }
} }

@ -22,9 +22,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
/** /**
* @author : wh * System clock.
* @date : 2022/4/25 17:03
* @description:
*/ */
public class SystemClock { public class SystemClock {
@ -50,8 +48,8 @@ public class SystemClock {
} }
private void scheduleClockUpdating() { private void scheduleClockUpdating() {
ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(1, r -> { ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(1, runnable -> {
Thread thread = new Thread(r, THREAD_NAME); Thread thread = new Thread(runnable, THREAD_NAME);
thread.setDaemon(true); thread.setDaemon(true);
return thread; return thread;
}); });

@ -23,9 +23,6 @@ import static cn.hippo4j.common.constant.Constants.EXECUTE_TIMEOUT_TRACE;
/** /**
* Trace context util. * Trace context util.
*
* @author chen.ma
* @date 2022/3/3 08:30
*/ */
public class TraceContextUtil { public class TraceContextUtil {

@ -57,8 +57,6 @@ public class DynamicThreadPoolAnnotationUtil {
.map(definition -> definition.getResolvedFactoryMethod()) .map(definition -> definition.getResolvedFactoryMethod())
.map(factoryMethod -> AnnotationUtils.getAnnotation(factoryMethod, annotationType)) .map(factoryMethod -> AnnotationUtils.getAnnotation(factoryMethod, annotationType))
.orElse(null); .orElse(null);
return annotation; return annotation;
} }
} }

@ -36,9 +36,6 @@ import java.util.concurrent.TimeUnit;
/** /**
* Inet utils. * Inet utils.
*
* @author Spencer Gibb
* @date 2021/11/12 21:33
*/ */
public class InetUtils implements Closeable { public class InetUtils implements Closeable {
@ -86,7 +83,6 @@ public class InetUtils implements Closeable {
} else if (result != null) { } else if (result != null) {
continue; continue;
} }
// @formatter:off // @formatter:off
if (!ignoreInterface(ifc.getDisplayName())) { if (!ignoreInterface(ifc.getDisplayName())) {
for (Enumeration<InetAddress> addrs = ifc for (Enumeration<InetAddress> addrs = ifc
@ -107,22 +103,18 @@ public class InetUtils implements Closeable {
} catch (IOException ex) { } catch (IOException ex) {
this.log.error("Cannot get first non-loopback address", ex); this.log.error("Cannot get first non-loopback address", ex);
} }
if (result != null) { if (result != null) {
return result; return result;
} }
try { try {
return InetAddress.getLocalHost(); return InetAddress.getLocalHost();
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
this.log.warn("Unable to retrieve localhost"); this.log.warn("Unable to retrieve localhost");
} }
return null; return null;
} }
boolean isPreferredAddress(InetAddress address) { boolean isPreferredAddress(InetAddress address) {
if (this.properties.isUseOnlySiteLocalInterfaces()) { if (this.properties.isUseOnlySiteLocalInterfaces()) {
final boolean siteLocalAddress = address.isSiteLocalAddress(); final boolean siteLocalAddress = address.isSiteLocalAddress();
if (!siteLocalAddress) { if (!siteLocalAddress) {

@ -26,9 +26,6 @@ import java.util.List;
/** /**
* Inet utils properties. * Inet utils properties.
*
* @author chen.ma
* @date 2021/11/12 21:34
*/ */
@ConfigurationProperties(InetUtilsProperties.PREFIX) @ConfigurationProperties(InetUtilsProperties.PREFIX)
public class InetUtilsProperties { public class InetUtilsProperties {

Loading…
Cancel
Save