fix: Add some notes.

pull/1125/head
yanrongzhen 3 years ago
parent 6f4b2ceca6
commit 19a6a1f9f3

@ -24,30 +24,46 @@ 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 web thread pool by server
*
* @param webServer
* @return
* 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();

@ -25,16 +25,40 @@ 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();

@ -46,6 +46,11 @@ public class DefaultJettyWebThreadPoolHandler extends DefaultAbstractWebThreadPo
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;

@ -48,6 +48,11 @@ public class DefaultTomcatWebThreadPoolHandler extends DefaultAbstractWebThreadP
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()) {

@ -49,6 +49,11 @@ public class DefaultUndertowWebThreadPoolHandler extends DefaultAbstractWebThrea
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.

@ -32,10 +32,16 @@ public abstract class AbstractWebThreadPoolService1x extends AbstractWebThreadPo
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();

Loading…
Cancel
Save