Search in sources :

Example 6 with DefaultDiscoveryServiceProvider

use of com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider in project hazelcast by hazelcast.

the class ClientDiscoverySpiTest method test_discovery_address_translator.

@Test
public void test_discovery_address_translator() throws Exception {
    String xmlFileName = "hazelcast-client-discovery-spi-test.xml";
    InputStream xmlResource = ClientDiscoverySpiTest.class.getClassLoader().getResourceAsStream(xmlFileName);
    ClientConfig clientConfig = new XmlClientConfigBuilder(xmlResource).build();
    ClientNetworkConfig networkConfig = clientConfig.getNetworkConfig();
    DiscoveryConfig discoveryConfig = networkConfig.getDiscoveryConfig();
    DiscoveryServiceProvider provider = new DefaultDiscoveryServiceProvider();
    DiscoveryService discoveryService = provider.newDiscoveryService(buildDiscoveryServiceSettings(discoveryConfig));
    AddressTranslator translator = new DiscoveryAddressTranslator(discoveryService, false);
    Address address = new Address("127.0.0.1", 50001);
    assertNull(translator.translate(null));
    assertEquals(address, translator.translate(address));
    // Enforce refresh of the internal mapping
    assertEquals(address, translator.translate(address));
}
Also used : Address(com.hazelcast.nio.Address) InputStream(java.io.InputStream) DiscoveryServiceProvider(com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) AddressTranslator(com.hazelcast.client.connection.AddressTranslator) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) XmlClientConfigBuilder(com.hazelcast.client.config.XmlClientConfigBuilder) ClientConfig(com.hazelcast.client.config.ClientConfig) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) DiscoveryService(com.hazelcast.spi.discovery.integration.DiscoveryService) DefaultDiscoveryService(com.hazelcast.spi.discovery.impl.DefaultDiscoveryService) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with DefaultDiscoveryServiceProvider

use of com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider in project hazelcast by hazelcast.

the class ClusterDiscoveryServiceBuilder method initDiscoveryService.

private DiscoveryService initDiscoveryService(ClientConfig config) {
    // Prevent confusing behavior where the DiscoveryService is started
    // and strategies are resolved but the AddressProvider is never registered
    List<DiscoveryStrategyConfig> aliasedDiscoveryConfigs = ClientAliasedDiscoveryConfigUtils.createDiscoveryStrategyConfigs(config);
    if (!properties.getBoolean(ClientProperty.DISCOVERY_SPI_ENABLED) && aliasedDiscoveryConfigs.isEmpty() && !config.getNetworkConfig().isAutoDetectionEnabled()) {
        return null;
    }
    ILogger logger = loggingService.getLogger(DiscoveryService.class);
    ClientNetworkConfig networkConfig = config.getNetworkConfig();
    DiscoveryConfig discoveryConfig = new DiscoveryConfigReadOnly(networkConfig.getDiscoveryConfig());
    DiscoveryServiceProvider factory = discoveryConfig.getDiscoveryServiceProvider();
    if (factory == null) {
        factory = new DefaultDiscoveryServiceProvider();
    }
    boolean isAutoDetectionEnabled = networkConfig.isAutoDetectionEnabled();
    DiscoveryServiceSettings settings = new DiscoveryServiceSettings().setConfigClassLoader(config.getClassLoader()).setLogger(logger).setDiscoveryMode(DiscoveryMode.Client).setAliasedDiscoveryConfigs(aliasedDiscoveryConfigs).setDiscoveryConfig(discoveryConfig).setAutoDetectionEnabled(isAutoDetectionEnabled);
    DiscoveryService discoveryService = factory.newDiscoveryService(settings);
    if (isAutoDetectionEnabled && isEmptyDiscoveryStrategies(discoveryService)) {
        return null;
    }
    discoveryService.start();
    return discoveryService;
}
Also used : DiscoveryServiceProvider(com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) ILogger(com.hazelcast.logging.ILogger) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) DefaultDiscoveryService(com.hazelcast.spi.discovery.impl.DefaultDiscoveryService) DiscoveryService(com.hazelcast.spi.discovery.integration.DiscoveryService) DiscoveryServiceSettings(com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings) DiscoveryConfigReadOnly(com.hazelcast.internal.config.DiscoveryConfigReadOnly) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig)

Example 8 with DefaultDiscoveryServiceProvider

use of com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider in project hazelcast by hazelcast.

