Wait executor terminated & Remove some usage of default model (#12713)
This commit is contained in:
parent
d452ea4924
commit
d8a314ff33
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.resource;
|
||||
|
||||
import org.apache.dubbo.common.config.ConfigurationUtils;
|
||||
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
import org.apache.dubbo.common.utils.NamedThreadFactory;
|
||||
|
|
@ -25,7 +26,9 @@ import java.util.List;
|
|||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_SERVER_SHUTDOWN_TIMEOUT;
|
||||
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_UNEXPECTED_EXCEPTION;
|
||||
|
||||
/**
|
||||
|
|
@ -105,6 +108,16 @@ public class GlobalResourcesRepository {
|
|||
}
|
||||
if (executorService != null) {
|
||||
executorService.shutdownNow();
|
||||
try {
|
||||
if (!executorService.awaitTermination(
|
||||
ConfigurationUtils.reCalShutdownTime(DEFAULT_SERVER_SHUTDOWN_TIMEOUT),
|
||||
TimeUnit.MILLISECONDS)) {
|
||||
logger.warn(COMMON_UNEXPECTED_EXCEPTION, "", "",
|
||||
"Wait global executor service terminated timeout.");
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
logger.warn(COMMON_UNEXPECTED_EXCEPTION, "", "", "destroy resources failed: " + e.getMessage(), e);
|
||||
}
|
||||
executorService = null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.threadpool.manager;
|
||||
|
||||
import org.apache.dubbo.common.config.ConfigurationUtils;
|
||||
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
import org.apache.dubbo.common.resource.Disposable;
|
||||
|
|
@ -31,6 +32,7 @@ import java.util.concurrent.SynchronousQueue;
|
|||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_SERVER_SHUTDOWN_TIMEOUT;
|
||||
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_UNEXPECTED_EXECUTORS_SHUTDOWN;
|
||||
|
||||
public class FrameworkExecutorRepository implements Disposable {
|
||||
|
|
@ -225,6 +227,12 @@ public class FrameworkExecutorRepository implements Disposable {
|
|||
private void shutdownExecutorService(ExecutorService executorService, String name) {
|
||||
try {
|
||||
executorService.shutdownNow();
|
||||
if (!executorService.awaitTermination(
|
||||
ConfigurationUtils.reCalShutdownTime(DEFAULT_SERVER_SHUTDOWN_TIMEOUT),
|
||||
TimeUnit.MILLISECONDS)) {
|
||||
logger.warn(COMMON_UNEXPECTED_EXECUTORS_SHUTDOWN, "", "",
|
||||
"Wait global executor service terminated timeout.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
String msg = "shutdown executor service [" + name + "] failed: ";
|
||||
logger.warn(COMMON_UNEXPECTED_EXECUTORS_SHUTDOWN, "", "", msg + e.getMessage(), e);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package org.apache.dubbo.metadata;
|
|||
|
||||
import org.apache.dubbo.common.cache.FileCacheStore;
|
||||
import org.apache.dubbo.common.cache.FileCacheStoreFactory;
|
||||
import org.apache.dubbo.common.config.ConfigurationUtils;
|
||||
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
import org.apache.dubbo.common.resource.Disposable;
|
||||
|
|
@ -32,7 +33,9 @@ import java.util.concurrent.Executors;
|
|||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_SERVER_SHUTDOWN_TIMEOUT;
|
||||
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_FAILED_LOAD_MAPPING_CACHE;
|
||||
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_UNEXPECTED_EXCEPTION;
|
||||
|
||||
public abstract class AbstractCacheManager<V> implements Disposable {
|
||||
protected final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(getClass());
|
||||
|
|
@ -109,6 +112,16 @@ public abstract class AbstractCacheManager<V> implements Disposable {
|
|||
public void destroy() {
|
||||
if (executorService != null) {
|
||||
executorService.shutdownNow();
|
||||
try {
|
||||
if (!executorService.awaitTermination(
|
||||
ConfigurationUtils.reCalShutdownTime(DEFAULT_SERVER_SHUTDOWN_TIMEOUT),
|
||||
TimeUnit.MILLISECONDS)) {
|
||||
logger.warn(COMMON_UNEXPECTED_EXCEPTION, "", "",
|
||||
"Wait global executor service terminated timeout.");
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
logger.warn(COMMON_UNEXPECTED_EXCEPTION, "", "", "destroy resources failed: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
if (cacheStore != null) {
|
||||
cacheStore.destroy();
|
||||
|
|
|
|||
|
|
@ -515,12 +515,14 @@ public class DubboProtocol extends AbstractProtocol {
|
|||
}
|
||||
|
||||
try {
|
||||
ScopeModel scopeModel = url.getScopeModel();
|
||||
int heartbeat = UrlUtils.getHeartbeat(url);
|
||||
// Replace InstanceAddressURL with ServiceConfigURL.
|
||||
url = new ServiceConfigURL(DubboCodec.NAME, url.getUsername(), url.getPassword(), url.getHost(), url.getPort(), url.getPath(), url.getAllParameters());
|
||||
url = url.addParameter(CODEC_KEY, DubboCodec.NAME);
|
||||
// enable heartbeat by default
|
||||
url = url.addParameterIfAbsent(HEARTBEAT_KEY, Integer.toString(heartbeat));
|
||||
url = url.setScopeModel(scopeModel);
|
||||
|
||||
// connection should be lazy
|
||||
return url.getParameter(LAZY_CONNECT_KEY, false)
|
||||
|
|
|
|||
|
|
@ -16,17 +16,17 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.serialize.fastjson2;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.serialize.ObjectInput;
|
||||
import org.apache.dubbo.common.serialize.ObjectOutput;
|
||||
import org.apache.dubbo.common.serialize.Serialization;
|
||||
import org.apache.dubbo.rpc.model.FrameworkModel;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.apache.dubbo.common.serialize.Constants.FASTJSON2_SERIALIZATION_ID;
|
||||
|
||||
/**
|
||||
|
|
@ -52,11 +52,11 @@ public class FastJson2Serialization implements Serialization {
|
|||
public ObjectOutput serialize(URL url, OutputStream output) throws IOException {
|
||||
Fastjson2CreatorManager fastjson2CreatorManager = Optional.ofNullable(url)
|
||||
.map(URL::getOrDefaultFrameworkModel)
|
||||
.orElse(FrameworkModel.defaultModel())
|
||||
.orElseGet(FrameworkModel::defaultModel)
|
||||
.getBeanFactory().getBean(Fastjson2CreatorManager.class);
|
||||
Fastjson2SecurityManager fastjson2SecurityManager = Optional.ofNullable(url)
|
||||
.map(URL::getOrDefaultFrameworkModel)
|
||||
.orElse(FrameworkModel.defaultModel())
|
||||
.orElseGet(FrameworkModel::defaultModel)
|
||||
.getBeanFactory().getBean(Fastjson2SecurityManager.class);
|
||||
|
||||
return new FastJson2ObjectOutput(fastjson2CreatorManager, fastjson2SecurityManager, output);
|
||||
|
|
@ -66,11 +66,11 @@ public class FastJson2Serialization implements Serialization {
|
|||
public ObjectInput deserialize(URL url, InputStream input) throws IOException {
|
||||
Fastjson2CreatorManager fastjson2CreatorManager = Optional.ofNullable(url)
|
||||
.map(URL::getOrDefaultFrameworkModel)
|
||||
.orElse(FrameworkModel.defaultModel())
|
||||
.orElseGet(FrameworkModel::defaultModel)
|
||||
.getBeanFactory().getBean(Fastjson2CreatorManager.class);
|
||||
Fastjson2SecurityManager fastjson2SecurityManager = Optional.ofNullable(url)
|
||||
.map(URL::getOrDefaultFrameworkModel)
|
||||
.orElse(FrameworkModel.defaultModel())
|
||||
.orElseGet(FrameworkModel::defaultModel)
|
||||
.getBeanFactory().getBean(Fastjson2SecurityManager.class);
|
||||
|
||||
return new FastJson2ObjectInput(fastjson2CreatorManager, fastjson2SecurityManager, input);
|
||||
|
|
|
|||
|
|
@ -16,17 +16,17 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.serialize.hessian2;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.serialize.ObjectInput;
|
||||
import org.apache.dubbo.common.serialize.ObjectOutput;
|
||||
import org.apache.dubbo.common.serialize.Serialization;
|
||||
import org.apache.dubbo.rpc.model.FrameworkModel;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.apache.dubbo.common.serialize.Constants.HESSIAN2_SERIALIZATION_ID;
|
||||
|
||||
/**
|
||||
|
|
@ -52,7 +52,7 @@ public class Hessian2Serialization implements Serialization {
|
|||
public ObjectOutput serialize(URL url, OutputStream out) throws IOException {
|
||||
Hessian2FactoryManager hessian2FactoryManager = Optional.ofNullable(url)
|
||||
.map(URL::getOrDefaultFrameworkModel)
|
||||
.orElse(FrameworkModel.defaultModel())
|
||||
.orElseGet(FrameworkModel::defaultModel)
|
||||
.getBeanFactory().getBean(Hessian2FactoryManager.class);
|
||||
return new Hessian2ObjectOutput(out, hessian2FactoryManager);
|
||||
}
|
||||
|
|
@ -61,7 +61,7 @@ public class Hessian2Serialization implements Serialization {
|
|||
public ObjectInput deserialize(URL url, InputStream is) throws IOException {
|
||||
Hessian2FactoryManager hessian2FactoryManager = Optional.ofNullable(url)
|
||||
.map(URL::getOrDefaultFrameworkModel)
|
||||
.orElse(FrameworkModel.defaultModel())
|
||||
.orElseGet(FrameworkModel::defaultModel)
|
||||
.getBeanFactory().getBean(Hessian2FactoryManager.class);
|
||||
return new Hessian2ObjectInput(is, hessian2FactoryManager);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue