mirror of https://github.com/longtai-cn/hippo4j
Bruceyan/issue#1106 (#1125)
* Refactor the web adapter module to be compatible with Spring Boot 1.x versions. * fix: Prevent NPE exceptions from being thrown when certain parameters are not configured. * fix: Add some ERROR logs. * fix: Add some notes.pull/1127/head
parent
a3724dd093
commit
9f94d9d29a
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.adapter.web;
|
||||
|
||||
import cn.hippo4j.common.config.ApplicationContextHolder;
|
||||
import org.springframework.boot.web.context.WebServerApplicationContext;
|
||||
import org.springframework.boot.web.server.WebServer;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* Default WebThreadPoolService abstract class,
|
||||
* reuses common capabilities for web container operations.
|
||||
*/
|
||||
public abstract class DefaultAbstractWebThreadPoolService extends AbstractWebThreadPoolService {
|
||||
|
||||
public DefaultAbstractWebThreadPoolService(IWebThreadPoolHandlerSupport support) {
|
||||
super(support);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the internal abstract method of the web container thread pool,
|
||||
* to be implemented by subclasses.
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected Executor getWebThreadPoolInternal() {
|
||||
return getWebThreadPoolByServer(getWebServer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get port by server.
|
||||
* @return web port
|
||||
*/
|
||||
@Override
|
||||
public Integer getPort() {
|
||||
return getWebServer().getPort();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the thread pool object of the current web container based on the WebServer.
|
||||
* @param webServer current Web-Server.
|
||||
* @return Thread pool executor of the current web container.
|
||||
*/
|
||||
protected abstract Executor getWebThreadPoolByServer(WebServer webServer);
|
||||
|
||||
/**
|
||||
* Get current Web Server.
|
||||
* @return webServer current Web-Server.
|
||||
*/
|
||||
public WebServer getWebServer() {
|
||||
ApplicationContext applicationContext = ApplicationContextHolder.getInstance();
|
||||
return ((WebServerApplicationContext) applicationContext).getWebServer();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.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;
|
||||
import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* Support class for WebThreadPoolHandler, providing some common methods.
|
||||
*/
|
||||
public interface IWebThreadPoolHandlerSupport {
|
||||
|
||||
/**
|
||||
* Set the Executor to the current class
|
||||
* so that other methods in the class can function properly.
|
||||
* @param executor
|
||||
*/
|
||||
void setExecutor(Executor executor);
|
||||
|
||||
/**
|
||||
* Retrieve the simple information of the thread pool.
|
||||
* @return
|
||||
*/
|
||||
ThreadPoolBaseInfo simpleInfo();
|
||||
|
||||
/**
|
||||
* Retrieve the parameter of the thread pool.
|
||||
* @return
|
||||
*/
|
||||
ThreadPoolParameter getWebThreadPoolParameter();
|
||||
|
||||
/**
|
||||
* Retrieve the run state of the thread pool.
|
||||
* @return
|
||||
*/
|
||||
ThreadPoolRunStateInfo getWebRunStateInfo();
|
||||
|
||||
/**
|
||||
* Update thread pool parameters.
|
||||
* @param threadPoolParameterInfo New parameters
|
||||
*/
|
||||
void updateWebThreadPool(ThreadPoolParameterInfo threadPoolParameterInfo);
|
||||
|
||||
WebContainerEnum getWebContainerType();
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.adapter.web.jetty;
|
||||
|
||||
import cn.hippo4j.adapter.web.DefaultAbstractWebThreadPoolService;
|
||||
import cn.hippo4j.adapter.web.IWebThreadPoolHandlerSupport;
|
||||
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;
|
||||
import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
|
||||
import cn.hippo4j.common.toolkit.ReflectUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
||||
import org.springframework.boot.web.embedded.jetty.JettyWebServer;
|
||||
import org.springframework.boot.web.server.WebServer;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* Jetty web thread pool handler.
|
||||
*/
|
||||
@Slf4j
|
||||
public class DefaultJettyWebThreadPoolHandler extends DefaultAbstractWebThreadPoolService
|
||||
implements
|
||||
JettyWebThreadPoolHandlerAdapt {
|
||||
|
||||
public DefaultJettyWebThreadPoolHandler() {
|
||||
super(new JettyWebThreadPoolHandlerSupport());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the thread pool object of the current web container based on the WebServer.
|
||||
* @param webServer current Web-Server.
|
||||
* @return Thread pool executor of the current web container.
|
||||
*/
|
||||
@Override
|
||||
protected Executor getWebThreadPoolByServer(WebServer webServer) {
|
||||
JettyWebServer jettyWebServer = (JettyWebServer) webServer;
|
||||
return jettyWebServer.getServer().getThreadPool();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.adapter.web.jetty;
|
||||
|
||||
import cn.hippo4j.adapter.web.WebThreadPoolService;
|
||||
|
||||
/**
|
||||
* Adapt interface of Jetty web thread-pool handler.
|
||||
*/
|
||||
public interface JettyWebThreadPoolHandlerAdapt extends WebThreadPoolService {
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.adapter.web.tomcat;
|
||||
|
||||
import cn.hippo4j.adapter.web.DefaultAbstractWebThreadPoolService;
|
||||
import cn.hippo4j.adapter.web.IWebThreadPoolHandlerSupport;
|
||||
import cn.hippo4j.common.enums.WebContainerEnum;
|
||||
import cn.hippo4j.common.model.ThreadPoolBaseInfo;
|
||||
import cn.hippo4j.common.model.ThreadPoolParameter;
|
||||
import cn.hippo4j.common.model.ThreadPoolParameterInfo;
|
||||
import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
|
||||
import cn.hippo4j.core.executor.state.AbstractThreadPoolRuntime;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.web.embedded.tomcat.TomcatWebServer;
|
||||
import org.springframework.boot.web.server.WebServer;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* Tomcat web thread pool handler.
|
||||
*/
|
||||
@Slf4j
|
||||
public class DefaultTomcatWebThreadPoolHandler extends DefaultAbstractWebThreadPoolService
|
||||
implements
|
||||
TomcatWebThreadPoolHandlerAdapt {
|
||||
|
||||
private final AtomicBoolean cacheFlag = new AtomicBoolean(Boolean.FALSE);
|
||||
|
||||
private static String exceptionMessage;
|
||||
|
||||
public DefaultTomcatWebThreadPoolHandler(AbstractThreadPoolRuntime runtime) {
|
||||
super(new TomcatWebThreadPoolHandlerSupport(runtime));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the thread pool object of the current web container based on the WebServer.
|
||||
* @param webServer current Web-Server.
|
||||
* @return Thread pool executor of the current web container.
|
||||
*/
|
||||
@Override
|
||||
protected Executor getWebThreadPoolByServer(WebServer webServer) {
|
||||
if (cacheFlag.get()) {
|
||||
log.warn("Exception getting Tomcat thread pool. Exception message: {}", exceptionMessage);
|
||||
return null;
|
||||
}
|
||||
Executor tomcatExecutor = null;
|
||||
try {
|
||||
tomcatExecutor = ((TomcatWebServer) webServer).getTomcat().getConnector().getProtocolHandler().getExecutor();
|
||||
} catch (Exception ex) {
|
||||
cacheFlag.set(Boolean.TRUE);
|
||||
exceptionMessage = ex.getMessage();
|
||||
log.error("Failed to get Tomcat thread pool. Message: {}", exceptionMessage);
|
||||
}
|
||||
return tomcatExecutor;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.adapter.web.tomcat;
|
||||
|
||||
import cn.hippo4j.adapter.web.WebThreadPoolService;
|
||||
|
||||
/**
|
||||
* Adapt interface of Tomcat web thread-pool handler.
|
||||
*/
|
||||
public interface TomcatWebThreadPoolHandlerAdapt extends WebThreadPoolService {
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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.adapter.web.undertow;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import cn.hippo4j.adapter.web.DefaultAbstractWebThreadPoolService;
|
||||
import cn.hippo4j.adapter.web.IWebThreadPoolHandlerSupport;
|
||||
import cn.hippo4j.common.enums.WebContainerEnum;
|
||||
import cn.hippo4j.common.model.ThreadPoolBaseInfo;
|
||||
import cn.hippo4j.common.model.ThreadPoolParameter;
|
||||
import cn.hippo4j.common.model.ThreadPoolParameterInfo;
|
||||
import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
|
||||
import io.undertow.Undertow;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServer;
|
||||
import org.springframework.boot.web.server.WebServer;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* Undertow web thread pool handler.
|
||||
*/
|
||||
@Slf4j
|
||||
public class DefaultUndertowWebThreadPoolHandler extends DefaultAbstractWebThreadPoolService
|
||||
implements
|
||||
UndertowWebThreadPoolHandlerAdapt {
|
||||
|
||||
private static final String UNDERTOW_NAME = "undertow";
|
||||
|
||||
public DefaultUndertowWebThreadPoolHandler() {
|
||||
super(new UndertowWebThreadPoolHandlerSupport());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the thread pool object of the current web container based on the WebServer.
|
||||
* @param webServer current Web-Server.
|
||||
* @return Thread pool executor of the current web container.
|
||||
*/
|
||||
@Override
|
||||
protected Executor getWebThreadPoolByServer(WebServer webServer) {
|
||||
// There is no need to consider reflection performance because the fetch is a singleton.
|
||||
// Springboot 2-3 version, can directly through reflection to obtain the undertow property
|
||||
UndertowServletWebServer undertowServletWebServer = (UndertowServletWebServer) webServer;
|
||||
Field undertowField = ReflectionUtils.findField(UndertowServletWebServer.class, UNDERTOW_NAME);
|
||||
ReflectionUtils.makeAccessible(undertowField);
|
||||
|
||||
Undertow undertow = (Undertow) ReflectionUtils.getField(undertowField, undertowServletWebServer);
|
||||
return Objects.isNull(undertow) ? null : undertow.getWorker();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.adapter.web.undertow;
|
||||
|
||||
import cn.hippo4j.adapter.web.WebThreadPoolService;
|
||||
|
||||
/**
|
||||
* Adapt interface of Undertow web thread-pool handler.
|
||||
*/
|
||||
public interface UndertowWebThreadPoolHandlerAdapt extends WebThreadPoolService {
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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.config.springboot1x.starter.config;
|
||||
|
||||
import cn.hippo4j.adapter.web.*;
|
||||
import cn.hippo4j.adapter.web.WebThreadPoolRunStateHandler;
|
||||
import cn.hippo4j.config.springboot1x.starter.web.jetty.JettyWebThreadPoolHandler1x;
|
||||
import cn.hippo4j.config.springboot1x.starter.web.tomcat.TomcatWebThreadPoolHandler1x;
|
||||
import cn.hippo4j.config.springboot1x.starter.web.undertow.UndertowWebThreadPoolHandler1x;
|
||||
import cn.hippo4j.springboot.starter.adapter.web.WebThreadPoolHandlerConfiguration;
|
||||
import io.undertow.Undertow;
|
||||
import org.apache.catalina.Loader;
|
||||
import org.apache.catalina.Server;
|
||||
import org.apache.catalina.startup.Tomcat;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.xnio.SslClientAuthMode;
|
||||
|
||||
import javax.servlet.Servlet;
|
||||
|
||||
/**
|
||||
* Spring auto-configuration class for WebThreadPoolHandlers.
|
||||
*/
|
||||
@Configuration
|
||||
@AutoConfigureBefore(WebThreadPoolHandlerConfiguration.class)
|
||||
public class WebThreadPoolHandlerConfiguration1x {
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnClass({Servlet.class, Tomcat.class})
|
||||
@ConditionalOnMissingBean(value = WebThreadPoolService.class, search = SearchStrategy.CURRENT)
|
||||
static class EmbeddedTomcat {
|
||||
|
||||
/**
|
||||
* Nested configuration if Tomcat is being used.
|
||||
*/
|
||||
@Bean
|
||||
public WebThreadPoolService tomcatWebThreadPoolHandler(WebThreadPoolRunStateHandler webThreadPoolRunStateHandler) {
|
||||
return new TomcatWebThreadPoolHandler1x(webThreadPoolRunStateHandler);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Nested configuration if Jetty is being used.
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass({Servlet.class, Server.class, Loader.class, WebAppContext.class})
|
||||
@ConditionalOnMissingBean(value = WebThreadPoolService.class, search = SearchStrategy.CURRENT)
|
||||
static class EmbeddedJetty {
|
||||
|
||||
@Bean
|
||||
public WebThreadPoolService jettyWebThreadPoolHandler() {
|
||||
return new JettyWebThreadPoolHandler1x();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Nested configuration if Undertow is being used.
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass({Servlet.class, Undertow.class, SslClientAuthMode.class})
|
||||
@ConditionalOnMissingBean(value = WebThreadPoolService.class, search = SearchStrategy.CURRENT)
|
||||
static class EmbeddedUndertow {
|
||||
|
||||
@Bean
|
||||
public WebThreadPoolService undertowWebThreadPoolHandler() {
|
||||
return new UndertowWebThreadPoolHandler1x();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.config.springboot1x.starter.web;
|
||||
|
||||
import cn.hippo4j.adapter.web.AbstractWebThreadPoolService;
|
||||
import cn.hippo4j.adapter.web.IWebThreadPoolHandlerSupport;
|
||||
import cn.hippo4j.common.config.ApplicationContextHolder;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainer;
|
||||
import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext;
|
||||
|
||||
/**
|
||||
* Abstract class for adapting WebThreadPoolService to Spring 1.x version.
|
||||
*/
|
||||
public abstract class AbstractWebThreadPoolService1x extends AbstractWebThreadPoolService {
|
||||
|
||||
public AbstractWebThreadPoolService1x(IWebThreadPoolHandlerSupport support) {
|
||||
super(support);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the embedded Servlet container from the Spring application context.
|
||||
*/
|
||||
protected EmbeddedServletContainer getContainer() {
|
||||
return ((EmbeddedWebApplicationContext) ApplicationContextHolder.getInstance()).getEmbeddedServletContainer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the port from web container.
|
||||
*/
|
||||
@Override
|
||||
public Integer getPort() {
|
||||
return getContainer().getPort();
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.config.springboot1x.starter.web.jetty;
|
||||
|
||||
import cn.hippo4j.adapter.web.IWebThreadPoolHandlerSupport;
|
||||
import cn.hippo4j.adapter.web.jetty.JettyWebThreadPoolHandlerSupport;
|
||||
import cn.hippo4j.common.enums.WebContainerEnum;
|
||||
import cn.hippo4j.common.model.ThreadPoolBaseInfo;
|
||||
import cn.hippo4j.common.model.ThreadPoolParameter;
|
||||
import cn.hippo4j.common.model.ThreadPoolParameterInfo;
|
||||
import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
|
||||
import cn.hippo4j.common.web.exception.ServiceException;
|
||||
import cn.hippo4j.config.springboot1x.starter.web.AbstractWebThreadPoolService1x;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainer;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* WebThreadPoolHandler compatible with Jetty container for Spring 1.x version.
|
||||
*/
|
||||
@Slf4j
|
||||
public class JettyWebThreadPoolHandler1x extends AbstractWebThreadPoolService1x {
|
||||
|
||||
public JettyWebThreadPoolHandler1x() {
|
||||
super(new JettyWebThreadPoolHandlerSupport());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Executor getWebThreadPoolInternal() {
|
||||
try {
|
||||
return ((JettyEmbeddedServletContainer) getContainer()).getServer().getThreadPool();
|
||||
} catch (Throwable th) {
|
||||
log.error("Failed to get Jetty thread pool.", th);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.config.springboot1x.starter.web.tomcat;
|
||||
|
||||
import cn.hippo4j.adapter.web.IWebThreadPoolHandlerSupport;
|
||||
import cn.hippo4j.adapter.web.tomcat.TomcatWebThreadPoolHandlerSupport;
|
||||
import cn.hippo4j.common.enums.WebContainerEnum;
|
||||
import cn.hippo4j.common.model.ThreadPoolBaseInfo;
|
||||
import cn.hippo4j.common.model.ThreadPoolParameter;
|
||||
import cn.hippo4j.common.model.ThreadPoolParameterInfo;
|
||||
import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
|
||||
import cn.hippo4j.common.web.exception.ServiceException;
|
||||
import cn.hippo4j.config.springboot1x.starter.web.AbstractWebThreadPoolService1x;
|
||||
import cn.hippo4j.core.executor.state.AbstractThreadPoolRuntime;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* WebThreadPoolHandler compatible with Tomcat container for Spring 1.x version.
|
||||
*/
|
||||
@Slf4j
|
||||
public class TomcatWebThreadPoolHandler1x extends AbstractWebThreadPoolService1x {
|
||||
|
||||
public TomcatWebThreadPoolHandler1x(AbstractThreadPoolRuntime runtime) {
|
||||
super(new TomcatWebThreadPoolHandlerSupport(runtime));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Executor getWebThreadPoolInternal() {
|
||||
try {
|
||||
return ((TomcatEmbeddedServletContainer) getContainer())
|
||||
.getTomcat().getConnector().getProtocolHandler().getExecutor();
|
||||
} catch (Throwable th) {
|
||||
log.error("Failed to get Tomcat thread pool.", th);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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.config.springboot1x.starter.web.undertow;
|
||||
|
||||
import cn.hippo4j.adapter.web.IWebThreadPoolHandlerSupport;
|
||||
import cn.hippo4j.adapter.web.undertow.UndertowWebThreadPoolHandlerSupport;
|
||||
import cn.hippo4j.common.enums.WebContainerEnum;
|
||||
import cn.hippo4j.common.model.ThreadPoolBaseInfo;
|
||||
import cn.hippo4j.common.model.ThreadPoolParameter;
|
||||
import cn.hippo4j.common.model.ThreadPoolParameterInfo;
|
||||
import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
|
||||
import cn.hippo4j.common.web.exception.ServiceException;
|
||||
import cn.hippo4j.config.springboot1x.starter.web.AbstractWebThreadPoolService1x;
|
||||
import io.undertow.Undertow;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainer;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* WebThreadPoolHandler compatible with Undertow container for Spring 1.x version.
|
||||
*/
|
||||
@Slf4j
|
||||
public class UndertowWebThreadPoolHandler1x extends AbstractWebThreadPoolService1x {
|
||||
|
||||
private static final String UNDERTOW_NAME = "undertow";
|
||||
|
||||
public UndertowWebThreadPoolHandler1x() {
|
||||
super(new UndertowWebThreadPoolHandlerSupport());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Executor getWebThreadPoolInternal() {
|
||||
try {
|
||||
UndertowEmbeddedServletContainer container = (UndertowEmbeddedServletContainer) getContainer();
|
||||
Field field = ReflectionUtils.findField(UndertowEmbeddedServletContainer.class, UNDERTOW_NAME);
|
||||
ReflectionUtils.makeAccessible(field);
|
||||
Undertow undertow = (Undertow) ReflectionUtils.getField(field, container);
|
||||
return undertow.getWorker();
|
||||
} catch (Throwable th) {
|
||||
log.error("Failed to get Undertow thread pool.", th);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1 +1,3 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.hippo4j.config.springboot1x.starter.config.ConfigHandlerAutoConfiguration
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
cn.hippo4j.config.springboot1x.starter.config.ConfigHandlerAutoConfiguration,\
|
||||
cn.hippo4j.config.springboot1x.starter.config.WebThreadPoolHandlerConfiguration1x
|
Loading…
Reference in new issue