Make sure module provider can't find other service in prepare stage. (#994)

This commit is contained in:
吴晟 Wu Sheng 2018-03-28 09:53:11 +08:00 committed by GitHub
parent aa9243b2aa
commit 4a8372b9f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 1 deletions

View File

@ -16,7 +16,6 @@
*
*/
package org.apache.skywalking.apm.collector.core.module;
import java.util.Arrays;
@ -31,6 +30,7 @@ import java.util.ServiceLoader;
* @author wu-sheng, peng-yongsheng
*/
public class ModuleManager {
private boolean isInPrepareStage = true;
private Map<String, Module> loadedModules = new HashMap<>();
/**
@ -60,6 +60,8 @@ public class ModuleManager {
}
}
}
// Finish prepare stage
isInPrepareStage = false;
if (moduleList.size() > 0) {
throw new ModuleNotFoundException(moduleList.toString() + " missing.");
@ -76,9 +78,16 @@ public class ModuleManager {
}
public Module find(String moduleName) throws ModuleNotFoundRuntimeException {
assertPreparedStage();
Module module = loadedModules.get(moduleName);
if (module != null)
return module;
throw new ModuleNotFoundRuntimeException(moduleName + " missing.");
}
private void assertPreparedStage() {
if (isInPrepareStage) {
throw new AssertionError("Still in preparing stage.");
}
}
}