File tree Expand file tree Collapse file tree 3 files changed +59
-0
lines changed
client-connection-strategy
src/main/java/com/hazelcast/samples Expand file tree Collapse file tree 3 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments