From 3501e5fd55f9ad671a41cd62b284533bb144eb16 Mon Sep 17 00:00:00 2001 From: "chen.ma" Date: Sun, 11 Jul 2021 01:14:34 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E6=8B=92?= =?UTF-8?q?=E7=BB=9D=E7=AD=96=E7=95=A5=20SPI=20=E6=8E=A5=E5=8F=A3.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CustomRejectedExecutionHandler.java | 23 +++++++------------ .../toolkit/thread/RejectedTypeEnum.java | 3 +-- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/spi/rejected/CustomRejectedExecutionHandler.java b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/spi/rejected/CustomRejectedExecutionHandler.java index 05840b64..7cb297fb 100644 --- a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/spi/rejected/CustomRejectedExecutionHandler.java +++ b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/spi/rejected/CustomRejectedExecutionHandler.java @@ -1,9 +1,5 @@ package io.dynamic.threadpool.starter.spi.rejected; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; - import java.util.concurrent.RejectedExecutionHandler; /** @@ -15,20 +11,17 @@ import java.util.concurrent.RejectedExecutionHandler; public interface CustomRejectedExecutionHandler { /** - * 生成拒绝策略 + * 获取类型 * * @return */ - RejectedExecutionHandlerWrap generateRejected(); - - @Getter - @Setter - @AllArgsConstructor - class RejectedExecutionHandlerWrap { + Integer getType(); - private Integer type; - - private RejectedExecutionHandler rejectedExecutionHandler; + /** + * 生成拒绝策略 + * + * @return + */ + RejectedExecutionHandler generateRejected(); - } } diff --git a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/toolkit/thread/RejectedTypeEnum.java b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/toolkit/thread/RejectedTypeEnum.java index 5764fa69..abec6258 100644 --- a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/toolkit/thread/RejectedTypeEnum.java +++ b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/toolkit/thread/RejectedTypeEnum.java @@ -72,9 +72,8 @@ public enum RejectedTypeEnum { Collection customRejectedExecutionHandlers = DynamicTpServiceLoader .getSingletonServiceInstances(CustomRejectedExecutionHandler.class); Optional customRejected = customRejectedExecutionHandlers.stream() - .map(each -> each.generateRejected()) .filter(each -> Objects.equals(type, each.getType())) - .map(each -> each.getRejectedExecutionHandler()) + .map(each -> each.generateRejected()) .findFirst(); return customRejected.orElse(ABORT_POLICY.rejectedHandler);