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; package io.dynamic.threadpool.starter.spi.rejected;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import java.util.concurrent.RejectedExecutionHandler; import java.util.concurrent.RejectedExecutionHandler;
/** /**
@ -15,20 +11,17 @@ import java.util.concurrent.RejectedExecutionHandler;
public interface CustomRejectedExecutionHandler { public interface CustomRejectedExecutionHandler {
/** /**
* *
* *
* @return * @return
*/ */
RejectedExecutionHandlerWrap generateRejected(); Integer getType();
@Getter
@Setter
@AllArgsConstructor
class RejectedExecutionHandlerWrap {
private Integer type; /**
*
private RejectedExecutionHandler rejectedExecutionHandler; *
* @return
*/
RejectedExecutionHandler generateRejected();
}
} }

@ -72,9 +72,8 @@ public enum RejectedTypeEnum {
Collection<CustomRejectedExecutionHandler> customRejectedExecutionHandlers = DynamicTpServiceLoader Collection<CustomRejectedExecutionHandler> customRejectedExecutionHandlers = DynamicTpServiceLoader
.getSingletonServiceInstances(CustomRejectedExecutionHandler.class); .getSingletonServiceInstances(CustomRejectedExecutionHandler.class);
Optional<RejectedExecutionHandler> customRejected = customRejectedExecutionHandlers.stream() Optional<RejectedExecutionHandler> customRejected = customRejectedExecutionHandlers.stream()
.map(each -> each.generateRejected())
.filter(each -> Objects.equals(type, each.getType())) .filter(each -> Objects.equals(type, each.getType()))
.map(each -> each.getRejectedExecutionHandler()) .map(each -> each.generateRejected())
.findFirst(); .findFirst();
return customRejected.orElse(ABORT_POLICY.rejectedHandler); return customRejected.orElse(ABORT_POLICY.rejectedHandler);

Loading…
Cancel
Save