refactor: 重构拒绝策略 SPI 接口.

pull/161/head
chen.ma 3 years ago
parent 56e57c39a2
commit 3501e5fd55

@ -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();
}
}

@ -72,9 +72,8 @@ public enum RejectedTypeEnum {
Collection<CustomRejectedExecutionHandler> customRejectedExecutionHandlers = DynamicTpServiceLoader
.getSingletonServiceInstances(CustomRejectedExecutionHandler.class);
Optional<RejectedExecutionHandler> 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);

Loading…
Cancel
Save