Skip to content

Commit

Permalink
Revert the bugfix changes and split them into issue opengoofy#1134.
Browse files Browse the repository at this point in the history
  • Loading branch information
yanrongzhen committed Mar 21, 2023
1 parent 5a9a16d commit aee8f53
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,22 @@
package cn.hippo4j.adapter.web;

import cn.hippo4j.common.config.ApplicationContextHolder;
import io.undertow.Undertow;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.context.WebServerApplicationContext;
import org.springframework.boot.web.server.WebServer;
import org.springframework.context.ApplicationContext;
import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Field;
import java.util.concurrent.Executor;

/**
* Default WebThreadPoolService abstract class,
* reuses common capabilities for web container operations.
*/
@Slf4j
public abstract class DefaultAbstractWebThreadPoolService extends AbstractWebThreadPoolService {

public DefaultAbstractWebThreadPoolService(IWebThreadPoolHandlerSupport support) {
super(support);
}

private static final String STARTED_FIELD_NAME = "started";

/**
* Get the internal abstract method of the web container thread pool,
* to be implemented by subclasses.
Expand All @@ -60,19 +53,6 @@ public Integer getPort() {
return getWebServer().getPort();
}

@Override
public boolean isContainerStarted() {
try {
WebServer container = getWebServer();
Field field = ReflectionUtils.findField(WebServer.class, STARTED_FIELD_NAME);
ReflectionUtils.makeAccessible(field);
return (boolean) ReflectionUtils.getField(field, container);
} catch (Throwable th) {
log.error("Failed to get isStarted flag.", th);
return false;
}
}

/**
* Get the thread pool object of the current web container based on the WebServer.
* @param webServer current Web-Server.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@
*/
public interface WebThreadPoolService {

/**
* Determine if the web container has started.
*/
boolean isContainerStarted();

/**
* Get web thread pool.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,18 @@
import cn.hippo4j.adapter.web.AbstractWebThreadPoolService;
import cn.hippo4j.adapter.web.IWebThreadPoolHandlerSupport;
import cn.hippo4j.common.config.ApplicationContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.embedded.EmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext;
import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Field;

/**
* Abstract class for adapting WebThreadPoolService to Spring 1.x version.
*/
@Slf4j
public abstract class AbstractWebThreadPoolService1x extends AbstractWebThreadPoolService {

public AbstractWebThreadPoolService1x(IWebThreadPoolHandlerSupport support) {
super(support);
}

private static final String STARTED_FIELD_NAME = "started";

/**
* Get the embedded Servlet container from the Spring application context.
*/
Expand All @@ -53,17 +46,4 @@ protected EmbeddedServletContainer getContainer() {
public Integer getPort() {
return getContainer().getPort();
}

@Override
public boolean isContainerStarted() {
try {
EmbeddedServletContainer container = getContainer();
Field field = ReflectionUtils.findField(EmbeddedServletContainer.class, STARTED_FIELD_NAME);
ReflectionUtils.makeAccessible(field);
return (boolean) ReflectionUtils.getField(field, container);
} catch (Throwable th) {
log.error("Failed to get isStarted flag.", th);
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import cn.hippo4j.common.model.ThreadPoolParameterInfo;
import cn.hippo4j.config.springboot.starter.config.BootstrapConfigProperties;
import cn.hippo4j.config.springboot.starter.config.WebExecutorProperties;
import cn.hippo4j.message.enums.NotifyTypeEnum;
import cn.hippo4j.message.request.ChangeParameterNotifyRequest;
import cn.hippo4j.message.request.WebChangeParameterNotifyRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
Expand Down Expand Up @@ -79,8 +77,7 @@ public void onApplicationEvent(Hippo4jConfigDynamicRefreshEvent threadPoolDynami
}
if (!Objects.equals(beforeParameter.getCoreSize(), nowParameter.getCoreSize())
|| !Objects.equals(beforeParameter.getMaxSize(), nowParameter.getMaxSize())
|| !Objects.equals(beforeParameter.getKeepAliveTime(), nowParameter.getKeepAliveTime())
|| !webThreadPoolService.isContainerStarted()) {
|| !Objects.equals(beforeParameter.getKeepAliveTime(), nowParameter.getKeepAliveTime())) {
webThreadPoolService.updateWebThreadPool(nowParameter);
configChange.sendPoolConfigChange(buildChangeRequest(beforeParameter, nowParameter, webThreadPoolService));
}
Expand Down

0 comments on commit aee8f53

Please sign in to comment.