Search in sources :

Example 1 with DiscoveryServiceProvider

use of com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider in project hazelcast by hazelcast.

the class Node method createDiscoveryService.

private DiscoveryService createDiscoveryService(Config config) {
    JoinConfig joinConfig = config.getNetworkConfig().getJoin();
    DiscoveryConfig discoveryConfig = joinConfig.getDiscoveryConfig().getAsReadOnly();
    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).setDiscoveryNode(new SimpleDiscoveryNode(localMember.getAddress(), localMember.getAttributes()));
    return factory.newDiscoveryService(settings);
}
Also used : DiscoveryServiceProvider(com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) JoinConfig(com.hazelcast.config.JoinConfig) SimpleDiscoveryNode(com.hazelcast.spi.discovery.SimpleDiscoveryNode) ILogger(com.hazelcast.logging.ILogger) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) DiscoveryServiceSettings(com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings)

Example 2 with DiscoveryServiceProvider

use of com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider 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)

Example 3 with DiscoveryServiceProvider

use of com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider in project hazelcast by hazelcast.

the class ClientDiscoverySpiTest method test_discovery_address_translator_with_public_ip.

@Test
public void test_discovery_address_translator_with_public_ip() 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, true);
    Address publicAddress = new Address("127.0.0.1", 50001);
    Address privateAddress = new Address("127.0.0.1", 1);
    // Enforce refresh of the internal mapping
    assertEquals(publicAddress, translator.translate(privateAddress));
}
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 4 with DiscoveryServiceProvider

use of com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider in project hazelcast by hazelcast.

the class ClientDiscoverySpiTest method test_CustomDiscoveryService_whenDiscoveredNodes_isNull.

@Test
public void test_CustomDiscoveryService_whenDiscoveredNodes_isNull() {
    ClientConfig config = new ClientConfig();
    config.setProperty(GroupProperty.DISCOVERY_SPI_ENABLED.getName(), "true");
    final DiscoveryService discoveryService = mock(DiscoveryService.class);
    DiscoveryServiceProvider discoveryServiceProvider = new DiscoveryServiceProvider() {

        public DiscoveryService newDiscoveryService(DiscoveryServiceSettings arg0) {
            return discoveryService;
        }
    };
    ClientNetworkConfig networkConfig = config.getNetworkConfig();
    networkConfig.setConnectionAttemptLimit(1);
    networkConfig.setConnectionAttemptPeriod(1);
    networkConfig.getDiscoveryConfig().setDiscoveryServiceProvider(discoveryServiceProvider);
    try {
        HazelcastClient.newHazelcastClient(config);
        fail("Client cannot start, discovery nodes is null!");
    } catch (NullPointerException expected) {
    // discovered nodes is null
    }
    verify(discoveryService).discoverNodes();
}
Also used : DiscoveryServiceProvider(com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) ClientConfig(com.hazelcast.client.config.ClientConfig) DiscoveryService(com.hazelcast.spi.discovery.integration.DiscoveryService) DefaultDiscoveryService(com.hazelcast.spi.discovery.impl.DefaultDiscoveryService) DiscoveryServiceSettings(com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with DiscoveryServiceProvider

use of com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider in project hazelcast by hazelcast.

the class DiscoveryTest method test_DiscoveryConfig_setDiscoveryServiceProvider.

@Test
public void test_DiscoveryConfig_setDiscoveryServiceProvider() {
    DiscoveryConfig discoveryConfig = new DiscoveryConfig();
    DiscoveryServiceProvider discoveryServiceProvider = new TestDiscoveryServiceProvider();
    discoveryConfig.setDiscoveryServiceProvider(discoveryServiceProvider);
    assertSame(discoveryServiceProvider, discoveryConfig.getDiscoveryServiceProvider());
}
Also used : DiscoveryServiceProvider(com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

DiscoveryServiceProvider (com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider)16 DefaultDiscoveryServiceProvider (com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider)15 DiscoveryService (com.hazelcast.spi.discovery.integration.DiscoveryService)13 DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)12 DefaultDiscoveryService (com.hazelcast.spi.discovery.impl.DefaultDiscoveryService)12 QuickTest (com.hazelcast.test.annotation.QuickTest)12 Test (org.junit.Test)12 DiscoveryServiceSettings (com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings)11 ClientNetworkConfig (com.hazelcast.client.config.ClientNetworkConfig)10 ClientConfig (com.hazelcast.client.config.ClientConfig)8 InputStream (java.io.InputStream)7 XmlClientConfigBuilder (com.hazelcast.client.config.XmlClientConfigBuilder)6 DiscoveryStrategyConfig (com.hazelcast.config.DiscoveryStrategyConfig)6 JoinConfig (com.hazelcast.config.JoinConfig)6 ILogger (com.hazelcast.logging.ILogger)6 Config (com.hazelcast.config.Config)5 InterfacesConfig (com.hazelcast.config.InterfacesConfig)5 Field (java.lang.reflect.Field)5 SimpleDiscoveryNode (com.hazelcast.spi.discovery.SimpleDiscoveryNode)4 Address (com.hazelcast.cluster.Address)3