use of com.tencent.polaris.api.plugin.TypeProvider in project polaris-java by polarismesh.
the class SDKContext method initContextByConfig.
/**
* 通过配置对象初始化SDK上下文
*
* @param config 配置对象
* @return SDK上下文
* @throws PolarisException 初始化过程的异常
*/
public static SDKContext initContextByConfig(Configuration config) throws PolarisException {
try {
((ConfigurationImpl) config).setDefault();
config.verify();
} catch (IllegalArgumentException e) {
throw new PolarisException(ErrorCode.INVALID_CONFIG, "fail to verify configuration", e);
}
ServiceLoader<TypeProvider> providers = ServiceLoader.load(TypeProvider.class);
List<PluginType> types = new ArrayList<>();
for (TypeProvider provider : providers) {
types.addAll(provider.getTypes());
}
PluginManager manager = new PluginManager(types);
ValueContext valueContext = new ValueContext();
valueContext.setHost(parseHost(config));
valueContext.setServerConnectorProtocol(parseServerConnectorProtocol(config));
SDKContext initContext = new SDKContext(config, manager, valueContext);
try {
manager.initPlugins(initContext);
} catch (Throwable e) {
manager.destroyPlugins();
if (e instanceof PolarisException) {
throw e;
}
throw new PolarisException(ErrorCode.PLUGIN_ERROR, "plugin error", e);
}
return initContext;
}
Aggregations