Merge branch 'apache-3.1' into apache-3.2

# Conflicts:
#	dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ApplicationModel.java
#	dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ModuleModel.java
#	dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ApplicationModelTest.java
This commit is contained in:
Albumen Kevin 2023-02-16 14:16:12 +08:00
commit 6c062586b4
40 changed files with 543 additions and 509 deletions

View File

@ -315,7 +315,7 @@ public class Environment extends LifecycleAdapter implements ApplicationExt {
return localMigrationRule;
}
public void refreshClassLoaders() {
public synchronized void refreshClassLoaders() {
propertiesConfiguration.refresh();
loadMigrationRule();
this.globalConfiguration = null;

View File

@ -220,7 +220,7 @@ public class ModuleEnvironment extends Environment implements ModuleExt {
}
@Override
public void refreshClassLoaders() {
public synchronized void refreshClassLoaders() {
orderedPropertiesConfiguration.refresh();
applicationDelegate.refreshClassLoaders();
}

View File

@ -55,20 +55,19 @@ public class ApplicationModel extends ScopeModel {
public static final String NAME = "ApplicationModel";
private final List<ModuleModel> moduleModels = new CopyOnWriteArrayList<>();
private final List<ModuleModel> pubModuleModels = new CopyOnWriteArrayList<>();
private Environment environment;
private ConfigManager configManager;
private ServiceRepository serviceRepository;
private ApplicationDeployer deployer;
private volatile Environment environment;
private volatile ConfigManager configManager;
private volatile ServiceRepository serviceRepository;
private volatile ApplicationDeployer deployer;
private final FrameworkModel frameworkModel;
private ModuleModel internalModule;
private final ModuleModel internalModule;
private volatile ModuleModel defaultModule;
// internal module index is 0, default module index is 1
private final AtomicInteger moduleIndex = new AtomicInteger(0);
private final Object moduleLock = new Object();
// --------- static methods ----------//
@ -91,6 +90,262 @@ public class ApplicationModel extends ScopeModel {
return FrameworkModel.defaultModel().defaultApplication();
}
// ------------- instance methods ---------------//
protected ApplicationModel(FrameworkModel frameworkModel) {
this(frameworkModel, false);
}
protected ApplicationModel(FrameworkModel frameworkModel, boolean isInternal) {
super(frameworkModel, ExtensionScope.APPLICATION, isInternal);
synchronized (instLock) {
Assert.notNull(frameworkModel, "FrameworkModel can not be null");
this.frameworkModel = frameworkModel;
frameworkModel.addApplication(this);
if (LOGGER.isInfoEnabled()) {
LOGGER.info(getDesc() + " is created");
}
initialize();
this.internalModule = new ModuleModel(this, true);
this.serviceRepository = new ServiceRepository(this);
ExtensionLoader<ApplicationInitListener> extensionLoader = this.getExtensionLoader(ApplicationInitListener.class);
Set<String> listenerNames = extensionLoader.getSupportedExtensions();
for (String listenerName : listenerNames) {
extensionLoader.getExtension(listenerName).init();
}
initApplicationExts();
ExtensionLoader<ScopeModelInitializer> initializerExtensionLoader = this.getExtensionLoader(ScopeModelInitializer.class);
Set<ScopeModelInitializer> initializers = initializerExtensionLoader.getSupportedExtensionInstances();
for (ScopeModelInitializer initializer : initializers) {
initializer.initializeApplicationModel(this);
}
Assert.notNull(getApplicationServiceRepository(), "ApplicationServiceRepository can not be null");
Assert.notNull(getApplicationConfigManager(), "ApplicationConfigManager can not be null");
Assert.assertTrue(getApplicationConfigManager().isInitialized(), "ApplicationConfigManager can not be initialized");
}
}
// already synchronized in constructor
private void initApplicationExts() {
Set<ApplicationExt> exts = this.getExtensionLoader(ApplicationExt.class).getSupportedExtensionInstances();
for (ApplicationExt ext : exts) {
ext.initialize();
}
}
@Override
protected void onDestroy() {
synchronized (instLock) {
// 1. remove from frameworkModel
frameworkModel.removeApplication(this);
// 2. pre-destroy, set stopping
if (deployer != null) {
// destroy registries and unregister services from registries first to notify consumers to stop consuming this instance.
deployer.preDestroy();
}
// 3. Try to destroy protocols to stop this instance from receiving new requests from connections
frameworkModel.tryDestroyProtocols();
// 4. destroy application resources
for (ModuleModel moduleModel : moduleModels) {
if (moduleModel != internalModule) {
moduleModel.destroy();
}
}
// 5. destroy internal module later
internalModule.destroy();
// 6. post-destroy, release registry resources
if (deployer != null) {
deployer.postDestroy();
}
// 7. destroy other resources (e.g. ZookeeperTransporter )
notifyDestroy();
if (environment != null) {
environment.destroy();
environment = null;
}
if (configManager != null) {
configManager.destroy();
configManager = null;
}
if (serviceRepository != null) {
serviceRepository.destroy();
serviceRepository = null;
}
// 8. destroy framework if none application
frameworkModel.tryDestroy();
}
}
public FrameworkModel getFrameworkModel() {
return frameworkModel;
}
public ModuleModel newModule() {
synchronized (instLock) {
return new ModuleModel(this);
}
}
@Override
public Environment getModelEnvironment() {
if (environment == null) {
environment = (Environment) this.getExtensionLoader(ApplicationExt.class)
.getExtension(Environment.NAME);
}
return environment;
}
public ConfigManager getApplicationConfigManager() {
if (configManager == null) {
configManager = (ConfigManager) this.getExtensionLoader(ApplicationExt.class)
.getExtension(ConfigManager.NAME);
}
return configManager;
}
public ServiceRepository getApplicationServiceRepository() {
return serviceRepository;
}
public ExecutorRepository getApplicationExecutorRepository() {
return ExecutorRepository.getInstance(this);
}
public ApplicationConfig getCurrentConfig() {
return getApplicationConfigManager().getApplicationOrElseThrow();
}
public String getApplicationName() {
return getCurrentConfig().getName();
}
public String tryGetApplicationName() {
Optional<ApplicationConfig> appCfgOptional = getApplicationConfigManager().getApplication();
return appCfgOptional.isPresent() ? appCfgOptional.get().getName() : null;
}
void addModule(ModuleModel moduleModel, boolean isInternal) {
synchronized (instLock) {
if (!this.moduleModels.contains(moduleModel)) {
checkDestroyed();
this.moduleModels.add(moduleModel);
moduleModel.setInternalId(buildInternalId(getInternalId(), moduleIndex.getAndIncrement()));
if (!isInternal) {
pubModuleModels.add(moduleModel);
}
}
}
}
public void removeModule(ModuleModel moduleModel) {
synchronized (instLock) {
this.moduleModels.remove(moduleModel);
this.pubModuleModels.remove(moduleModel);
if (moduleModel == defaultModule) {
defaultModule = findDefaultModule();
}
}
}
void tryDestroy() {
synchronized (instLock) {
if (this.moduleModels.isEmpty()
|| (this.moduleModels.size() == 1 && this.moduleModels.get(0) == internalModule)) {
destroy();
}
}
}
private void checkDestroyed() {
if (isDestroyed()) {
throw new IllegalStateException("ApplicationModel is destroyed");
}
}
public List<ModuleModel> getModuleModels() {
return Collections.unmodifiableList(moduleModels);
}
public List<ModuleModel> getPubModuleModels() {
return Collections.unmodifiableList(pubModuleModels);
}
public ModuleModel getDefaultModule() {
if (defaultModule == null) {
synchronized (instLock) {
if (defaultModule == null) {
defaultModule = findDefaultModule();
if (defaultModule == null) {
defaultModule = this.newModule();
}
}
}
}
return defaultModule;
}
private ModuleModel findDefaultModule() {
synchronized (instLock) {
for (ModuleModel moduleModel : moduleModels) {
if (moduleModel != internalModule) {
return moduleModel;
}
}
return null;
}
}
public ModuleModel getInternalModule() {
return internalModule;
}
@Override
public void addClassLoader(ClassLoader classLoader) {
super.addClassLoader(classLoader);
if (environment != null) {
environment.refreshClassLoaders();
}
}
@Override
public void removeClassLoader(ClassLoader classLoader) {
super.removeClassLoader(classLoader);
if (environment != null) {
environment.refreshClassLoaders();
}
}
@Override
protected boolean checkIfClassLoaderCanRemoved(ClassLoader classLoader) {
return super.checkIfClassLoaderCanRemoved(classLoader) && !containsClassLoader(classLoader);
}
protected boolean containsClassLoader(ClassLoader classLoader) {
return moduleModels.stream().anyMatch(moduleModel -> moduleModel.getClassLoaders().contains(classLoader));
}
public ApplicationDeployer getDeployer() {
return deployer;
}
public void setDeployer(ApplicationDeployer deployer) {
this.deployer = deployer;
}
// =============================== Deprecated Methods Start =======================================
/**
* @deprecated use {@link ServiceRepository#allConsumerModels()}
*/
@ -187,218 +442,6 @@ public class ApplicationModel extends ScopeModel {
}
}
// ------------- instance methods ---------------//
public ApplicationModel(FrameworkModel frameworkModel) {
this(frameworkModel, false);
}
public ApplicationModel(FrameworkModel frameworkModel, boolean isInternal) {
super(frameworkModel, ExtensionScope.APPLICATION, isInternal);
Assert.notNull(frameworkModel, "FrameworkModel can not be null");
this.frameworkModel = frameworkModel;
frameworkModel.addApplication(this);
if (LOGGER.isInfoEnabled()) {
LOGGER.info(getDesc() + " is created");
}
initialize();
Assert.notNull(getApplicationServiceRepository(), "ApplicationServiceRepository can not be null");
Assert.notNull(getApplicationConfigManager(), "ApplicationConfigManager can not be null");
Assert.assertTrue(getApplicationConfigManager().isInitialized(), "ApplicationConfigManager can not be initialized");
}
@Override
protected void initialize() {
super.initialize();
internalModule = new ModuleModel(this, true);
this.serviceRepository = new ServiceRepository(this);
ExtensionLoader<ApplicationInitListener> extensionLoader = this.getExtensionLoader(ApplicationInitListener.class);
Set<String> listenerNames = extensionLoader.getSupportedExtensions();
for (String listenerName : listenerNames) {
extensionLoader.getExtension(listenerName).init();
}
initApplicationExts();
ExtensionLoader<ScopeModelInitializer> initializerExtensionLoader = this.getExtensionLoader(ScopeModelInitializer.class);
Set<ScopeModelInitializer> initializers = initializerExtensionLoader.getSupportedExtensionInstances();
for (ScopeModelInitializer initializer : initializers) {
initializer.initializeApplicationModel(this);
}
}
private void initApplicationExts() {
Set<ApplicationExt> exts = this.getExtensionLoader(ApplicationExt.class).getSupportedExtensionInstances();
for (ApplicationExt ext : exts) {
ext.initialize();
}
}
@Override
protected void onDestroy() {
// 1. remove from frameworkModel
frameworkModel.removeApplication(this);
// 2. pre-destroy, set stopping
if (deployer != null) {
// destroy registries and unregister services from registries first to notify consumers to stop consuming this instance.
deployer.preDestroy();
}
// 3. Try to destroy protocols to stop this instance from receiving new requests from connections
frameworkModel.tryDestroyProtocols();
// 4. destroy application resources
for (ModuleModel moduleModel : moduleModels) {
if (moduleModel != internalModule) {
moduleModel.destroy();
}
}
// 5. destroy internal module later
internalModule.destroy();
// 6. post-destroy, release registry resources
if (deployer != null) {
deployer.postDestroy();
}
// 7. destroy other resources (e.g. ZookeeperTransporter )
notifyDestroy();
if (environment != null) {
environment.destroy();
environment = null;
}
if (configManager != null) {
configManager.destroy();
configManager = null;
}
if (serviceRepository != null) {
serviceRepository.destroy();
serviceRepository = null;
}
// 8. destroy framework if none application
frameworkModel.tryDestroy();
}
public FrameworkModel getFrameworkModel() {
return frameworkModel;
}
public ModuleModel newModule() {
return new ModuleModel(this);
}
@Override
public Environment getModelEnvironment() {
if (environment == null) {
environment = (Environment) this.getExtensionLoader(ApplicationExt.class)
.getExtension(Environment.NAME);
}
return environment;
}
public ConfigManager getApplicationConfigManager() {
if (configManager == null) {
configManager = (ConfigManager) this.getExtensionLoader(ApplicationExt.class)
.getExtension(ConfigManager.NAME);
}
return configManager;
}
public ServiceRepository getApplicationServiceRepository() {
return serviceRepository;
}
public ExecutorRepository getApplicationExecutorRepository() {
return ExecutorRepository.getInstance(this);
}
public ApplicationConfig getCurrentConfig() {
return getApplicationConfigManager().getApplicationOrElseThrow();
}
public String getApplicationName() {
return getCurrentConfig().getName();
}
public String tryGetApplicationName() {
Optional<ApplicationConfig> appCfgOptional = getApplicationConfigManager().getApplication();
return appCfgOptional.isPresent() ? appCfgOptional.get().getName() : null;
}
void addModule(ModuleModel moduleModel, boolean isInternal) {
synchronized (moduleLock) {
if (!this.moduleModels.contains(moduleModel)) {
checkDestroyed();
this.moduleModels.add(moduleModel);
moduleModel.setInternalId(buildInternalId(getInternalId(), moduleIndex.getAndIncrement()));
if (!isInternal) {
pubModuleModels.add(moduleModel);
}
}
}
}
public void removeModule(ModuleModel moduleModel) {
synchronized (moduleLock) {
this.moduleModels.remove(moduleModel);
this.pubModuleModels.remove(moduleModel);
if (moduleModel == defaultModule) {
defaultModule = findDefaultModule();
}
}
}
void tryDestroy() {
if (this.moduleModels.isEmpty()
|| (this.moduleModels.size() == 1 && this.moduleModels.get(0) == internalModule)) {
destroy();
}
}
private void checkDestroyed() {
if (isDestroyed()) {
throw new IllegalStateException("ApplicationModel is destroyed");
}
}
public List<ModuleModel> getModuleModels() {
return Collections.unmodifiableList(moduleModels);
}
public List<ModuleModel> getPubModuleModels() {
return Collections.unmodifiableList(pubModuleModels);
}
public ModuleModel getDefaultModule() {
if (defaultModule == null) {
synchronized (moduleLock) {
if (defaultModule == null) {
defaultModule = findDefaultModule();
if (defaultModule == null) {
defaultModule = this.newModule();
}
}
}
}
return defaultModule;
}
private ModuleModel findDefaultModule() {
for (ModuleModel moduleModel : moduleModels) {
if (moduleModel != internalModule) {
return moduleModel;
}
}
return null;
}
public ModuleModel getInternalModule() {
return internalModule;
}
/**
* @deprecated only for ut
*/
@ -423,37 +466,5 @@ public class ApplicationModel extends ScopeModel {
this.serviceRepository = serviceRepository;
}
@Override
public void addClassLoader(ClassLoader classLoader) {
super.addClassLoader(classLoader);
if (environment != null) {
environment.refreshClassLoaders();
}
}
@Override
public void removeClassLoader(ClassLoader classLoader) {
super.removeClassLoader(classLoader);
if (environment != null) {
environment.refreshClassLoaders();
}
}
@Override
protected boolean checkIfClassLoaderCanRemoved(ClassLoader classLoader) {
return super.checkIfClassLoaderCanRemoved(classLoader) && !containsClassLoader(classLoader);
}
protected boolean containsClassLoader(ClassLoader classLoader) {
return moduleModels.stream().anyMatch(moduleModel -> moduleModel.getClassLoaders().contains(classLoader));
}
public ApplicationDeployer getDeployer() {
return deployer;
}
public void setDeployer(ApplicationDeployer deployer) {
this.deployer = deployer;
}
// =============================== Deprecated Methods End =======================================
}

View File

@ -40,111 +40,117 @@ import java.util.stream.Collectors;
*/
public class FrameworkModel extends ScopeModel {
// ========================= Static Fields Start ===================================
protected static final Logger LOGGER = LoggerFactory.getLogger(FrameworkModel.class);
public static final String NAME = "FrameworkModel";
private static final AtomicLong index = new AtomicLong(1);
// internal app index is 0, default app index is 1
private final AtomicLong appIndex = new AtomicLong(0);
private static final Object globalLock = new Object();
private volatile static FrameworkModel defaultInstance;
private static final List<FrameworkModel> allInstances = new CopyOnWriteArrayList<>();
// ========================= Static Fields End ===================================
// internal app index is 0, default app index is 1
private final AtomicLong appIndex = new AtomicLong(0);
private volatile ApplicationModel defaultAppModel;
private static List<FrameworkModel> allInstances = new CopyOnWriteArrayList<>();
private final List<ApplicationModel> applicationModels = new CopyOnWriteArrayList<>();
private List<ApplicationModel> applicationModels = new CopyOnWriteArrayList<>();
private final List<ApplicationModel> pubApplicationModels = new CopyOnWriteArrayList<>();
private List<ApplicationModel> pubApplicationModels = new CopyOnWriteArrayList<>();
private final FrameworkServiceRepository serviceRepository;
private FrameworkServiceRepository serviceRepository;
private ApplicationModel internalApplicationModel;
private final Object instLock = new Object();
private final ApplicationModel internalApplicationModel;
/**
* Use {@link FrameworkModel#newModel()} to create a new model
*/
public FrameworkModel() {
super(null, ExtensionScope.FRAMEWORK, false);
this.setInternalId(String.valueOf(index.getAndIncrement()));
// register FrameworkModel instance early
synchronized (globalLock) {
allInstances.add(this);
resetDefaultFrameworkModel();
synchronized (instLock) {
this.setInternalId(String.valueOf(index.getAndIncrement()));
// register FrameworkModel instance early
allInstances.add(this);
if (LOGGER.isInfoEnabled()) {
LOGGER.info(getDesc() + " is created");
}
initialize();
TypeDefinitionBuilder.initBuilders(this);
serviceRepository = new FrameworkServiceRepository(this);
ExtensionLoader<ScopeModelInitializer> initializerExtensionLoader = this.getExtensionLoader(ScopeModelInitializer.class);
Set<ScopeModelInitializer> initializers = initializerExtensionLoader.getSupportedExtensionInstances();
for (ScopeModelInitializer initializer : initializers) {
initializer.initializeFrameworkModel(this);
}
internalApplicationModel = new ApplicationModel(this, true);
internalApplicationModel.getApplicationConfigManager().setApplication(
new ApplicationConfig(internalApplicationModel, CommonConstants.DUBBO_INTERNAL_APPLICATION));
internalApplicationModel.setModelName(CommonConstants.DUBBO_INTERNAL_APPLICATION);
}
}
if (LOGGER.isInfoEnabled()) {
LOGGER.info(getDesc() + " is created");
}
initialize();
}
@Override
protected void initialize() {
super.initialize();
TypeDefinitionBuilder.initBuilders(this);
serviceRepository = new FrameworkServiceRepository(this);
ExtensionLoader<ScopeModelInitializer> initializerExtensionLoader = this.getExtensionLoader(ScopeModelInitializer.class);
Set<ScopeModelInitializer> initializers = initializerExtensionLoader.getSupportedExtensionInstances();
for (ScopeModelInitializer initializer : initializers) {
initializer.initializeFrameworkModel(this);
}
internalApplicationModel = new ApplicationModel(this, true);
internalApplicationModel.getApplicationConfigManager().setApplication(
new ApplicationConfig(internalApplicationModel, CommonConstants.DUBBO_INTERNAL_APPLICATION));
internalApplicationModel.setModelName(CommonConstants.DUBBO_INTERNAL_APPLICATION);
}
@Override
protected void onDestroy() {
if (defaultInstance == this) {
// NOTE: During destroying the default FrameworkModel, the FrameworkModel.defaultModel() or ApplicationModel.defaultModel()
// will return a broken model, maybe cause unpredictable problem.
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Destroying default framework model: " + getDesc());
synchronized (instLock) {
if (defaultInstance == this) {
// NOTE: During destroying the default FrameworkModel, the FrameworkModel.defaultModel() or ApplicationModel.defaultModel()
// will return a broken model, maybe cause unpredictable problem.
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Destroying default framework model: " + getDesc());
}
}
if (LOGGER.isInfoEnabled()) {
LOGGER.info(getDesc() + " is destroying ...");
}
// destroy all application model
for (ApplicationModel applicationModel : new ArrayList<>(applicationModels)) {
applicationModel.destroy();
}
// check whether all application models are destroyed
checkApplicationDestroy();
// notify destroy and clean framework resources
// see org.apache.dubbo.config.deploy.FrameworkModelCleaner
notifyDestroy();
if (LOGGER.isInfoEnabled()) {
LOGGER.info(getDesc() + " is destroyed");
}
// remove from allInstances and reset default FrameworkModel
synchronized (globalLock) {
allInstances.remove(this);
resetDefaultFrameworkModel();
}
// if all FrameworkModels are destroyed, clean global static resources, shutdown dubbo completely
destroyGlobalResources();
}
if (LOGGER.isInfoEnabled()) {
LOGGER.info(getDesc() + " is destroying ...");
}
// destroy all application model
for (ApplicationModel applicationModel : new ArrayList<>(applicationModels)) {
applicationModel.destroy();
}
// check whether all application models are destroyed
checkApplicationDestroy();
// notify destroy and clean framework resources
// see org.apache.dubbo.config.deploy.FrameworkModelCleaner
notifyDestroy();
if (LOGGER.isInfoEnabled()) {
LOGGER.info(getDesc() + " is destroyed");
}
// remove from allInstances and reset default FrameworkModel
synchronized (globalLock) {
allInstances.remove(this);
resetDefaultFrameworkModel();
}
// if all FrameworkModels are destroyed, clean global static resources, shutdown dubbo completely
destroyGlobalResources();
}
private void checkApplicationDestroy() {
if (applicationModels.size() > 0) {
List<String> remainApplications = applicationModels.stream()
.map(ScopeModel::getDesc)
.collect(Collectors.toList());
throw new IllegalStateException("Not all application models are completely destroyed, remaining " +
remainApplications.size() + " application models may be created during destruction: " + remainApplications);
synchronized (instLock) {
if (applicationModels.size() > 0) {
List<String> remainApplications = applicationModels.stream()
.map(ScopeModel::getDesc)
.collect(Collectors.toList());
throw new IllegalStateException("Not all application models are completely destroyed, remaining " +
remainApplications.size() + " application models may be created during destruction: " + remainApplications);
}
}
}
@ -182,20 +188,26 @@ public class FrameworkModel extends ScopeModel {
* @return
*/
public static List<FrameworkModel> getAllInstances() {
return Collections.unmodifiableList(new ArrayList<>(allInstances));
synchronized (globalLock) {
return Collections.unmodifiableList(new ArrayList<>(allInstances));
}
}
/**
* Destroy all framework model instances, shutdown dubbo engine completely.
*/
public static void destroyAll() {
for (FrameworkModel frameworkModel : new ArrayList<>(allInstances)) {
frameworkModel.destroy();
synchronized (globalLock) {
for (FrameworkModel frameworkModel : new ArrayList<>(allInstances)) {
frameworkModel.destroy();
}
}
}
public ApplicationModel newApplication() {
return new ApplicationModel(this);
synchronized (instLock) {
return new ApplicationModel(this);
}
}
/**
@ -235,7 +247,6 @@ public class FrameworkModel extends ScopeModel {
if (!applicationModel.isInternal()) {
this.pubApplicationModels.add(applicationModel);
}
resetDefaultAppModel();
}
}
}
@ -323,14 +334,18 @@ public class FrameworkModel extends ScopeModel {
* Get all application models except for the internal application model.
*/
public List<ApplicationModel> getApplicationModels() {
return Collections.unmodifiableList(pubApplicationModels);
synchronized (globalLock) {
return Collections.unmodifiableList(pubApplicationModels);
}
}
/**
* Get all application models including the internal application model.
*/
public List<ApplicationModel> getAllApplicationModels() {
return Collections.unmodifiableList(applicationModels);
synchronized (globalLock) {
return Collections.unmodifiableList(applicationModels);
}
}
public ApplicationModel getInternalApplicationModel() {

View File

@ -42,51 +42,50 @@ public class ModuleModel extends ScopeModel {
public static final String NAME = "ModuleModel";
private final ApplicationModel applicationModel;
private ModuleEnvironment moduleEnvironment;
private ModuleServiceRepository serviceRepository;
private ModuleConfigManager moduleConfigManager;
private ModuleDeployer deployer;
private volatile ModuleServiceRepository serviceRepository;
private volatile ModuleEnvironment moduleEnvironment;
private volatile ModuleConfigManager moduleConfigManager;
private volatile ModuleDeployer deployer;
private boolean lifeCycleManagedExternally = false;
public ModuleModel(ApplicationModel applicationModel) {
protected ModuleModel(ApplicationModel applicationModel) {
this(applicationModel, false);
}
public ModuleModel(ApplicationModel applicationModel, boolean isInternal) {
protected ModuleModel(ApplicationModel applicationModel, boolean isInternal) {
super(applicationModel, ExtensionScope.MODULE, isInternal);
Assert.notNull(applicationModel, "ApplicationModel can not be null");
this.applicationModel = applicationModel;
applicationModel.addModule(this, isInternal);
if (LOGGER.isInfoEnabled()) {
LOGGER.info(getDesc() + " is created");
}
synchronized (instLock) {
Assert.notNull(applicationModel, "ApplicationModel can not be null");
this.applicationModel = applicationModel;
applicationModel.addModule(this, isInternal);
if (LOGGER.isInfoEnabled()) {
LOGGER.info(getDesc() + " is created");
}
initialize();
Assert.notNull(getServiceRepository(), "ModuleServiceRepository can not be null");
Assert.notNull(getConfigManager(), "ModuleConfigManager can not be null");
Assert.assertTrue(getConfigManager().isInitialized(), "ModuleConfigManager can not be initialized");
initialize();
// notify application check state
ApplicationDeployer applicationDeployer = applicationModel.getDeployer();
if (applicationDeployer != null) {
applicationDeployer.notifyModuleChanged(this, DeployState.PENDING);
}
}
@Override
protected void initialize() {
super.initialize();
this.serviceRepository = new ModuleServiceRepository(this);
initModuleExt();
ExtensionLoader<ScopeModelInitializer> initializerExtensionLoader = this.getExtensionLoader(ScopeModelInitializer.class);
Set<ScopeModelInitializer> initializers = initializerExtensionLoader.getSupportedExtensionInstances();
for (ScopeModelInitializer initializer : initializers) {
initializer.initializeModuleModel(this);
this.serviceRepository = new ModuleServiceRepository(this);
initModuleExt();
ExtensionLoader<ScopeModelInitializer> initializerExtensionLoader = this.getExtensionLoader(ScopeModelInitializer.class);
Set<ScopeModelInitializer> initializers = initializerExtensionLoader.getSupportedExtensionInstances();
for (ScopeModelInitializer initializer : initializers) {
initializer.initializeModuleModel(this);
}
Assert.notNull(getServiceRepository(), "ModuleServiceRepository can not be null");
Assert.notNull(getConfigManager(), "ModuleConfigManager can not be null");
Assert.assertTrue(getConfigManager().isInitialized(), "ModuleConfigManager can not be initialized");
// notify application check state
ApplicationDeployer applicationDeployer = applicationModel.getDeployer();
if (applicationDeployer != null) {
applicationDeployer.notifyModuleChanged(this, DeployState.PENDING);
}
}
}
// already synchronized in constructor
private void initModuleExt() {
Set<ModuleExt> exts = this.getExtensionLoader(ModuleExt.class).getSupportedExtensionInstances();
for (ModuleExt ext : exts) {
@ -96,39 +95,41 @@ public class ModuleModel extends ScopeModel {
@Override
protected void onDestroy() {
// 1. remove from applicationModel
applicationModel.removeModule(this);
synchronized (instLock) {
// 1. remove from applicationModel
applicationModel.removeModule(this);
// 2. set stopping
if (deployer != null) {
deployer.preDestroy();
// 2. set stopping
if (deployer != null) {
deployer.preDestroy();
}
// 3. release services
if (deployer != null) {
deployer.postDestroy();
}
// destroy other resources
notifyDestroy();
if (serviceRepository != null) {
serviceRepository.destroy();
serviceRepository = null;
}
if (moduleEnvironment != null) {
moduleEnvironment.destroy();
moduleEnvironment = null;
}
if (moduleConfigManager != null) {
moduleConfigManager.destroy();
moduleConfigManager = null;
}
// destroy application if none pub module
applicationModel.tryDestroy();
}
// 3. release services
if (deployer != null) {
deployer.postDestroy();
}
// destroy other resources
notifyDestroy();
if (serviceRepository != null) {
serviceRepository.destroy();
serviceRepository = null;
}
if (moduleEnvironment != null) {
moduleEnvironment.destroy();
moduleEnvironment = null;
}
if (moduleConfigManager != null) {
moduleConfigManager.destroy();
moduleConfigManager = null;
}
// destroy application if none pub module
applicationModel.tryDestroy();
}
public ApplicationModel getApplicationModel() {

View File

@ -28,11 +28,11 @@ import org.apache.dubbo.common.utils.StringUtils;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_UNABLE_DESTROY_MODEL;
@ -62,23 +62,25 @@ public abstract class ScopeModel implements ExtensionAccessor {
private String desc;
private Set<ClassLoader> classLoaders;
private final Set<ClassLoader> classLoaders = new ConcurrentHashSet<>();
private final ScopeModel parent;
private final ExtensionScope scope;
private ExtensionDirector extensionDirector;
private volatile ExtensionDirector extensionDirector;
private ScopeBeanFactory beanFactory;
private List<ScopeModelDestroyListener> destroyListeners;
private volatile ScopeBeanFactory beanFactory;
private final List<ScopeModelDestroyListener> destroyListeners = new CopyOnWriteArrayList<>();
private List<ScopeClassLoaderListener> classLoaderListeners;
private final List<ScopeClassLoaderListener> classLoaderListeners = new CopyOnWriteArrayList<>();
private Map<String, Object> attributes;
private final Map<String, Object> attributes = new ConcurrentHashMap<>();
private final AtomicBoolean destroyed = new AtomicBoolean(false);
private final boolean internalScope;
public ScopeModel(ScopeModel parent, ExtensionScope scope, boolean isInternal) {
protected final Object instLock = new Object();
protected ScopeModel(ScopeModel parent, ExtensionScope scope, boolean isInternal) {
this.parent = parent;
this.scope = scope;
this.internalScope = isInternal;
@ -94,18 +96,16 @@ public abstract class ScopeModel implements ExtensionAccessor {
* </ol>
*/
protected void initialize() {
this.extensionDirector = new ExtensionDirector(parent != null ? parent.getExtensionDirector() : null, scope, this);
this.extensionDirector.addExtensionPostProcessor(new ScopeModelAwareExtensionProcessor(this));
this.beanFactory = new ScopeBeanFactory(parent != null ? parent.getBeanFactory() : null, extensionDirector);
this.destroyListeners = new LinkedList<>();
this.classLoaderListeners = new LinkedList<>();
this.attributes = new ConcurrentHashMap<>();
this.classLoaders = new ConcurrentHashSet<>();
synchronized (instLock) {
this.extensionDirector = new ExtensionDirector(parent != null ? parent.getExtensionDirector() : null, scope, this);
this.extensionDirector.addExtensionPostProcessor(new ScopeModelAwareExtensionProcessor(this));
this.beanFactory = new ScopeBeanFactory(parent != null ? parent.getBeanFactory() : null, extensionDirector);
// Add Framework's ClassLoader by default
ClassLoader dubboClassLoader = ScopeModel.class.getClassLoader();
if (dubboClassLoader != null) {
this.addClassLoader(dubboClassLoader);
// Add Framework's ClassLoader by default
ClassLoader dubboClassLoader = ScopeModel.class.getClassLoader();
if (dubboClassLoader != null) {
this.addClassLoader(dubboClassLoader);
}
}
}
@ -203,22 +203,26 @@ public abstract class ScopeModel implements ExtensionAccessor {
}
public void addClassLoader(ClassLoader classLoader) {
this.classLoaders.add(classLoader);
if (parent != null) {
parent.addClassLoader(classLoader);
synchronized (instLock) {
this.classLoaders.add(classLoader);
if (parent != null) {
parent.addClassLoader(classLoader);
}
extensionDirector.removeAllCachedLoader();
notifyClassLoaderAdd(classLoader);
}
extensionDirector.removeAllCachedLoader();
notifyClassLoaderAdd(classLoader);
}
public void removeClassLoader(ClassLoader classLoader) {
if (checkIfClassLoaderCanRemoved(classLoader)) {
this.classLoaders.remove(classLoader);
if (parent != null) {
parent.removeClassLoader(classLoader);
synchronized (instLock) {
if (checkIfClassLoaderCanRemoved(classLoader)) {
this.classLoaders.remove(classLoader);
if (parent != null) {
parent.removeClassLoader(classLoader);
}
extensionDirector.removeAllCachedLoader();
notifyClassLoaderDestroy(classLoader);
}
extensionDirector.removeAllCachedLoader();
notifyClassLoaderDestroy(classLoader);
}
}

View File

@ -41,8 +41,8 @@ class CommonScopeModelInitializerTest {
@BeforeEach
public void setUp() {
frameworkModel = new FrameworkModel();
applicationModel = new ApplicationModel(frameworkModel);
moduleModel = new ModuleModel(applicationModel);
applicationModel = frameworkModel.newApplication();
moduleModel = applicationModel.newModule();
}
@AfterEach
@ -60,4 +60,4 @@ class CommonScopeModelInitializerTest {
ScopeBeanFactory moduleModelBeanFactory = moduleModel.getBeanFactory();
Assertions.assertNotNull(moduleModelBeanFactory.getBean(ConfigurationCache.class));
}
}
}

View File

@ -36,7 +36,7 @@ class ConfigurationUtilsTest {
void testCachedProperties() {
FrameworkModel frameworkModel = new FrameworkModel();
ApplicationModel applicationModel = new ApplicationModel(frameworkModel);
ApplicationModel applicationModel = frameworkModel.newApplication();
Environment originApplicationEnvironment = applicationModel.getModelEnvironment();
Environment applicationEnvironment = Mockito.spy(originApplicationEnvironment);
applicationModel.setEnvironment(applicationEnvironment);
@ -51,7 +51,7 @@ class ConfigurationUtilsTest {
// cached key
Assertions.assertEquals("a", ConfigurationUtils.getCachedDynamicProperty(applicationModel, "TestKey", "xxx"));
ModuleModel moduleModel = new ModuleModel(applicationModel);
ModuleModel moduleModel = applicationModel.newModule();
ModuleEnvironment originModuleEnvironment = moduleModel.getModelEnvironment();
ModuleEnvironment moduleEnvironment = Mockito.spy(originModuleEnvironment);
moduleModel.setModuleEnvironment(moduleEnvironment);
@ -109,4 +109,4 @@ class ConfigurationUtilsTest {
Assertions.assertEquals(1, result.size());
Assertions.assertEquals("zookeeper://127.0.0.1:2181\\ndubbo.protocol.port=20880", result.get("dubbo.registry.address"));
}
}
}

View File

@ -64,7 +64,7 @@ class EnvironmentTest {
@Test
void test() {
FrameworkModel frameworkModel = new FrameworkModel();
ApplicationModel applicationModel = new ApplicationModel(frameworkModel);
ApplicationModel applicationModel = frameworkModel.newApplication();
Environment environment = applicationModel.getModelEnvironment();
// test getPrefixedConfiguration
@ -112,4 +112,4 @@ class EnvironmentTest {
frameworkModel.destroy();
}
}
}

View File

@ -90,8 +90,8 @@ class ExtensionDirectorTest {
// 3. Framework scope SPI can be injected FrameworkModel, but not ModuleModel, ApplicationModel
FrameworkModel frameworkModel = new FrameworkModel();
ApplicationModel applicationModel = new ApplicationModel(frameworkModel);
ModuleModel moduleModel = new ModuleModel(applicationModel);
ApplicationModel applicationModel = frameworkModel.newApplication();
ModuleModel moduleModel = applicationModel.newModule();
ExtensionDirector moduleExtensionDirector = moduleModel.getExtensionDirector();
ExtensionDirector appExtensionDirector = applicationModel.getExtensionDirector();
@ -152,16 +152,16 @@ class ExtensionDirectorTest {
// moduleModel211
FrameworkModel frameworkModel1 = new FrameworkModel();
ApplicationModel applicationModel11 = new ApplicationModel(frameworkModel1);
ModuleModel moduleModel111 = new ModuleModel(applicationModel11);
ModuleModel moduleModel112 = new ModuleModel(applicationModel11);
ApplicationModel applicationModel11 = frameworkModel1.newApplication();
ModuleModel moduleModel111 = applicationModel11.newModule();
ModuleModel moduleModel112 = applicationModel11.newModule();
ApplicationModel applicationModel12 = new ApplicationModel(frameworkModel1);
ModuleModel moduleModel121 = new ModuleModel(applicationModel12);
ApplicationModel applicationModel12 = frameworkModel1.newApplication();
ModuleModel moduleModel121 = applicationModel12.newModule();
FrameworkModel frameworkModel2 = new FrameworkModel();
ApplicationModel applicationModel21 = new ApplicationModel(frameworkModel2);
ModuleModel moduleModel211 = new ModuleModel(applicationModel21);
ApplicationModel applicationModel21 = frameworkModel2.newApplication();
ModuleModel moduleModel211 = applicationModel21.newModule();
// test model references
Collection<ApplicationModel> applicationsOfFw1 = frameworkModel1.getApplicationModels();
@ -235,8 +235,8 @@ class ExtensionDirectorTest {
// 3. Module scope extension can be injected to extensions of Module scope, but not Framework/Application scope
FrameworkModel frameworkModel = new FrameworkModel();
ApplicationModel applicationModel = new ApplicationModel(frameworkModel);
ModuleModel moduleModel = new ModuleModel(applicationModel);
ApplicationModel applicationModel = frameworkModel.newApplication();
ModuleModel moduleModel = applicationModel.newModule();
// check module service
TestModuleService moduleService = (TestModuleService) moduleModel.getExtensionDirector()
@ -272,4 +272,4 @@ class ExtensionDirectorTest {
Assertions.assertTrue(appService.isDestroyed());
Assertions.assertTrue(frameworkService.isDestroyed());
}
}
}

View File

@ -56,4 +56,4 @@ class AdaptiveExtensionInjectorTest {
frameworkModel.destroy();
}
}
}

View File

@ -41,7 +41,7 @@ class FrameworkStatusReportServiceTest {
@Test
void test() {
FrameworkModel frameworkModel = new FrameworkModel();
ApplicationModel applicationModel = new ApplicationModel(frameworkModel);
ApplicationModel applicationModel = frameworkModel.newApplication();
ApplicationConfig app = new ApplicationConfig("APP");
applicationModel.getApplicationConfigManager().setApplication(app);
FrameworkStatusReportService reportService = applicationModel.getBeanFactory().getBean(FrameworkStatusReportService.class);
@ -103,4 +103,4 @@ class FrameworkStatusReportServiceTest {
frameworkModel.destroy();
}
}
}

View File

@ -40,7 +40,7 @@ class ApplicationModelTest {
@Test
void testInitialize() {
FrameworkModel frameworkModel = new FrameworkModel();
ApplicationModel applicationModel = new ApplicationModel(frameworkModel);
ApplicationModel applicationModel = frameworkModel.newApplication();
Assertions.assertEquals(applicationModel.getParent(), frameworkModel);
Assertions.assertEquals(applicationModel.getScope(), ExtensionScope.APPLICATION);
@ -82,7 +82,7 @@ class ApplicationModelTest {
@Test
void testModule() {
FrameworkModel frameworkModel = new FrameworkModel();
ApplicationModel applicationModel = new ApplicationModel(frameworkModel);
ApplicationModel applicationModel = frameworkModel.newApplication();
ModuleModel defaultModule = applicationModel.getDefaultModule();
ModuleModel internalModule = applicationModel.getInternalModule();
@ -106,7 +106,7 @@ class ApplicationModelTest {
applicationModel.getFrameworkModel().destroy();
FrameworkModel frameworkModel = new FrameworkModel();
ApplicationModel applicationModel1 = new ApplicationModel(frameworkModel);
ApplicationModel applicationModel1 = frameworkModel.newApplication();
ApplicationModel applicationModel2 = ApplicationModel.ofNullable(applicationModel1);
Assertions.assertEquals(applicationModel1, applicationModel2);
frameworkModel.destroy();
@ -115,7 +115,7 @@ class ApplicationModelTest {
@Test
void testDestroy() {
FrameworkModel frameworkModel = new FrameworkModel();
ApplicationModel applicationModel = new ApplicationModel(frameworkModel);
ApplicationModel applicationModel = frameworkModel.newApplication();
applicationModel.getDefaultModule();
applicationModel.newModule();

View File

@ -105,4 +105,4 @@ class FrameworkModelTest {
}
}
}
}

View File

@ -43,8 +43,8 @@ class FrameworkServiceRepositoryTest {
@BeforeEach
public void setUp() {
frameworkModel = new FrameworkModel();
applicationModel = new ApplicationModel(frameworkModel);
moduleModel = new ModuleModel(applicationModel);
applicationModel = frameworkModel.newApplication();
moduleModel = applicationModel.newModule();
}
@AfterEach
@ -111,4 +111,4 @@ class FrameworkServiceRepositoryTest {
}
return interfaceName + ":" + version;
}
}
}

View File

@ -33,8 +33,8 @@ class ModuleModelTest {
@Test
void testInitialize() {
FrameworkModel frameworkModel = new FrameworkModel();
ApplicationModel applicationModel = new ApplicationModel(frameworkModel);
ModuleModel moduleModel = new ModuleModel(applicationModel);
ApplicationModel applicationModel = frameworkModel.newApplication();
ModuleModel moduleModel = applicationModel.newModule();
Assertions.assertEquals(moduleModel.getParent(), applicationModel);
Assertions.assertEquals(moduleModel.getScope(), ExtensionScope.MODULE);
Assertions.assertEquals(moduleModel.getApplicationModel(), applicationModel);
@ -58,8 +58,8 @@ class ModuleModelTest {
@Test
void testModelEnvironment() {
FrameworkModel frameworkModel = new FrameworkModel();
ApplicationModel applicationModel = new ApplicationModel(frameworkModel);
ModuleModel moduleModel = new ModuleModel(applicationModel);
ApplicationModel applicationModel = frameworkModel.newApplication();
ModuleModel moduleModel = applicationModel.newModule();
ModuleEnvironment modelEnvironment = moduleModel.getModelEnvironment();
Assertions.assertNotNull(modelEnvironment);
@ -70,8 +70,8 @@ class ModuleModelTest {
@Test
void testDestroy() {
FrameworkModel frameworkModel = new FrameworkModel();
ApplicationModel applicationModel = new ApplicationModel(frameworkModel);
ModuleModel moduleModel = new ModuleModel(applicationModel);
ApplicationModel applicationModel = frameworkModel.newApplication();
ModuleModel moduleModel = applicationModel.newModule();
MockScopeModelDestroyListener destroyListener = new MockScopeModelDestroyListener();
moduleModel.addDestroyListener(destroyListener);
@ -88,4 +88,4 @@ class ModuleModelTest {
Assertions.assertTrue(frameworkModel.isDestroyed());
}
}
}

View File

@ -39,8 +39,8 @@ class ModuleServiceRepositoryTest {
@BeforeEach
public void setUp() {
frameworkModel = new FrameworkModel();
applicationModel = new ApplicationModel(frameworkModel);
moduleModel = new ModuleModel(applicationModel);
applicationModel = frameworkModel.newApplication();
moduleModel = applicationModel.newModule();
}
@AfterEach
@ -111,4 +111,4 @@ class ModuleServiceRepositoryTest {
Assertions.assertTrue(repository.getExportedServices().isEmpty());
Assertions.assertTrue(frameworkModel.getServiceRepository().allProviderModels().isEmpty());
}
}
}

View File

@ -96,4 +96,4 @@ class ReflectionServiceDescriptorTest {
DemoService.class);
Assertions.assertEquals(service2.hashCode(), service3.hashCode());
}
}
}

View File

@ -34,8 +34,8 @@ class ScopeModelAwareExtensionProcessorTest {
@BeforeEach
public void setUp() {
frameworkModel = new FrameworkModel();
applicationModel = new ApplicationModel(frameworkModel);
moduleModel = new ModuleModel(applicationModel);
applicationModel = frameworkModel.newApplication();
moduleModel = applicationModel.newModule();
}
@AfterEach
@ -76,4 +76,4 @@ class ScopeModelAwareExtensionProcessorTest {
Assertions.assertEquals(mockScopeModelAware.getApplicationModel(), applicationModel);
Assertions.assertEquals(mockScopeModelAware.getModuleModel(), moduleModel);
}
}
}

View File

@ -109,4 +109,4 @@ class ScopeModelTest {
List<String> remainFrameworks = FrameworkModel.getAllInstances().stream().map(m -> m.getDesc()).collect(Collectors.toList());
Assertions.assertEquals(0, FrameworkModel.getAllInstances().size(), "FrameworkModel is not completely destroyed: " + remainFrameworks);
}
}
}

View File

@ -36,8 +36,8 @@ class ScopeModelUtilTest {
@BeforeEach
public void setUp() {
frameworkModel = new FrameworkModel();
applicationModel = new ApplicationModel(frameworkModel);
moduleModel = new ModuleModel(applicationModel);
applicationModel = frameworkModel.newApplication();
moduleModel = applicationModel.newModule();
}
@AfterEach
@ -111,4 +111,4 @@ class ScopeModelUtilTest {
}
}
}
}

View File

@ -40,8 +40,8 @@ class ServiceRepositoryTest {
@BeforeEach
public void setUp() {
frameworkModel = new FrameworkModel();
applicationModel = new ApplicationModel(frameworkModel);
moduleModel = new ModuleModel(applicationModel);
applicationModel = frameworkModel.newApplication();
moduleModel = applicationModel.newModule();
}
@AfterEach
@ -88,4 +88,4 @@ class ServiceRepositoryTest {
}
}
}

View File

@ -33,8 +33,8 @@ class ConfigScopeModelInitializerTest {
@BeforeEach
public void setUp() {
frameworkModel = new FrameworkModel();
applicationModel = new ApplicationModel(frameworkModel);
moduleModel = new ModuleModel(applicationModel);
applicationModel = frameworkModel.newApplication();
moduleModel = applicationModel.newModule();
}
@AfterEach
@ -47,4 +47,4 @@ class ConfigScopeModelInitializerTest {
Assertions.assertNotNull(applicationModel.getDeployer());
Assertions.assertNotNull(moduleModel.getDeployer());
}
}
}

View File

@ -966,9 +966,9 @@ class ReferenceConfigTest {
@Test
void testDifferentClassLoader() throws Exception {
ApplicationConfig applicationConfig = new ApplicationConfig("TestApp");
ApplicationModel applicationModel = new ApplicationModel(FrameworkModel.defaultModel());
ApplicationModel applicationModel = ApplicationModel.defaultModel();
applicationModel.getApplicationConfigManager().setApplication(applicationConfig);
ModuleModel moduleModel = new ModuleModel(applicationModel);
ModuleModel moduleModel = applicationModel.newModule();
DemoService demoService = new DemoServiceImpl();
ServiceConfig<DemoService> serviceConfig = new ServiceConfig<>();
@ -1047,9 +1047,9 @@ class ReferenceConfigTest {
TestClassLoader2 classLoader3 = new TestClassLoader2(classLoader2, basePath);
ApplicationConfig applicationConfig = new ApplicationConfig("TestApp");
ApplicationModel applicationModel = new ApplicationModel(frameworkModel);
ApplicationModel applicationModel = frameworkModel.newApplication();
applicationModel.getApplicationConfigManager().setApplication(applicationConfig);
ModuleModel moduleModel = new ModuleModel(applicationModel);
ModuleModel moduleModel = applicationModel.newModule();
Class<?> clazz1 = classLoader1.loadClass(MultiClassLoaderService.class.getName(), false);
Class<?> clazz1impl = classLoader1.loadClass(MultiClassLoaderServiceImpl.class.getName(), false);

View File

@ -739,7 +739,7 @@ class MultiInstanceTest {
// consumer app
ApplicationModel consumerApplicationModel = new ApplicationModel(FrameworkModel.defaultModel());
ApplicationModel consumerApplicationModel = ApplicationModel.defaultModel();
ReferenceConfig<DemoService> referenceConfig = new ReferenceConfig<>();
referenceConfig.setScopeModel(consumerApplicationModel.getDefaultModule());
referenceConfig.setApplication(new ApplicationConfig("consumer-app"));

View File

@ -58,7 +58,7 @@ class InvokeTelnetTest {
mockChannel = mock(Channel.class);
mockCommandContext = mock(CommandContext.class);
given(mockCommandContext.getRemote()).willReturn(mockChannel);
ApplicationModel applicationModel = new ApplicationModel(frameworkModel);
ApplicationModel applicationModel = frameworkModel.newApplication();
repository = applicationModel.getDefaultModule().getServiceRepository();
}
@ -267,4 +267,4 @@ class InvokeTelnetTest {
null
);
}
}
}

View File

@ -50,4 +50,4 @@ class LiveTest {
Assertions.assertEquals(result, "true");
Assertions.assertEquals(commandContext.getHttpCode(), 200);
}
}
}

View File

@ -100,4 +100,4 @@ class LsTest {
serviceMetadata, methodConfigs, referenceConfig.getInterfaceClassLoader());
repository.registerConsumer(consumerModel);
}
}
}

View File

@ -100,4 +100,4 @@ class OfflineTest {
);
repository.registerProvider(providerModel);
}
}
}

View File

@ -100,4 +100,4 @@ class OnlineTest {
);
repository.registerProvider(providerModel);
}
}
}

View File

@ -68,4 +68,4 @@ class PublishMetadataTest {
Assertions.assertEquals(result, expectResult);
}
}
}

View File

@ -19,6 +19,7 @@ package org.apache.dubbo.qos.command.impl;
import org.apache.dubbo.common.utils.SerializeSecurityManager;
import org.apache.dubbo.qos.command.CommandContext;
import org.apache.dubbo.rpc.model.FrameworkModel;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

View File

@ -19,6 +19,7 @@ package org.apache.dubbo.qos.command.impl;
import org.apache.dubbo.common.utils.SerializeSecurityManager;
import org.apache.dubbo.qos.command.CommandContext;
import org.apache.dubbo.rpc.model.FrameworkModel;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

View File

@ -19,6 +19,7 @@ package org.apache.dubbo.qos.command.util;
import org.apache.dubbo.common.utils.SerializeCheckStatus;
import org.apache.dubbo.common.utils.SerializeSecurityManager;
import org.apache.dubbo.rpc.model.FrameworkModel;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

View File

@ -32,6 +32,8 @@ import org.apache.dubbo.metadata.report.MetadataReport;
import org.apache.dubbo.metadata.report.MetadataReportInstance;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.model.FrameworkModel;
import org.checkerframework.checker.units.qual.A;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -58,7 +60,7 @@ class MetadataServiceNameMappingTest {
@BeforeEach
public void setUp() {
applicationModel = new ApplicationModel(FrameworkModel.defaultModel());
applicationModel = ApplicationModel.defaultModel();
configManager = mock(ConfigManager.class);
metadataReport = mock(MetadataReport.class);
metadataReportList.put("default", metadataReport);

View File

@ -66,7 +66,7 @@ class DecodeableRpcInvocationTest {
ChannelBuffer buffer = writeBuffer(url, inv, proto);
FrameworkModel frameworkModel = new FrameworkModel();
ApplicationModel applicationModel = new ApplicationModel(frameworkModel);
ApplicationModel applicationModel = frameworkModel.newApplication();
applicationModel.getDefaultModule().getServiceRepository().registerService(DemoService.class.getName(), DemoService.class);
frameworkModel.getServiceRepository().registerProviderUrl(url);

View File

@ -27,7 +27,6 @@ import org.apache.dubbo.rpc.Protocol;
import org.apache.dubbo.rpc.ProxyFactory;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.model.ConsumerModel;
import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.model.ModuleModel;
import org.apache.dubbo.rpc.model.ProviderModel;
import org.apache.dubbo.rpc.model.ServiceDescriptor;
@ -62,9 +61,9 @@ class InjvmClassLoaderTest {
TestClassLoader2 classLoader3 = new TestClassLoader2(classLoader2, basePath);
ApplicationConfig applicationConfig = new ApplicationConfig("TestApp");
ApplicationModel applicationModel = new ApplicationModel(FrameworkModel.defaultModel());
ApplicationModel applicationModel = ApplicationModel.defaultModel();
applicationModel.getApplicationConfigManager().setApplication(applicationConfig);
ModuleModel moduleModel = new ModuleModel(applicationModel);
ModuleModel moduleModel = applicationModel.newModule();
Class clazz1 = classLoader1.loadClass(MultiClassLoaderService.class.getName(), false);
Class<?> clazz1impl = classLoader1.loadClass(MultiClassLoaderServiceImpl.class.getName(), false);

View File

@ -25,7 +25,6 @@ import org.apache.dubbo.rpc.Protocol;
import org.apache.dubbo.rpc.ProxyFactory;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.model.ConsumerModel;
import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.model.ModuleModel;
import org.apache.dubbo.rpc.model.ProviderModel;
import org.apache.dubbo.rpc.model.ServiceDescriptor;
@ -40,7 +39,7 @@ class InjvmDeepCopyTest {
@Test
void testDeepCopy() {
ApplicationModel applicationModel = new ApplicationModel(FrameworkModel.defaultModel());
ApplicationModel applicationModel = ApplicationModel.defaultModel();
applicationModel.getApplicationConfigManager().setApplication(new ApplicationConfig("TestInjvm"));
ModuleModel moduleModel = applicationModel.newModule();

View File

@ -16,12 +16,12 @@
*/
package org.apache.dubbo.rpc.protocol.tri.service;
import io.grpc.health.v1.DubboHealthTriple;
import org.apache.dubbo.rpc.PathResolver;
import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.model.ModuleServiceRepository;
import org.apache.dubbo.rpc.stub.StubSuppliers;
import io.grpc.health.v1.DubboHealthTriple;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;