mirror of https://github.com/longtai-cn/hippo4j
Implement the ability to notify changes to the web container thread pool under the Config mode. (#1133)
* Add notification logic after modifying web thread pool parameters. * Refactor the notification module to enable notification capability for the web container. * Add application profile enum. * Revert the bugfix changes and split them into issue #1134. * Revert @Order annotation in AbstractWebThreadPoolService. * fix profile enum name with test environment. * Fix: remove unused imports. * Delete ProfileEnum class. * Modify the way of obtaining the ID of the web thread pool. * Move the IExecutorProperties class to the common module. * Narrow the scope of @SuppressWarnings annotation usage.pull/1154/head
parent
ffaa4fbd4d
commit
f54d915dec
@ -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.common.api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for thread pool configuration.
|
||||||
|
*/
|
||||||
|
public interface IExecutorProperties {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thread pool id
|
||||||
|
*/
|
||||||
|
String getThreadPoolId();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Core pool size
|
||||||
|
*/
|
||||||
|
Integer getCorePoolSize();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum pool size
|
||||||
|
*/
|
||||||
|
Integer getMaximumPoolSize();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keep alive time
|
||||||
|
*/
|
||||||
|
Long getKeepAliveTime();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notify configs
|
||||||
|
*/
|
||||||
|
ExecutorNotifyProperties getNotify();
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* 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.message.request;
|
||||||
|
|
||||||
|
import cn.hippo4j.message.request.base.BaseNotifyRequest;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change parameter notify request for web thread pool.
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class WebChangeParameterNotifyRequest extends BaseNotifyRequest {
|
||||||
|
|
||||||
|
private String active;
|
||||||
|
|
||||||
|
private String appName;
|
||||||
|
|
||||||
|
private String identify;
|
||||||
|
|
||||||
|
private Integer beforeCorePoolSize;
|
||||||
|
|
||||||
|
private Integer nowCorePoolSize;
|
||||||
|
|
||||||
|
private Integer beforeMaximumPoolSize;
|
||||||
|
|
||||||
|
private Integer nowMaximumPoolSize;
|
||||||
|
|
||||||
|
private Long beforeKeepAliveTime;
|
||||||
|
|
||||||
|
private Long nowKeepAliveTime;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* 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.message.service;
|
||||||
|
|
||||||
|
import cn.hippo4j.common.api.ThreadPoolConfigChange;
|
||||||
|
import cn.hippo4j.common.toolkit.StringUtil;
|
||||||
|
import cn.hippo4j.core.toolkit.IdentifyUtil;
|
||||||
|
import cn.hippo4j.message.request.ChangeParameterNotifyRequest;
|
||||||
|
import cn.hippo4j.message.request.WebChangeParameterNotifyRequest;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Web thread-pool config change handler.
|
||||||
|
*/
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
|
public class WebThreadPoolConfigChangeHandler implements ThreadPoolConfigChange<WebChangeParameterNotifyRequest> {
|
||||||
|
|
||||||
|
@Value("${spring.profiles.active:UNKNOWN}")
|
||||||
|
private String active;
|
||||||
|
|
||||||
|
@Value("${spring.dynamic.thread-pool.item-id:}")
|
||||||
|
private String itemId;
|
||||||
|
|
||||||
|
@Value("${spring.application.name:UNKNOWN}")
|
||||||
|
private String applicationName;
|
||||||
|
|
||||||
|
private final Hippo4jSendMessageService hippo4jSendMessageService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send pool config change message for web.
|
||||||
|
*
|
||||||
|
* @param requestParam change parameter notify request
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void sendPoolConfigChange(WebChangeParameterNotifyRequest requestParam) {
|
||||||
|
try {
|
||||||
|
requestParam.setActive(active.toUpperCase());
|
||||||
|
String appName = StringUtil.isBlank(itemId) ? applicationName : itemId;
|
||||||
|
requestParam.setAppName(appName);
|
||||||
|
requestParam.setIdentify(IdentifyUtil.getIdentify());
|
||||||
|
hippo4jSendMessageService.sendChangeMessage(requestParam);
|
||||||
|
} catch (Throwable th) {
|
||||||
|
log.error("send web thread pool config change message failed.", th);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue