add queue and reject policy

pull/1464/head
furaul 2 years ago
parent 37630e3b42
commit 596d0915e3

@ -105,8 +105,8 @@ public class WebThreadPoolHandlerConfiguration {
* the Web embedded server loads the {@link ServletWebServerFactory} top-level interface type at the same time * the Web embedded server loads the {@link ServletWebServerFactory} top-level interface type at the same time
*/ */
@Bean @Bean
public UndertowWebThreadPoolHandlerAdapt undertowWebThreadPoolHandler() { public UndertowWebThreadPoolHandlerAdapt undertowWebThreadPoolHandler(WebThreadPoolRunStateHandler webThreadPoolRunStateHandler) {
return new DefaultUndertowWebThreadPoolHandler(); return new DefaultUndertowWebThreadPoolHandler(webThreadPoolRunStateHandler);
} }
} }
} }

@ -89,8 +89,8 @@ public class WebThreadPoolHandlerConfiguration1x {
static class EmbeddedUndertow { static class EmbeddedUndertow {
@Bean @Bean
public WebThreadPoolService undertowWebThreadPoolHandler() { public WebThreadPoolService undertowWebThreadPoolHandler(WebThreadPoolRunStateHandler webThreadPoolRunStateHandler) {
return new UndertowWebThreadPoolHandler1x(); return new UndertowWebThreadPoolHandler1x(webThreadPoolRunStateHandler);
} }
} }
} }

@ -19,6 +19,7 @@ package cn.hippo4j.config.springboot1x.starter.web.undertow;
import cn.hippo4j.adapter.web.undertow.UndertowWebThreadPoolHandlerSupport; import cn.hippo4j.adapter.web.undertow.UndertowWebThreadPoolHandlerSupport;
import cn.hippo4j.config.springboot1x.starter.web.AbstractWebThreadPoolService1x; import cn.hippo4j.config.springboot1x.starter.web.AbstractWebThreadPoolService1x;
import cn.hippo4j.core.executor.state.AbstractThreadPoolRuntime;
import io.undertow.Undertow; import io.undertow.Undertow;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainer; import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainer;
@ -35,8 +36,8 @@ public class UndertowWebThreadPoolHandler1x extends AbstractWebThreadPoolService
private static final String UNDERTOW_NAME = "undertow"; private static final String UNDERTOW_NAME = "undertow";
public UndertowWebThreadPoolHandler1x() { public UndertowWebThreadPoolHandler1x(AbstractThreadPoolRuntime runtime) {
super(new UndertowWebThreadPoolHandlerSupport()); super(new UndertowWebThreadPoolHandlerSupport(runtime));
} }
@Override @Override

@ -17,6 +17,7 @@
package cn.hippo4j.adapter.web.undertow; package cn.hippo4j.adapter.web.undertow;
import cn.hippo4j.core.executor.state.AbstractThreadPoolRuntime;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
@ -39,8 +40,8 @@ public class DefaultUndertowWebThreadPoolHandler extends DefaultAbstractWebThrea
private static final String UNDERTOW_NAME = "undertow"; private static final String UNDERTOW_NAME = "undertow";
public DefaultUndertowWebThreadPoolHandler() { public DefaultUndertowWebThreadPoolHandler(AbstractThreadPoolRuntime runtime) {
super(new UndertowWebThreadPoolHandlerSupport()); super(new UndertowWebThreadPoolHandlerSupport(runtime));
} }
/** /**

@ -25,8 +25,11 @@ import cn.hippo4j.common.model.ThreadPoolParameter;
import cn.hippo4j.common.model.ThreadPoolParameterInfo; import cn.hippo4j.common.model.ThreadPoolParameterInfo;
import cn.hippo4j.common.model.ThreadPoolRunStateInfo; import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
import cn.hippo4j.common.toolkit.CalculateUtil; import cn.hippo4j.common.toolkit.CalculateUtil;
import cn.hippo4j.common.toolkit.ReflectUtil;
import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; import cn.hippo4j.core.executor.DynamicThreadPoolExecutor;
import cn.hippo4j.core.executor.state.AbstractThreadPoolRuntime;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.jboss.threads.EnhancedQueueExecutor;
import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils;
import org.xnio.Options; import org.xnio.Options;
import org.xnio.XnioWorker; import org.xnio.XnioWorker;
@ -44,8 +47,14 @@ import java.util.concurrent.Executor;
@Slf4j @Slf4j
public class UndertowWebThreadPoolHandlerSupport implements IWebThreadPoolHandlerSupport { public class UndertowWebThreadPoolHandlerSupport implements IWebThreadPoolHandlerSupport {
private final AbstractThreadPoolRuntime runtime;
private Executor executor; private Executor executor;
public UndertowWebThreadPoolHandlerSupport(AbstractThreadPoolRuntime runtime) {
this.runtime = runtime;
}
/** /**
* A callback will be invoked and the Executor will be set up when the web container has been started. * A callback will be invoked and the Executor will be set up when the web container has been started.
* @param executor Thread-pool executor in Undertow container. * @param executor Thread-pool executor in Undertow container.
@ -67,8 +76,13 @@ public class UndertowWebThreadPoolHandlerSupport implements IWebThreadPoolHandle
poolBaseInfo.setCoreSize(coreSize); poolBaseInfo.setCoreSize(coreSize);
poolBaseInfo.setMaximumSize(maximumPoolSize); poolBaseInfo.setMaximumSize(maximumPoolSize);
poolBaseInfo.setKeepAliveTime((long) keepAliveTime); poolBaseInfo.setKeepAliveTime((long) keepAliveTime);
poolBaseInfo.setRejectedName("-"); poolBaseInfo.setRejectedName("RejectedExecutionException");
poolBaseInfo.setQueueType("-"); poolBaseInfo.setQueueType("org.jboss.threads.EnhancedQueueExecutor.TaskNode:FIFO");
EnhancedQueueExecutor enhancedQueueExecutor =
(EnhancedQueueExecutor) ReflectUtil.getFieldValue(
ReflectUtil.getFieldValue(xnioWorker, "taskPool"), "executor");
poolBaseInfo.setQueueCapacity(enhancedQueueExecutor.getQueueSize());
} catch (Exception ex) { } catch (Exception ex) {
log.error("The undertow container failed to get thread pool parameters.", ex); log.error("The undertow container failed to get thread pool parameters.", ex);
} }
@ -127,7 +141,7 @@ public class UndertowWebThreadPoolHandlerSupport implements IWebThreadPoolHandle
stateInfo.setRejectCount(rejectCount); stateInfo.setRejectCount(rejectCount);
stateInfo.setClientLastRefreshTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); stateInfo.setClientLastRefreshTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
stateInfo.setTimestamp(System.currentTimeMillis()); stateInfo.setTimestamp(System.currentTimeMillis());
return stateInfo; return runtime.supplement(stateInfo);
} }
@Override @Override

Loading…
Cancel
Save