Skip to content

Commit 7175f0e

Browse files
authored
client connection strategy example, (#182)
pom group name clean up
1 parent 7955736 commit 7175f0e

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<artifactId>client-connection-strategy</artifactId>
7+
<name>Client Connection Strategy</name>
8+
<description>Examples for Client connection strategy</description>
9+
10+
<parent>
11+
<artifactId>clients</artifactId>
12+
<groupId>book.hazelcast.client</groupId>
13+
<version>0.1-SNAPSHOT</version>
14+
</parent>
15+
16+
17+
<properties>
18+
<!-- needed for checkstyle/findbugs -->
19+
<main.basedir>${project.parent.parent.basedir}</main.basedir>
20+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
21+
</properties>
22+
23+
24+
</project>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.hazelcast.samples;
2+
3+
import com.hazelcast.client.HazelcastClient;
4+
import com.hazelcast.client.config.ClientConfig;
5+
import com.hazelcast.client.util.ClientStateListener;
6+
import com.hazelcast.core.Hazelcast;
7+
import com.hazelcast.core.HazelcastInstance;
8+
9+
public class ClientStrategy {
10+
11+
public static void main(String[] args) {
12+
HazelcastInstance server = Hazelcast.newHazelcastInstance();
13+
14+
ClientConfig clientConfig = new ClientConfig();
15+
clientConfig.getConnectionStrategyConfig().setAsyncStart(true);
16+
ClientStateListener clientStateListener = new ClientStateListener(clientConfig);
17+
HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
18+
19+
boolean started = false;
20+
try {
21+
started = clientStateListener.awaitConnected();
22+
} catch (InterruptedException e) {
23+
e.printStackTrace();
24+
}
25+
26+
if (started) {
27+
//client started and ready to operate.
28+
System.out.println("Is Client connected to cluster: " + clientStateListener.isConnected());
29+
}
30+
31+
HazelcastClient.shutdownAll();
32+
Hazelcast.shutdownAll();
33+
}
34+
}

clients/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<module>client-statistics</module>
3030
<module>user-code-deployment</module>
3131
<module>client-labels</module>
32+
<module>client-connection-strategy</module>
3233
</modules>
3334

3435
<dependencies>

0 commit comments

Comments
 (0)