Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
2f600c8
feat: 修复线程池泄露问题,并增加相应测试。
magicliang Aug 28, 2025
0c6c2f2
chore(test): 新增 DefResponseFutureManager.reset() 调用
magicliang Aug 29, 2025
81c41ff
docs(test): 将测试注释及字符串转为英文,新增两个测试方法
magicliang Sep 17, 2025
44a753e
docs: 将部分代码注释从中文改为英文
magicliang Sep 17, 2025
3138849
docs: 将注释“服务接口配置”改为英文“Service interface configuration”
magicliang Sep 17, 2025
6fec831
docs: 将注释“服务接口配置”改为英文“Service interface configuration”
magicliang Sep 17, 2025
c778e25
feat: 新增关闭监听器及超时管理器控制方法
magicliang Sep 17, 2025
251abed
style: 移除 DefTimeoutManager 类 watch 方法多余减号注释行
magicliang Sep 17, 2025
1e63482
style: 统一 ConfigManagerTest 测试方法缩进格式
magicliang Sep 17, 2025
40e7162
style: 移除 ConfigManager.reset() 空行并设置默认值 false
magicliang Sep 17, 2025
ba6b344
test: 为 Http2cRpcClientTest 新增前置方法与类导入
magicliang Sep 17, 2025
700d8d9
test: 新增测试类初始化方法重置 AbstractConsumerInvoker
magicliang Sep 17, 2025
32775c8
fix: 修正日志标点及异常参数顺序并补充异常对象输出
magicliang Sep 17, 2025
2c62555
test: 新增 AbstractConsumerInvoker 的 ShutdownListener 功能测试
magicliang Sep 17, 2025
e19a490
feat(test): 新增HTTP/HTTPS协议配置及URI构建测试
magicliang Sep 17, 2025
4b81079
feat(test): 新增测试验证 MXBean 为 null 时关闭方法正常执行
magicliang Sep 17, 2025
9bb151f
test: 新增 MBean 注册注销异常处理及 TestMBean 测试用例
magicliang Sep 17, 2025
54ae07e
docs: 将测试类注释从中文改为英文
magicliang Sep 17, 2025
130229a
test: 新增测试验证 unregisterMBean 对 null 参数的异常处理
magicliang Sep 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.tencent.trpc.core.exception.TRpcException;
import com.tencent.trpc.core.rpc.RpcClientContext;
import com.tencent.trpc.core.rpc.TRpcProxy;
import com.tencent.trpc.proto.support.DefResponseFutureManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -44,6 +45,7 @@ public void after() {
container.stop();
}
ConfigManager.stopTest();
DefResponseFutureManager.reset();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.TimeUnit;

public class ConfigManager {
Expand All @@ -55,6 +56,12 @@ public class ConfigManager {
* Container startup listener
*/
private final Set<TRPCRunListener> tRPCRunListeners = Sets.newConcurrentHashSet();

/**
* Shutdown listeners for decoupled cleanup, using WeakHashMap to prevent classloader leaks
*/
private final Map<ShutdownListener, Boolean> shutdownListeners = new WeakHashMap<>();

/**
* Business initialization
*/
Expand Down Expand Up @@ -251,6 +258,41 @@ public void addTRPCRunListener(TRPCRunListener trpcRunListener) {
tRPCRunListeners.add(trpcRunListener);
}

/**
* Get all shutdown listeners loaded via SPI.
*
* @return set of shutdown listeners
*/
public void registerShutdownListener(ShutdownListener listener) {
if (listener != null) {
shutdownListeners.put(listener, Boolean.TRUE);
}
}

/**
* Unregister a shutdown listener.
*
* @param listener the shutdown listener to unregister
*/
public void unregisterShutdownListener(ShutdownListener listener) {
if (listener != null) {
shutdownListeners.remove(listener);
}
}

/**
* Notify all registered shutdown listeners.
*/
private void notifyShutdownListeners() {
shutdownListeners.keySet().forEach(listener -> {
try {
listener.onShutdown();
} catch (Exception e) {
logger.error("Error executing shutdown listener: {}", listener.getClass().getName(), e);
}
});
}

@Override
public String toString() {
return "ApplicationConfig {globalConfig=" + globalConfig + ", serverConfig=" + serverConfig
Expand Down Expand Up @@ -385,6 +427,10 @@ protected void stopInternal() throws Exception {
ExtensionLoader.destroyAllPlugin();
// 8) close client cluster
RpcClusterClientManager.close();

// Notify all shutdown listeners before actual shutdown
notifyShutdownListeners();

logger.info(">>>tRPC Server stopped");
}

Expand All @@ -394,4 +440,4 @@ public String toString() {
}
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Tencent is pleased to support the open source community by making tRPC available.
*
* Copyright (C) 2023 Tencent.
* All rights reserved.
*
* If you have downloaded a copy of the tRPC source code from Tencent,
* please note that tRPC source code is licensed under the Apache 2.0 License,
* A copy of the Apache 2.0 License can be found in the LICENSE file.
*/

package com.tencent.trpc.core.common;

/**
* Shutdown listener for components that need to perform cleanup when the container stops.
* This provides a decoupled way for components to register shutdown hooks without
* creating circular dependencies.
*/
public interface ShutdownListener {

/**
* Called when the container is shutting down.
*/
void onShutdown();

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,20 @@ public static void registerMBean(Object object, ObjectName objectName) {
}
}

/**
* Unregister mbean
*
* @param objectName mbean object name {@link ObjectName}
*/
public static void unregisterMBean(ObjectName objectName) {
try {
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
if (mBeanServer.isRegistered(objectName)) {
mBeanServer.unregisterMBean(objectName);
}
} catch (Exception e) {
logger.warn("unregister mbean exception: ", e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ public void close(long timeoutMills) {
shutdownGraceful(timeoutMills);
}
}

// unregister MBean
if (this.forkJoinPoolMXBean != null) {
MBeanRegistryHelper.unregisterMBean(this.forkJoinPoolMXBean.getObjectName());
}
}

private void shutdownGraceful(long timeoutMills) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ public void close(long timeoutMills) {
shutdownGraceful(timeoutMills);
}
}
// unregister Mbean
if (this.threadPoolMXBean != null) {
MBeanRegistryHelper.unregisterMBean(this.threadPoolMXBean.getObjectName());
}
}

@Override
Expand Down
Loading