Search in sources :

Example 6 with ConfigurationImpl

use of com.tencent.polaris.factory.config.ConfigurationImpl 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;
}
Also used : PolarisException(com.tencent.polaris.api.exception.PolarisException) PluginManager(com.tencent.polaris.api.plugin.impl.PluginManager) ValueContext(com.tencent.polaris.api.plugin.common.ValueContext) ArrayList(java.util.ArrayList) TypeProvider(com.tencent.polaris.api.plugin.TypeProvider) ConfigurationImpl(com.tencent.polaris.factory.config.ConfigurationImpl) PluginType(com.tencent.polaris.api.plugin.PluginType)

Example 7 with ConfigurationImpl

use of com.tencent.polaris.factory.config.ConfigurationImpl in project polaris-java by polarismesh.

the class ServiceExpireTest method createConfiguration.

private static Configuration createConfiguration() {
    ConfigurationImpl configuration = (ConfigurationImpl) TestUtils.configWithEnvAddress();
    configuration.setDefault();
    configuration.getConsumer().getLocalCache().setServiceExpireTime(5000);
    configuration.getGlobal().getServerConnector().setServerSwitchInterval(1500L);
    return configuration;
}
Also used : ConfigurationImpl(com.tencent.polaris.factory.config.ConfigurationImpl)

Example 8 with ConfigurationImpl

use of com.tencent.polaris.factory.config.ConfigurationImpl in project polaris-java by polarismesh.

the class TestUtils method configWithEnvAddress.

/**
 * 从环境变量中获取服务端地址并创建配置
 *
 * @return 配置的服务端地址
 */
public static Configuration configWithEnvAddress() {
    Configuration configuration = ConfigAPIFactory.defaultConfig();
    String[] addresses = getServerAddressFromEnv();
    if (null != addresses) {
        ConfigurationImpl configurationImpl = (ConfigurationImpl) configuration;
        configurationImpl.setDefault();
        configurationImpl.getGlobal().getServerConnector().setAddresses(Arrays.asList(addresses.clone()));
    }
    return configuration;
}
Also used : Configuration(com.tencent.polaris.api.config.Configuration) ConfigurationImpl(com.tencent.polaris.factory.config.ConfigurationImpl)

Example 9 with ConfigurationImpl

use of com.tencent.polaris.factory.config.ConfigurationImpl in project polaris-java by polarismesh.

the class TestUtils method createSimpleConfiguration.

public static Configuration createSimpleConfiguration(int port) {
    ConfigurationImpl configuration = new ConfigurationImpl();
    configuration.setDefault();
    configuration.getGlobal().getServerConnector().setAddresses(Collections.singletonList(String.format("127.0.0.1:%d", port)));
    return configuration;
}
Also used : ConfigurationImpl(com.tencent.polaris.factory.config.ConfigurationImpl)

Example 10 with ConfigurationImpl

use of com.tencent.polaris.factory.config.ConfigurationImpl in project polaris-java-agent by polarismesh.

the class PolarisContext method configuration.

/**
 * 初始化配置
 *
 * @param polarisAgentProperties
 * @return
 */
private static Configuration configuration(PolarisAgentProperties polarisAgentProperties) {
    ConfigurationImpl configuration = (ConfigurationImpl) ConfigAPIFactory.defaultConfig(ConfigProvider.DEFAULT_CONFIG);
    configuration.setDefault();
    configuration.getGlobal().getAPI().setBindIP(PolarisServiceConstants.HOST);
    configuration.getGlobal().getServerConnector().setAddresses(Collections.singletonList(polarisAgentProperties.getServerAddress()));
    return configuration;
}
Also used : ConfigurationImpl(com.tencent.polaris.factory.config.ConfigurationImpl)

Aggregations

ConfigurationImpl (com.tencent.polaris.factory.config.ConfigurationImpl)10 Configuration (com.tencent.polaris.api.config.Configuration)3 ConsumerAPI (com.tencent.polaris.api.core.ConsumerAPI)1 PolarisException (com.tencent.polaris.api.exception.PolarisException)1 PluginType (com.tencent.polaris.api.plugin.PluginType)1 TypeProvider (com.tencent.polaris.api.plugin.TypeProvider)1 ValueContext (com.tencent.polaris.api.plugin.common.ValueContext)1 PluginManager (com.tencent.polaris.api.plugin.impl.PluginManager)1 Instance (com.tencent.polaris.api.pojo.Instance)1 GetOneInstanceRequest (com.tencent.polaris.api.rpc.GetOneInstanceRequest)1 InstancesResponse (com.tencent.polaris.api.rpc.InstancesResponse)1 ServerConnectorConfigImpl (com.tencent.polaris.factory.config.global.ServerConnectorConfigImpl)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1