refactor: modify web-container thread-pool executor configuration pattern with general mode. (#1015) (#1084)

pull/1087/head
yanrongzhen 1 year ago committed by GitHub
parent 39bb1a09a7
commit 4cceb1aa4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -18,6 +18,7 @@
package cn.hippo4j.adapter.web;
import cn.hippo4j.common.constant.ChangeThreadPoolConstants;
import cn.hippo4j.common.enums.WebContainerEnum;
import cn.hippo4j.common.model.ThreadPoolBaseInfo;
import cn.hippo4j.common.model.ThreadPoolParameter;
import cn.hippo4j.common.model.ThreadPoolParameterInfo;
@ -96,4 +97,9 @@ public class JettyWebThreadPoolHandler extends AbstractWebThreadPoolService {
log.error("Failed to modify the jetty thread pool parameter.", ex);
}
}
@Override
public WebContainerEnum getWebContainerType() {
return WebContainerEnum.JETTY;
}
}

@ -18,6 +18,7 @@
package cn.hippo4j.adapter.web;
import cn.hippo4j.common.constant.ChangeThreadPoolConstants;
import cn.hippo4j.common.enums.WebContainerEnum;
import cn.hippo4j.common.model.ThreadPoolBaseInfo;
import cn.hippo4j.common.model.ThreadPoolParameter;
import cn.hippo4j.common.model.ThreadPoolParameterInfo;
@ -164,4 +165,9 @@ public class TomcatWebThreadPoolHandler extends AbstractWebThreadPoolService {
log.error("Failed to modify the Tomcat thread pool parameter.", ex);
}
}
@Override
public WebContainerEnum getWebContainerType() {
return WebContainerEnum.TOMCAT;
}
}

@ -25,6 +25,7 @@ import java.util.Objects;
import java.util.concurrent.Executor;
import cn.hippo4j.common.constant.ChangeThreadPoolConstants;
import cn.hippo4j.common.enums.WebContainerEnum;
import cn.hippo4j.common.model.ThreadPoolBaseInfo;
import cn.hippo4j.common.model.ThreadPoolParameter;
import cn.hippo4j.common.model.ThreadPoolParameterInfo;
@ -155,4 +156,9 @@ public class UndertowWebThreadPoolHandler extends AbstractWebThreadPoolService {
log.error("Failed to modify the undertow thread pool parameter.", ex);
}
}
@Override
public WebContainerEnum getWebContainerType() {
return WebContainerEnum.UNDERTOW;
}
}

@ -17,6 +17,7 @@
package cn.hippo4j.adapter.web;
import cn.hippo4j.common.enums.WebContainerEnum;
import cn.hippo4j.common.model.ThreadPoolBaseInfo;
import cn.hippo4j.common.model.ThreadPoolParameter;
import cn.hippo4j.common.model.ThreadPoolParameterInfo;
@ -73,4 +74,11 @@ public interface WebThreadPoolService {
default WebServer getWebServer() {
return null;
}
/**
* resolve current web container type.
*
* <p>e.g: tomcat, jetty, undertow, etc.</p>
*/
WebContainerEnum getWebContainerType();
}

@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.hippo4j.common.enums;
public enum WebContainerEnum {
TOMCAT,
JETTY,
UNDERTOW
}

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.hippo4j.common.spi;
import cn.hippo4j.common.executor.support.CustomBlockingQueue;

@ -101,20 +101,9 @@ public class BootstrapConfigProperties implements BootstrapPropertiesInterface {
private Map<String, String> etcd;
/**
* Tomcat thread pool config.
* web config
*/
private WebThreadPoolProperties tomcat;
/**
* Undertow thread pool config.
*/
private WebThreadPoolProperties undertow;
/**
* Jetty thread pool config.
* KeepAliveTime is not supported temporarily.
*/
private WebThreadPoolProperties jetty;
private WebThreadPoolProperties web;
/**
* Notify platforms.

@ -46,10 +46,7 @@ public class WebExecutorRefreshListener extends AbstractRefreshListener<WebThrea
@Override
public void onApplicationEvent(Hippo4jConfigDynamicRefreshEvent threadPoolDynamicRefreshEvent) {
BootstrapConfigProperties bindableCoreProperties = threadPoolDynamicRefreshEvent.getBootstrapConfigProperties();
boolean isNullFlag = bindableCoreProperties.getJetty() == null
&& bindableCoreProperties.getUndertow() == null
&& bindableCoreProperties.getTomcat() == null;
if (isNullFlag) {
if (bindableCoreProperties.getWeb() == null) {
return;
}
try {
@ -71,14 +68,8 @@ public class WebExecutorRefreshListener extends AbstractRefreshListener<WebThrea
private ThreadPoolParameterInfo buildWebPoolParameter(BootstrapConfigProperties bindableCoreProperties) {
ThreadPoolParameterInfo threadPoolParameterInfo = null;
WebThreadPoolProperties webThreadPoolProperties = null;
if (bindableCoreProperties.getTomcat() != null) {
webThreadPoolProperties = bindableCoreProperties.getTomcat();
} else if (bindableCoreProperties.getUndertow() != null) {
webThreadPoolProperties = bindableCoreProperties.getUndertow();
} else if (bindableCoreProperties.getJetty() != null) {
webThreadPoolProperties = bindableCoreProperties.getJetty();
}
WebThreadPoolProperties webThreadPoolProperties = bindableCoreProperties.getWeb();
if (webThreadPoolProperties != null && webThreadPoolProperties.getEnable() && match(webThreadPoolProperties)) {
threadPoolParameterInfo = ThreadPoolParameterInfo.builder()
.coreSize(webThreadPoolProperties.getCorePoolSize())

Loading…
Cancel
Save