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>
<groupId>com.aliyun</groupId>
<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>
<exclusion>
<groupId>log4j</groupId>

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -23,9 +23,6 @@ import java.util.concurrent.TimeUnit;
/**
* Task queue.
*
* @author chen.ma
* @date 2021/7/5 21:00
*/
public class TaskQueue<R extends Runnable> extends LinkedBlockingQueue<Runnable> {
@ -44,17 +41,18 @@ public class TaskQueue<R extends Runnable> extends LinkedBlockingQueue<Runnable>
@Override
public boolean offer(Runnable runnable) {
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) {
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()) {
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);
}
@ -64,5 +62,4 @@ public class TaskQueue<R extends Runnable> extends LinkedBlockingQueue<Runnable>
}
return super.offer(o, timeout, unit);
}
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save