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; import java.util.concurrent.Executor;
/**
* Default WebThreadPoolService abstract class,
* reuses common capabilities for web container operations.
*/
public abstract class DefaultAbstractWebThreadPoolService extends AbstractWebThreadPoolService { public abstract class DefaultAbstractWebThreadPoolService extends AbstractWebThreadPoolService {
public DefaultAbstractWebThreadPoolService(IWebThreadPoolHandlerSupport support) { public DefaultAbstractWebThreadPoolService(IWebThreadPoolHandlerSupport support) {
super(support); super(support);
} }
/**
* Get the internal abstract method of the web container thread pool,
* to be implemented by subclasses.
* @return
*/
@Override @Override
protected Executor getWebThreadPoolInternal() { protected Executor getWebThreadPoolInternal() {
return getWebThreadPoolByServer(getWebServer()); return getWebThreadPoolByServer(getWebServer());
} }
/**
* Get port by server.
* @return web port
*/
@Override @Override
public Integer getPort() { public Integer getPort() {
return getWebServer().getPort(); return getWebServer().getPort();
} }
/** /**
* Get web thread pool by server * Get the thread pool object of the current web container based on the WebServer.
* * @param webServer current Web-Server.
* @param webServer * @return Thread pool executor of the current web container.
* @return
*/ */
protected abstract Executor getWebThreadPoolByServer(WebServer webServer); protected abstract Executor getWebThreadPoolByServer(WebServer webServer);
/**
* Get current Web Server.
* @return webServer current Web-Server.
*/
public WebServer getWebServer() { public WebServer getWebServer() {
ApplicationContext applicationContext = ApplicationContextHolder.getInstance(); ApplicationContext applicationContext = ApplicationContextHolder.getInstance();
return ((WebServerApplicationContext) applicationContext).getWebServer(); return ((WebServerApplicationContext) applicationContext).getWebServer();

@ -25,16 +25,40 @@ import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
/**
* Support class for WebThreadPoolHandler, providing some common methods.
*/
public interface IWebThreadPoolHandlerSupport { 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); void setExecutor(Executor executor);
/**
* Retrieve the simple information of the thread pool.
* @return
*/
ThreadPoolBaseInfo simpleInfo(); ThreadPoolBaseInfo simpleInfo();
/**
* Retrieve the parameter of the thread pool.
* @return
*/
ThreadPoolParameter getWebThreadPoolParameter(); ThreadPoolParameter getWebThreadPoolParameter();
/**
* Retrieve the run state of the thread pool.
* @return
*/
ThreadPoolRunStateInfo getWebRunStateInfo(); ThreadPoolRunStateInfo getWebRunStateInfo();
/**
* Update thread pool parameters.
* @param threadPoolParameterInfo New parameters
*/
void updateWebThreadPool(ThreadPoolParameterInfo threadPoolParameterInfo); void updateWebThreadPool(ThreadPoolParameterInfo threadPoolParameterInfo);
WebContainerEnum getWebContainerType(); WebContainerEnum getWebContainerType();

@ -46,6 +46,11 @@ public class DefaultJettyWebThreadPoolHandler extends DefaultAbstractWebThreadPo
super(new JettyWebThreadPoolHandlerSupport()); 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 @Override
protected Executor getWebThreadPoolByServer(WebServer webServer) { protected Executor getWebThreadPoolByServer(WebServer webServer) {
JettyWebServer jettyWebServer = (JettyWebServer) webServer; JettyWebServer jettyWebServer = (JettyWebServer) webServer;

@ -48,6 +48,11 @@ public class DefaultTomcatWebThreadPoolHandler extends DefaultAbstractWebThreadP
super(new TomcatWebThreadPoolHandlerSupport(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 @Override
protected Executor getWebThreadPoolByServer(WebServer webServer) { protected Executor getWebThreadPoolByServer(WebServer webServer) {
if (cacheFlag.get()) { if (cacheFlag.get()) {

@ -49,6 +49,11 @@ public class DefaultUndertowWebThreadPoolHandler extends DefaultAbstractWebThrea
super(new UndertowWebThreadPoolHandlerSupport()); 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 @Override
protected Executor getWebThreadPoolByServer(WebServer webServer) { protected Executor getWebThreadPoolByServer(WebServer webServer) {
// There is no need to consider reflection performance because the fetch is a singleton. // 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); super(support);
} }
/**
* Get the embedded Servlet container from the Spring application context.
*/
protected EmbeddedServletContainer getContainer() { protected EmbeddedServletContainer getContainer() {
return ((EmbeddedWebApplicationContext) ApplicationContextHolder.getInstance()).getEmbeddedServletContainer(); return ((EmbeddedWebApplicationContext) ApplicationContextHolder.getInstance()).getEmbeddedServletContainer();
} }
/**
* Get the port from web container.
*/
@Override @Override
public Integer getPort() { public Integer getPort() {
return getContainer().getPort(); return getContainer().getPort();

Loading…
Cancel
Save