Skip to content

Commit

Permalink
Rename getModelEnvironment to modelEnvironment
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbumenJ committed Jun 18, 2023
1 parent 5f39404 commit f07d3b1
Show file tree
Hide file tree
Showing 30 changed files with 111 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public String getRule(String key, String group, long timeout) throws IllegalStat
}

private DynamicConfiguration getDynamicConfiguration() {
return moduleModel.getModelEnvironment().getDynamicConfiguration().orElse(null);
return moduleModel.modelEnvironment().getDynamicConfiguration().orElse(null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class ShortestResponseLoadBalance extends AbstractLoadBalance implements

@Override
public void setApplicationModel(ApplicationModel applicationModel) {
slidePeriod = applicationModel.getModelEnvironment().getConfiguration().getInt(Constants.SHORTEST_RESPONSE_SLIDE_PERIOD, 30_000);
slidePeriod = applicationModel.modelEnvironment().getConfiguration().getInt(Constants.SHORTEST_RESPONSE_SLIDE_PERIOD, 30_000);
executorService = applicationModel.getFrameworkModel().getBeanFactory()
.getBean(FrameworkExecutorRepository.class).getSharedExecutor();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private ConfigurationUtils() {
* @return
*/
public static Configuration getSystemConfiguration(ScopeModel scopeModel) {
return getScopeModelOrDefaultApplicationModel(scopeModel).getModelEnvironment().getSystemConfiguration();
return getScopeModelOrDefaultApplicationModel(scopeModel).modelEnvironment().getSystemConfiguration();
}

/**
Expand All @@ -86,7 +86,7 @@ public static Configuration getSystemConfiguration(ScopeModel scopeModel) {
* @return
*/
public static Configuration getEnvConfiguration(ScopeModel scopeModel) {
return getScopeModelOrDefaultApplicationModel(scopeModel).getModelEnvironment().getEnvironmentConfiguration();
return getScopeModelOrDefaultApplicationModel(scopeModel).modelEnvironment().getEnvironmentConfiguration();
}

/**
Expand All @@ -98,11 +98,11 @@ public static Configuration getEnvConfiguration(ScopeModel scopeModel) {
*/

public static Configuration getGlobalConfiguration(ScopeModel scopeModel) {
return getScopeModelOrDefaultApplicationModel(scopeModel).getModelEnvironment().getConfiguration();
return getScopeModelOrDefaultApplicationModel(scopeModel).modelEnvironment().getConfiguration();
}

public static Configuration getDynamicGlobalConfiguration(ScopeModel scopeModel) {
return scopeModel.getModelEnvironment().getDynamicGlobalConfiguration();
return scopeModel.modelEnvironment().getDynamicGlobalConfiguration();
}

// FIXME
Expand Down Expand Up @@ -365,7 +365,7 @@ public static DynamicConfigurationFactory getDynamicConfigurationFactory(Extensi
*/
@Deprecated
public static Configuration getSystemConfiguration() {
return ApplicationModel.defaultModel().getModelEnvironment().getSystemConfiguration();
return ApplicationModel.defaultModel().modelEnvironment().getSystemConfiguration();
}

/**
Expand All @@ -375,7 +375,7 @@ public static Configuration getSystemConfiguration() {
*/
@Deprecated
public static Configuration getEnvConfiguration() {
return ApplicationModel.defaultModel().getModelEnvironment().getEnvironmentConfiguration();
return ApplicationModel.defaultModel().modelEnvironment().getEnvironmentConfiguration();
}

/**
Expand All @@ -385,7 +385,7 @@ public static Configuration getEnvConfiguration() {
*/
@Deprecated
public static Configuration getGlobalConfiguration() {
return ApplicationModel.defaultModel().getModelEnvironment().getConfiguration();
return ApplicationModel.defaultModel().modelEnvironment().getConfiguration();
}

/**
Expand All @@ -395,7 +395,7 @@ public static Configuration getGlobalConfiguration() {
*/
@Deprecated
public static Configuration getDynamicGlobalConfiguration() {
return ApplicationModel.defaultModel().getDefaultModule().getModelEnvironment().getDynamicGlobalConfiguration();
return ApplicationModel.defaultModel().getDefaultModule().modelEnvironment().getDynamicGlobalConfiguration();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class ModuleEnvironment extends Environment implements ModuleExt {
public ModuleEnvironment(ModuleModel moduleModel) {
super(moduleModel);
this.moduleModel = moduleModel;
this.applicationDelegate = moduleModel.getApplicationModel().getModelEnvironment();
this.applicationDelegate = moduleModel.getApplicationModel().modelEnvironment();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ public void refresh() {
}

protected void refreshWithPrefixes(List<String> prefixes, ConfigMode configMode) {
Environment environment = getScopeModel().getModelEnvironment();
Environment environment = getScopeModel().modelEnvironment();
List<Map<String, String>> configurationMaps = environment.getConfigurationMaps();

// Search props starts with PREFIX in order
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ protected String[] methods(Class<?> interfaceClass) {
}

protected Environment getEnvironment() {
return getScopeModel().getModelEnvironment();
return getScopeModel().modelEnvironment();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ protected void processExtraRefresh(String preferredPrefix, InmemoryConfiguration
private void refreshArgument(ArgumentConfig argument, InmemoryConfiguration subPropsConfiguration) {
if (argument.getIndex() != null && argument.getIndex() >= 0) {
String prefix = argument.getIndex() + ".";
Environment environment = getScopeModel().getModelEnvironment();
Environment environment = getScopeModel().modelEnvironment();
List<java.lang.reflect.Method> methods = MethodUtils.getMethods(argument.getClass(),
method -> method.getDeclaringClass() != Object.class);
for (java.lang.reflect.Method method : methods) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ public AbstractConfigManager(ScopeModel scopeModel, Collection<Class<? extends A
this.scopeModel = scopeModel;
this.applicationModel = ScopeModelUtil.getApplicationModel(scopeModel);
this.supportedConfigTypes = supportedConfigTypes;
environment = scopeModel.getModelEnvironment();
environment = scopeModel.modelEnvironment();
}

@Override
public void initialize() throws IllegalStateException {
if (!initialized.compareAndSet(false, true)) {
return;
}
CompositeConfiguration configuration = scopeModel.getModelEnvironment().getConfiguration();
CompositeConfiguration configuration = scopeModel.modelEnvironment().getConfiguration();

// dubbo.config.mode
String configModeStr = (String) configuration.getProperty(ConfigKeys.DUBBO_CONFIG_MODE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public ModuleModel newModule() {
}

@Override
public Environment getModelEnvironment() {
public Environment modelEnvironment() {
if (environment == null) {
environment = (Environment) this.getExtensionLoader(ApplicationExt.class)
.getExtension(Environment.NAME);
Expand Down Expand Up @@ -390,11 +390,11 @@ public static ConsumerModel getConsumerModel(String serviceKey) {
}

/**
* @deprecated Replace to {@link ScopeModel#getModelEnvironment()}
* @deprecated Replace to {@link ScopeModel#modelEnvironment()}
*/
@Deprecated
public static Environment getEnvironment() {
return defaultModel().getModelEnvironment();
return defaultModel().modelEnvironment();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ protected Lock acquireDestroyLock() {
}

@Override
public Environment getModelEnvironment() {
public Environment modelEnvironment() {
throw new UnsupportedOperationException("Environment is inaccessible for FrameworkModel");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void addClassLoader(ClassLoader classLoader) {
}

@Override
public ModuleEnvironment getModelEnvironment() {
public ModuleEnvironment modelEnvironment() {
if (moduleEnvironment == null) {
moduleEnvironment = (ModuleEnvironment) this.getExtensionLoader(ModuleExt.class)
.getExtension(ModuleEnvironment.NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,28 @@ public Set<ClassLoader> getClassLoaders() {
return Collections.unmodifiableSet(classLoaders);
}

public abstract Environment getModelEnvironment();
/**
* Get current model's environment.
* </br>
* Note: This method should not start with `get` or it would be invoked due to Spring boot refresh.
* @see <a href="https://github.com/apache/dubbo/issues/12542">Configuration refresh issue</a>
*/
public abstract Environment modelEnvironment();

/**
* Get current model's environment.
*
* @see <a href="https://github.com/apache/dubbo/issues/12542">Configuration refresh issue</a>
* @deprecated use modelEnvironment() instead
*/
@Deprecated
public final Environment getModelEnvironment() {
try {
return modelEnvironment();
} catch (Exception ex) {
return null;
}
}

public String getInternalId() {
return this.internalId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void testCachedProperties() {
FrameworkModel frameworkModel = new FrameworkModel();

ApplicationModel applicationModel = frameworkModel.newApplication();
Environment originApplicationEnvironment = applicationModel.getModelEnvironment();
Environment originApplicationEnvironment = applicationModel.modelEnvironment();
Environment applicationEnvironment = Mockito.spy(originApplicationEnvironment);
applicationModel.setEnvironment(applicationEnvironment);

Expand All @@ -52,7 +52,7 @@ void testCachedProperties() {
Assertions.assertEquals("a", ConfigurationUtils.getCachedDynamicProperty(applicationModel, "TestKey", "xxx"));

ModuleModel moduleModel = applicationModel.newModule();
ModuleEnvironment originModuleEnvironment = moduleModel.getModelEnvironment();
ModuleEnvironment originModuleEnvironment = moduleModel.modelEnvironment();
ModuleEnvironment moduleEnvironment = Mockito.spy(originModuleEnvironment);
moduleModel.setModuleEnvironment(moduleEnvironment);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class EnvironmentTest {

@Test
void testResolvePlaceholders() {
Environment environment = ApplicationModel.defaultModel().getModelEnvironment();
Environment environment = ApplicationModel.defaultModel().modelEnvironment();

Map<String, String> externalMap = new LinkedHashMap<>();
externalMap.put("zookeeper.address", "127.0.0.1");
Expand All @@ -65,7 +65,7 @@ void testResolvePlaceholders() {
void test() {
FrameworkModel frameworkModel = new FrameworkModel();
ApplicationModel applicationModel = frameworkModel.newApplication();
Environment environment = applicationModel.getModelEnvironment();
Environment environment = applicationModel.modelEnvironment();

// test getPrefixedConfiguration
RegistryConfig registryConfig = new RegistryConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void testModelEnvironment() {
ApplicationModel applicationModel = frameworkModel.newApplication();
ModuleModel moduleModel = applicationModel.newModule();

ModuleEnvironment modelEnvironment = moduleModel.getModelEnvironment();
ModuleEnvironment modelEnvironment = moduleModel.modelEnvironment();
Assertions.assertNotNull(modelEnvironment);

frameworkModel.destroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected void onDestroy() {
}

@Override
public Environment getModelEnvironment() {
public Environment modelEnvironment() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public static void reset(boolean destroy) {
private DubboBootstrap(ApplicationModel applicationModel) {
this.applicationModel = applicationModel;
configManager = applicationModel.getApplicationConfigManager();
environment = applicationModel.getModelEnvironment();
environment = applicationModel.modelEnvironment();

executorRepository = ExecutorRepository.getInstance(applicationModel);
applicationDeployer = applicationModel.getDeployer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public DefaultApplicationDeployer(ApplicationModel applicationModel) {
super(applicationModel);
this.applicationModel = applicationModel;
configManager = applicationModel.getApplicationConfigManager();
environment = applicationModel.getModelEnvironment();
environment = applicationModel.modelEnvironment();

referenceCache = new CompositeReferenceCache(applicationModel);
frameworkExecutorRepository = applicationModel.getFrameworkModel().getBeanFactory().getBean(FrameworkExecutorRepository.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ public static void validateApplicationConfig(ApplicationConfig config) {

// backward compatibility
ScopeModel scopeModel = ScopeModelUtil.getOrDefaultApplicationModel(config.getScopeModel());
PropertiesConfiguration configuration = scopeModel.getModelEnvironment().getPropertiesConfiguration();
PropertiesConfiguration configuration = scopeModel.modelEnvironment().getPropertiesConfiguration();
String wait = configuration.getProperty(SHUTDOWN_WAIT_KEY);
if (wait != null && wait.trim().length() > 0) {
System.setProperty(SHUTDOWN_WAIT_KEY, wait.trim());
Expand Down
Loading

0 comments on commit f07d3b1

Please sign in to comment.