Search in sources :

Example 1 with ClientConfig

use of com.hazelcast.client.config.ClientConfig in project camel by apache.

the class HazelcastComponent method getOrCreateHzClientInstance.

private HazelcastInstance getOrCreateHzClientInstance(CamelContext context, Map<String, Object> parameters) throws Exception {
    HazelcastInstance hzInstance = null;
    ClientConfig config = null;
    // Query param named 'hazelcastInstance' (if exists) overrides the instance that was set
    hzInstance = resolveAndRemoveReferenceParameter(parameters, HAZELCAST_INSTANCE_PARAM, HazelcastInstance.class);
    // Check if an already created instance is given then just get instance by its name.
    if (hzInstance == null && parameters.get(HAZELCAST_INSTANCE_NAME_PARAM) != null) {
        hzInstance = Hazelcast.getHazelcastInstanceByName((String) parameters.get(HAZELCAST_INSTANCE_NAME_PARAM));
    }
    // as reference or as xml configuration file.
    if (hzInstance == null) {
        config = resolveAndRemoveReferenceParameter(parameters, HAZELCAST_CONFIGU_PARAM, ClientConfig.class);
        if (config == null) {
            String configUri = getAndRemoveParameter(parameters, HAZELCAST_CONFIGU_URI_PARAM, String.class);
            if (configUri != null) {
                configUri = getCamelContext().resolvePropertyPlaceholders(configUri);
            }
            if (configUri != null) {
                InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(context, configUri);
                config = new XmlClientConfigBuilder(is).build();
            }
        }
        if (hazelcastInstance == null && config == null) {
            config = new XmlClientConfigBuilder().build();
            // Disable the version check
            config.getProperties().setProperty("hazelcast.version.check.enabled", "false");
            config.getProperties().setProperty("hazelcast.phone.home.enabled", "false");
            hzInstance = HazelcastClient.newHazelcastClient(config);
        } else if (config != null) {
            hzInstance = HazelcastClient.newHazelcastClient(config);
        }
        if (hzInstance != null) {
            if (this.customHazelcastInstances.add(hzInstance)) {
                LOGGER.debug("Add managed HZ instance {}", hzInstance.getName());
            }
        }
    }
    return hzInstance == null ? hazelcastInstance : hzInstance;
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) XmlClientConfigBuilder(com.hazelcast.client.config.XmlClientConfigBuilder) InputStream(java.io.InputStream) ClientConfig(com.hazelcast.client.config.ClientConfig)

Example 2 with ClientConfig

use of com.hazelcast.client.config.ClientConfig in project camel by apache.

the class HazelcastRoute method configure.

@Override
public void configure() throws Exception {
    HazelcastComponent component = new HazelcastComponent();
    ClientConfig config = new ClientConfig();
    config.getNetworkConfig().addAddress("hazelcast");
    config.getNetworkConfig().setSSLConfig(new SSLConfig().setEnabled(false));
    config.setGroupConfig(new GroupConfig("someGroup", "someSecret"));
    HazelcastInstance instance = HazelcastClient.newHazelcastClient(config);
    component.setHazelcastInstance(instance);
    getContext().addComponent("hazelcast", component);
    from("timer:foo?period=5000").log("Producer side: Sending data to Hazelcast topic..").process(new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(HazelcastConstants.OPERATION, HazelcastConstants.PUBLISH_OPERATION);
            String payload = "Test " + UUID.randomUUID();
            exchange.getIn().setBody(payload);
        }
    }).to("hazelcast:topic:foo");
    from("hazelcast:topic:foo").log("Consumer side: Detected following action: $simple{in.header.CamelHazelcastListenerAction}");
}
Also used : Exchange(org.apache.camel.Exchange) SSLConfig(com.hazelcast.config.SSLConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Processor(org.apache.camel.Processor) GroupConfig(com.hazelcast.config.GroupConfig) HazelcastComponent(org.apache.camel.component.hazelcast.HazelcastComponent) ClientConfig(com.hazelcast.client.config.ClientConfig)

Example 3 with ClientConfig

use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.

the class ClientConsoleApp method main.

/**
     * Starts the test application. Loads the config from classpath hazelcast.xml,
     * if it fails to load, will use default config.
     *
     * @param args none
     * @throws Exception
     */
public static void main(String[] args) throws Exception {
    ClientConfig clientConfig;
    try {
        clientConfig = new XmlClientConfigBuilder().build();
    } catch (IllegalArgumentException e) {
        clientConfig = new ClientConfig();
    }
    final HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
    ClientConsoleApp clientConsoleApp = new ClientConsoleApp(client);
    clientConsoleApp.start(args);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) XmlClientConfigBuilder(com.hazelcast.client.config.XmlClientConfigBuilder) ClientConfig(com.hazelcast.client.config.ClientConfig)

Example 4 with ClientConfig

use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.

the class ClientAuthenticationTest method testFailedAuthentication.

@Test(expected = IllegalStateException.class)
public void testFailedAuthentication() throws Exception {
    hazelcastFactory.newHazelcastInstance();
    final ClientConfig clientConfig = new ClientConfig();
    clientConfig.getNetworkConfig().setConnectionAttemptPeriod(1);
    clientConfig.getGroupConfig().setPassword("InvalidPassword");
    hazelcastFactory.newHazelcastClient(clientConfig);
}
Also used : ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with ClientConfig

use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.

the class ClientConnectionTest method testWithLegalAndIllegalAddressTogether.

@Test
public void testWithLegalAndIllegalAddressTogether() {
    String illegalAddress = randomString();
    HazelcastInstance server = hazelcastFactory.newHazelcastInstance();
    ClientConfig config = new ClientConfig();
    config.setProperty(ClientProperty.SHUFFLE_MEMBER_LIST.getName(), "false");
    config.getNetworkConfig().addAddress(illegalAddress).addAddress("localhost");
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(config);
    Collection<Client> connectedClients = server.getClientService().getConnectedClients();
    assertEquals(connectedClients.size(), 1);
    Client serverSideClientInfo = connectedClients.iterator().next();
    assertEquals(serverSideClientInfo.getUuid(), client.getLocalEndpoint().getUuid());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientConfig(com.hazelcast.client.config.ClientConfig) Client(com.hazelcast.core.Client) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

ClientConfig (com.hazelcast.client.config.ClientConfig)214 Test (org.junit.Test)129 HazelcastInstance (com.hazelcast.core.HazelcastInstance)110 QuickTest (com.hazelcast.test.annotation.QuickTest)107 ParallelTest (com.hazelcast.test.annotation.ParallelTest)81 Config (com.hazelcast.config.Config)45 NearCacheConfig (com.hazelcast.config.NearCacheConfig)32 NightlyTest (com.hazelcast.test.annotation.NightlyTest)32 CountDownLatch (java.util.concurrent.CountDownLatch)25 AssertTask (com.hazelcast.test.AssertTask)20 Before (org.junit.Before)20 HazelcastClientProxy (com.hazelcast.client.impl.HazelcastClientProxy)16 ClientNetworkConfig (com.hazelcast.client.config.ClientNetworkConfig)15 HazelcastClientCachingProvider (com.hazelcast.client.cache.impl.HazelcastClientCachingProvider)13 CachingProvider (javax.cache.spi.CachingProvider)13 IMap (com.hazelcast.core.IMap)12 LifecycleListener (com.hazelcast.core.LifecycleListener)12 LifecycleEvent (com.hazelcast.core.LifecycleEvent)11 Data (com.hazelcast.nio.serialization.Data)11 NearCacheManager (com.hazelcast.internal.nearcache.NearCacheManager)10