the class ClientDiscoverySpiTest method testNodeFilter_from_xml.

@Test
public void testNodeFilter_from_xml() throws Exception {
    String xmlFileName = "hazelcast-client-discovery-spi-test.xml";
    InputStream xmlResource = ClientDiscoverySpiTest.class.getClassLoader().getResourceAsStream(xmlFileName);
    ClientConfig clientConfig = new XmlClientConfigBuilder(xmlResource).build();
    ClientNetworkConfig networkConfig = clientConfig.getNetworkConfig();
    DiscoveryConfig discoveryConfig = networkConfig.getDiscoveryConfig();
    DiscoveryServiceProvider provider = new DefaultDiscoveryServiceProvider();
    DiscoveryService discoveryService = provider.newDiscoveryService(buildDiscoveryServiceSettings(discoveryConfig));
    discoveryService.start();
    discoveryService.discoverNodes();
    discoveryService.destroy();
    Field nodeFilterField = DefaultDiscoveryService.class.getDeclaredField("nodeFilter");
    nodeFilterField.setAccessible(true);
    TestNodeFilter nodeFilter = (TestNodeFilter) nodeFilterField.get(discoveryService);
    assertEquals(4, nodeFilter.getNodes().size());
}
Also used : DiscoveryServiceProvider(com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) Field(java.lang.reflect.Field) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) XmlClientConfigBuilder(com.hazelcast.client.config.XmlClientConfigBuilder) InputStream(java.io.InputStream) ClientConfig(com.hazelcast.client.config.ClientConfig) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) DiscoveryService(com.hazelcast.spi.discovery.integration.DiscoveryService) DefaultDiscoveryService(com.hazelcast.spi.discovery.impl.DefaultDiscoveryService) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 9 with DefaultDiscoveryServiceProvider

use of com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider in project hazelcast by hazelcast.

the class Node method createDiscoveryService.

public DiscoveryService createDiscoveryService(DiscoveryConfig discoveryConfig, List<DiscoveryStrategyConfig> aliasedDiscoveryConfigs, boolean isAutoDetectionEnabled, Member localMember) {
    DiscoveryServiceProvider factory = discoveryConfig.getDiscoveryServiceProvider();
    if (factory == null) {
        factory = new DefaultDiscoveryServiceProvider();
    }
    ILogger logger = getLogger(DiscoveryService.class);
    DiscoveryServiceSettings settings = new DiscoveryServiceSettings().setConfigClassLoader(configClassLoader).setLogger(logger).setDiscoveryMode(DiscoveryMode.Member).setDiscoveryConfig(discoveryConfig).setAliasedDiscoveryConfigs(aliasedDiscoveryConfigs).setAutoDetectionEnabled(isAutoDetectionEnabled).setDiscoveryNode(new SimpleDiscoveryNode(localMember.getAddress(), localMember.getAttributes()));
    return factory.newDiscoveryService(settings);
}
Also used : DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) DiscoveryServiceProvider(com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) SimpleDiscoveryNode(com.hazelcast.spi.discovery.SimpleDiscoveryNode) ILogger(com.hazelcast.logging.ILogger) DiscoveryServiceSettings(com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings)

Aggregations

DefaultDiscoveryServiceProvider (com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider)9 DiscoveryServiceProvider (com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider)9 DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)8 DiscoveryService (com.hazelcast.spi.discovery.integration.DiscoveryService)7 ClientNetworkConfig (com.hazelcast.client.config.ClientNetworkConfig)6 DefaultDiscoveryService (com.hazelcast.spi.discovery.impl.DefaultDiscoveryService)6 DiscoveryServiceSettings (com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 InputStream (java.io.InputStream)5 Test (org.junit.Test)5 ClientConfig (com.hazelcast.client.config.ClientConfig)4 XmlClientConfigBuilder (com.hazelcast.client.config.XmlClientConfigBuilder)4 ILogger (com.hazelcast.logging.ILogger)4 Field (java.lang.reflect.Field)3 AddressTranslator (com.hazelcast.client.connection.AddressTranslator)2 DiscoveryStrategyConfig (com.hazelcast.config.DiscoveryStrategyConfig)2 JoinConfig (com.hazelcast.config.JoinConfig)2 Address (com.hazelcast.nio.Address)2 SimpleDiscoveryNode (com.hazelcast.spi.discovery.SimpleDiscoveryNode)2 Address (com.hazelcast.cluster.Address)1