use of com.tencent.polaris.api.plugin.Plugin in project polaris-java by polarismesh.
the class InMemoryRegistry method reportCircuitStat.
private void reportCircuitStat(Entry<StatusDimension, CircuitBreakerStatus> dimensionEntry, Instance instance) {
if (null != statPlugins) {
try {
for (Plugin statPlugin : statPlugins) {
if (statPlugin instanceof StatReporter) {
StatInfo info = new StatInfo();
info.setCircuitBreakGauge(convertToCircuitBreakGauge(dimensionEntry, instance));
((StatReporter) statPlugin).reportStat(info);
}
}
} catch (Exception ex) {
LOG.info("circuit breaker report encountered exception, e: {}", ex.getMessage());
}
}
}
use of com.tencent.polaris.api.plugin.Plugin in project polaris-java by polarismesh.
the class APIFactoryTest method testInitContextByConfig.
@Test
public void testInitContextByConfig() {
SDKContext sdkContext = null;
try {
sdkContext = APIFactory.initContextByConfig(TestUtils.createSimpleConfiguration(8888));
Supplier plugins = sdkContext.getPlugins();
Plugin plugin = plugins.getPlugin(PluginTypes.LOAD_BALANCER.getBaseType(), LoadBalanceConfig.LOAD_BALANCE_WEIGHTED_RANDOM);
Assert.assertNotNull(plugin);
} catch (PolarisException e) {
Assert.fail(e.getMessage());
} finally {
if (null != sdkContext) {
sdkContext.destroy();
}
}
}
use of com.tencent.polaris.api.plugin.Plugin in project polaris-java by polarismesh.
the class APIFactoryTest method testInitContextByFile.
@Test
public void testInitContextByFile() {
InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream("conf/default.yaml");
SDKContext sdkContext = null;
try {
sdkContext = APIFactory.initContextByFile(resourceAsStream);
Supplier plugins = sdkContext.getPlugins();
Plugin plugin = plugins.getPlugin(PluginTypes.CIRCUIT_BREAKER.getBaseType(), DefaultPlugins.CIRCUIT_BREAKER_ERROR_COUNT);
Assert.assertNotNull(plugin);
} catch (Exception e) {
Assert.fail(e.getMessage());
} finally {
if (null != sdkContext) {
sdkContext.destroy();
}
}
}
use of com.tencent.polaris.api.plugin.Plugin in project polaris-java by polarismesh.
the class PluginManager method initPlugins.
@Override
public void initPlugins(InitContext context) throws PolarisException {
// 先实例化所有插件
int baseId = 0;
for (PluginType pluginType : pluginTypes) {
Map<String, Plugin> plugins = new HashMap<>();
typedPlugins.put(pluginType, plugins);
ServiceLoader<? extends Plugin> loader = ServiceLoader.load(pluginType.getClazz());
for (Plugin plugin : loader) {
baseId++;
String name = plugin.getName();
if (StringUtils.isBlank(name) || plugins.containsKey(name)) {
throw new PolarisException(ErrorCode.PLUGIN_ERROR, String.format("duplicated name for plugin(name=%s, type=%s)", name, pluginType));
}
if (plugin instanceof IdAwarePlugin) {
((IdAwarePlugin) plugin).setId(baseId);
}
plugins.put(name, plugin);
}
}
// 再进行初始化
for (PluginType pluginType : pluginTypes) {
Map<String, Plugin> plugins = typedPlugins.get(pluginType);
for (Map.Entry<String, Plugin> pluginEntry : plugins.entrySet()) {
pluginEntry.getValue().init(context);
}
}
}
use of com.tencent.polaris.api.plugin.Plugin in project polaris-java by polarismesh.
the class PluginManager method postContextInitPlugins.
/**
* 在应用上下文初始化完毕后进行调用
*
* @param extensions 插件实例
* @throws PolarisException 运行异常
*/
public void postContextInitPlugins(Extensions extensions) throws PolarisException {
for (PluginType pluginType : pluginTypes) {
Map<String, Plugin> plugins = typedPlugins.get(pluginType);
if (MapUtils.isEmpty(plugins)) {
continue;
}
for (Map.Entry<String, Plugin> pluginEntry : plugins.entrySet()) {
Plugin plugin = pluginEntry.getValue();
plugin.postContextInit(extensions);
}
}
}
Aggregations