Skip to content

Commit d8a314f

Browse files
authored
Wait executor terminated & Remove some usage of default model (#12713)
1 parent d452ea4 commit d8a314f

File tree

6 files changed

+52
-16
lines changed

6 files changed

+52
-16
lines changed

dubbo-common/src/main/java/org/apache/dubbo/common/resource/GlobalResourcesRepository.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.dubbo.common.resource;
1818

19+
import org.apache.dubbo.common.config.ConfigurationUtils;
1920
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
2021
import org.apache.dubbo.common.logger.LoggerFactory;
2122
import org.apache.dubbo.common.utils.NamedThreadFactory;
@@ -25,7 +26,9 @@
2526
import java.util.concurrent.CopyOnWriteArrayList;
2627
import java.util.concurrent.ExecutorService;
2728
import java.util.concurrent.Executors;
29+
import java.util.concurrent.TimeUnit;
2830

31+
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_SERVER_SHUTDOWN_TIMEOUT;
2932
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_UNEXPECTED_EXCEPTION;
3033

3134
/**
@@ -105,6 +108,16 @@ public synchronized void destroy() {
105108
}
106109
if (executorService != null) {
107110
executorService.shutdownNow();
111+
try {
112+
if (!executorService.awaitTermination(
113+
ConfigurationUtils.reCalShutdownTime(DEFAULT_SERVER_SHUTDOWN_TIMEOUT),
114+
TimeUnit.MILLISECONDS)) {
115+
logger.warn(COMMON_UNEXPECTED_EXCEPTION, "", "",
116+
"Wait global executor service terminated timeout.");
117+
}
118+
} catch (InterruptedException e) {
119+
logger.warn(COMMON_UNEXPECTED_EXCEPTION, "", "", "destroy resources failed: " + e.getMessage(), e);
120+
}
108121
executorService = null;
109122
}
110123

dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/manager/FrameworkExecutorRepository.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.dubbo.common.threadpool.manager;
1818

19+
import org.apache.dubbo.common.config.ConfigurationUtils;
1920
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
2021
import org.apache.dubbo.common.logger.LoggerFactory;
2122
import org.apache.dubbo.common.resource.Disposable;
@@ -31,6 +32,7 @@
3132
import java.util.concurrent.ThreadPoolExecutor;
3233
import java.util.concurrent.TimeUnit;
3334

35+
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_SERVER_SHUTDOWN_TIMEOUT;
3436
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_UNEXPECTED_EXECUTORS_SHUTDOWN;
3537

3638
public class FrameworkExecutorRepository implements Disposable {
@@ -225,6 +227,12 @@ private void shutdownExecutorServices(List<? extends ExecutorService> executorSe
225227
private void shutdownExecutorService(ExecutorService executorService, String name) {
226228
try {
227229
executorService.shutdownNow();
230+
if (!executorService.awaitTermination(
231+
ConfigurationUtils.reCalShutdownTime(DEFAULT_SERVER_SHUTDOWN_TIMEOUT),
232+
TimeUnit.MILLISECONDS)) {
233+
logger.warn(COMMON_UNEXPECTED_EXECUTORS_SHUTDOWN, "", "",
234+
"Wait global executor service terminated timeout.");
235+
}
228236
} catch (Exception e) {
229237
String msg = "shutdown executor service [" + name + "] failed: ";
230238
logger.warn(COMMON_UNEXPECTED_EXECUTORS_SHUTDOWN, "", "", msg + e.getMessage(), e);

dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/AbstractCacheManager.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.apache.dubbo.common.cache.FileCacheStore;
2020
import org.apache.dubbo.common.cache.FileCacheStoreFactory;
21+
import org.apache.dubbo.common.config.ConfigurationUtils;
2122
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
2223
import org.apache.dubbo.common.logger.LoggerFactory;
2324
import org.apache.dubbo.common.resource.Disposable;
@@ -32,7 +33,9 @@
3233
import java.util.concurrent.ScheduledExecutorService;
3334
import java.util.concurrent.TimeUnit;
3435

36+
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_SERVER_SHUTDOWN_TIMEOUT;
3537
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_FAILED_LOAD_MAPPING_CACHE;
38+
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_UNEXPECTED_EXCEPTION;
3639

3740
public abstract class AbstractCacheManager<V> implements Disposable {
3841
protected final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(getClass());
@@ -109,6 +112,16 @@ public void update(Map<String, V> newCache) {
109112
public void destroy() {
110113
if (executorService != null) {
111114
executorService.shutdownNow();
115+
try {
116+
if (!executorService.awaitTermination(
117+
ConfigurationUtils.reCalShutdownTime(DEFAULT_SERVER_SHUTDOWN_TIMEOUT),
118+
TimeUnit.MILLISECONDS)) {
119+
logger.warn(COMMON_UNEXPECTED_EXCEPTION, "", "",
120+
"Wait global executor service terminated timeout.");
121+
}
122+
} catch (InterruptedException e) {
123+
logger.warn(COMMON_UNEXPECTED_EXCEPTION, "", "", "destroy resources failed: " + e.getMessage(), e);
124+
}
112125
}
113126
if (cacheStore != null) {
114127
cacheStore.destroy();

dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocol.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,12 +515,14 @@ private ExchangeClient initClient(URL url) {
515515
}
516516

517517
try {
518+
ScopeModel scopeModel = url.getScopeModel();
518519
int heartbeat = UrlUtils.getHeartbeat(url);
519520
// Replace InstanceAddressURL with ServiceConfigURL.
520521
url = new ServiceConfigURL(DubboCodec.NAME, url.getUsername(), url.getPassword(), url.getHost(), url.getPort(), url.getPath(), url.getAllParameters());
521522
url = url.addParameter(CODEC_KEY, DubboCodec.NAME);
522523
// enable heartbeat by default
523524
url = url.addParameterIfAbsent(HEARTBEAT_KEY, Integer.toString(heartbeat));
525+
url = url.setScopeModel(scopeModel);
524526

525527
// connection should be lazy
526528
return url.getParameter(LAZY_CONNECT_KEY, false)

dubbo-serialization/dubbo-serialization-fastjson2/src/main/java/org/apache/dubbo/common/serialize/fastjson2/FastJson2Serialization.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
*/
1717
package org.apache.dubbo.common.serialize.fastjson2;
1818

19-
import java.io.IOException;
20-
import java.io.InputStream;
21-
import java.io.OutputStream;
22-
import java.util.Optional;
23-
2419
import org.apache.dubbo.common.URL;
2520
import org.apache.dubbo.common.serialize.ObjectInput;
2621
import org.apache.dubbo.common.serialize.ObjectOutput;
2722
import org.apache.dubbo.common.serialize.Serialization;
2823
import org.apache.dubbo.rpc.model.FrameworkModel;
2924

25+
import java.io.IOException;
26+
import java.io.InputStream;
27+
import java.io.OutputStream;
28+
import java.util.Optional;
29+
3030
import static org.apache.dubbo.common.serialize.Constants.FASTJSON2_SERIALIZATION_ID;
3131

3232
/**
@@ -52,11 +52,11 @@ public String getContentType() {
5252
public ObjectOutput serialize(URL url, OutputStream output) throws IOException {
5353
Fastjson2CreatorManager fastjson2CreatorManager = Optional.ofNullable(url)
5454
.map(URL::getOrDefaultFrameworkModel)
55-
.orElse(FrameworkModel.defaultModel())
55+
.orElseGet(FrameworkModel::defaultModel)
5656
.getBeanFactory().getBean(Fastjson2CreatorManager.class);
5757
Fastjson2SecurityManager fastjson2SecurityManager = Optional.ofNullable(url)
5858
.map(URL::getOrDefaultFrameworkModel)
59-
.orElse(FrameworkModel.defaultModel())
59+
.orElseGet(FrameworkModel::defaultModel)
6060
.getBeanFactory().getBean(Fastjson2SecurityManager.class);
6161

6262
return new FastJson2ObjectOutput(fastjson2CreatorManager, fastjson2SecurityManager, output);
@@ -66,11 +66,11 @@ public ObjectOutput serialize(URL url, OutputStream output) throws IOException {
6666
public ObjectInput deserialize(URL url, InputStream input) throws IOException {
6767
Fastjson2CreatorManager fastjson2CreatorManager = Optional.ofNullable(url)
6868
.map(URL::getOrDefaultFrameworkModel)
69-
.orElse(FrameworkModel.defaultModel())
69+
.orElseGet(FrameworkModel::defaultModel)
7070
.getBeanFactory().getBean(Fastjson2CreatorManager.class);
7171
Fastjson2SecurityManager fastjson2SecurityManager = Optional.ofNullable(url)
7272
.map(URL::getOrDefaultFrameworkModel)
73-
.orElse(FrameworkModel.defaultModel())
73+
.orElseGet(FrameworkModel::defaultModel)
7474
.getBeanFactory().getBean(Fastjson2SecurityManager.class);
7575

7676
return new FastJson2ObjectInput(fastjson2CreatorManager, fastjson2SecurityManager, input);

dubbo-serialization/dubbo-serialization-hessian2/src/main/java/org/apache/dubbo/common/serialize/hessian2/Hessian2Serialization.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
*/
1717
package org.apache.dubbo.common.serialize.hessian2;
1818

19-
import java.io.IOException;
20-
import java.io.InputStream;
21-
import java.io.OutputStream;
22-
import java.util.Optional;
23-
2419
import org.apache.dubbo.common.URL;
2520
import org.apache.dubbo.common.serialize.ObjectInput;
2621
import org.apache.dubbo.common.serialize.ObjectOutput;
2722
import org.apache.dubbo.common.serialize.Serialization;
2823
import org.apache.dubbo.rpc.model.FrameworkModel;
2924

25+
import java.io.IOException;
26+
import java.io.InputStream;
27+
import java.io.OutputStream;
28+
import java.util.Optional;
29+
3030
import static org.apache.dubbo.common.serialize.Constants.HESSIAN2_SERIALIZATION_ID;
3131

3232
/**
@@ -52,7 +52,7 @@ public String getContentType() {
5252
public ObjectOutput serialize(URL url, OutputStream out) throws IOException {
5353
Hessian2FactoryManager hessian2FactoryManager = Optional.ofNullable(url)
5454
.map(URL::getOrDefaultFrameworkModel)
55-
.orElse(FrameworkModel.defaultModel())
55+
.orElseGet(FrameworkModel::defaultModel)
5656
.getBeanFactory().getBean(Hessian2FactoryManager.class);
5757
return new Hessian2ObjectOutput(out, hessian2FactoryManager);
5858
}
@@ -61,7 +61,7 @@ public ObjectOutput serialize(URL url, OutputStream out) throws IOException {
6161
public ObjectInput deserialize(URL url, InputStream is) throws IOException {
6262
Hessian2FactoryManager hessian2FactoryManager = Optional.ofNullable(url)
6363
.map(URL::getOrDefaultFrameworkModel)
64-
.orElse(FrameworkModel.defaultModel())
64+
.orElseGet(FrameworkModel::defaultModel)
6565
.getBeanFactory().getBean(Hessian2FactoryManager.class);
6666
return new Hessian2ObjectInput(is, hessian2FactoryManager);
6767
}

0 commit comments

Comments
 (0)