Search in sources :

Example 1 with MemberAddressProvider

use of com.hazelcast.spi.MemberAddressProvider in project hazelcast by hazelcast.

the class DefaultNodeContext method newMemberAddressProviderInstance.

@SuppressWarnings("checkstyle:npathcomplexity")
private static // would make it harder to read
MemberAddressProvider newMemberAddressProviderInstance(Class<? extends MemberAddressProvider> clazz, ILogger logger, Properties properties) {
    Properties nonNullProps = properties == null ? new Properties() : properties;
    MemberAddressProvider provider = InstantiationUtils.newInstanceOrNull(clazz, nonNullProps, logger);
    if (provider == null) {
        provider = InstantiationUtils.newInstanceOrNull(clazz, logger, nonNullProps);
    }
    if (provider == null) {
        provider = InstantiationUtils.newInstanceOrNull(clazz, nonNullProps);
    }
    if (provider == null) {
        if (properties != null && !properties.isEmpty()) {
            throw new InvalidConfigurationException("Cannot find a matching constructor for MemberAddressProvider.  " + "The member address provider has properties configured, but the class " + "'" + clazz.getName() + "' does not have a public constructor accepting properties.");
        }
        provider = InstantiationUtils.newInstanceOrNull(clazz, logger);
    }
    if (provider == null) {
        provider = InstantiationUtils.newInstanceOrNull(clazz);
    }
    if (provider == null) {
        throw new InvalidConfigurationException("Cannot find a matching constructor for MemberAddressProvider " + "implementation '" + clazz.getName() + "'.");
    }
    return provider;
}
Also used : MemberAddressProvider(com.hazelcast.spi.MemberAddressProvider) Properties(java.util.Properties) HazelcastProperties(com.hazelcast.spi.properties.HazelcastProperties) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 2 with MemberAddressProvider

use of com.hazelcast.spi.MemberAddressProvider in project hazelcast by hazelcast.

the class DefaultNodeContext method createAddressPicker.

@Override
public AddressPicker createAddressPicker(Node node) {
    Config config = node.getConfig();
    MemberAddressProviderConfig memberAddressProviderConfig = getActiveMemberNetworkConfig(config).getMemberAddressProviderConfig();
    final ILogger addressPickerLogger = node.getLogger(AddressPicker.class);
    if (!memberAddressProviderConfig.isEnabled()) {
        if (config.getAdvancedNetworkConfig().isEnabled()) {
            return new AdvancedNetworkAddressPicker(config, addressPickerLogger);
        }
        return new DefaultAddressPicker(config, addressPickerLogger);
    }
    MemberAddressProvider implementation = memberAddressProviderConfig.getImplementation();
    if (implementation != null) {
        return new DelegatingAddressPicker(implementation, config, addressPickerLogger);
    }
    ClassLoader classLoader = config.getClassLoader();
    String classname = memberAddressProviderConfig.getClassName();
    Class<? extends MemberAddressProvider> clazz = loadMemberAddressProviderClass(classLoader, classname);
    ILogger memberAddressProviderLogger = node.getLogger(clazz);
    Properties properties = memberAddressProviderConfig.getProperties();
    MemberAddressProvider memberAddressProvider = newMemberAddressProviderInstance(clazz, memberAddressProviderLogger, properties);
    return new DelegatingAddressPicker(memberAddressProvider, config, addressPickerLogger);
}
Also used : MemberAddressProviderConfig(com.hazelcast.config.MemberAddressProviderConfig) Config(com.hazelcast.config.Config) ConfigAccessor.getActiveMemberNetworkConfig(com.hazelcast.config.ConfigAccessor.getActiveMemberNetworkConfig) MemberAddressProviderConfig(com.hazelcast.config.MemberAddressProviderConfig) ILogger(com.hazelcast.logging.ILogger) MemberAddressProvider(com.hazelcast.spi.MemberAddressProvider) Properties(java.util.Properties) HazelcastProperties(com.hazelcast.spi.properties.HazelcastProperties)

Aggregations

MemberAddressProvider (com.hazelcast.spi.MemberAddressProvider)2 HazelcastProperties (com.hazelcast.spi.properties.HazelcastProperties)2 Properties (java.util.Properties)2 Config (com.hazelcast.config.Config)1 ConfigAccessor.getActiveMemberNetworkConfig (com.hazelcast.config.ConfigAccessor.getActiveMemberNetworkConfig)1 InvalidConfigurationException (com.hazelcast.config.InvalidConfigurationException)1 MemberAddressProviderConfig (com.hazelcast.config.MemberAddressProviderConfig)1 ILogger (com.hazelcast.logging.ILogger)1