Skip to content

Commit 16d4f42

Browse files
authored
Reference manual update (#1191)
1 parent cc1719d commit 16d4f42

File tree

1 file changed

+83
-54
lines changed

1 file changed

+83
-54
lines changed

Reference_Manual.md

Lines changed: 83 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* [Release Notes](#release-notes)
77
* [1. Getting Started](#1-getting-started)
88
* [1.1. Installing](#11-installing)
9-
* [1.1.1. Conan Users](#111-conan-users)
10-
* [1.1.2. Vcpkg Users](#112-vcpkg-users)
9+
* [1.1.1. Vcpkg Users](#111-vcpkg-users)
10+
* [1.1.2. Conan Users](#112-conan-users)
1111
* [1.1.3. Install From Source Code Using CMake](#113-install-from-source-code-using-cmake)
1212
* [1.1.3.1. Requirements](#1131-requirements)
1313
* [1.1.3.2. Downloading Source Code](#1132-downloading-source-code)
@@ -184,7 +184,35 @@ This chapter provides information on how to get started with your Hazelcast C++
184184

185185
## 1.1. Installing
186186

187-
### 1.1.1. Conan Users
187+
### 1.1.1. Vcpkg Users (Recommended)
188+
Hazelcast C++ client package is available for [Vcpkg](https://github.com/microsoft/vcpkg) users. The package name is `hazelcast-cpp-client`.
189+
190+
Please see [getting started](https://github.com/microsoft/vcpkg#getting-started) on how to use Vcpkg package manager with your application. In summary,
191+
192+
If you use Linux or Mac:
193+
194+
```sh
195+
git clone https://github.com/microsoft/vcpkg
196+
./vcpkg/bootstrap-vcpkg.sh
197+
./vcpkg/vcpkg install "hazelcast-cpp-client[openssl]" --recurse
198+
```
199+
200+
If you use Windows:
201+
202+
```bat
203+
git clone https://github.com/microsoft/vcpkg
204+
.\vcpkg\bootstrap-vcpkg.bat
205+
.\vcpkg\vcpkg install "hazelcast-cpp-client[openssl]:x64-windows" --recurse
206+
```
207+
The above code snippet will install `hazelcast-cpp-client` with its `boost` and `openssl` dependencies.
208+
209+
After the installation, the library is available for usage. For example, if you are using CMake for your builds, you can use the following cmake build command with the `CMAKE_TOOLCHAIN_FILE` cmake option to be the `vcpkg.cmake`.
210+
```bat
211+
cmake -B [build directory] -S . -DCMAKE_TOOLCHAIN_FILE=[path to vcpkg]/scripts/buildsystems/vcpkg.cmake
212+
cmake --build [build directory]
213+
```
214+
215+
### 1.2.1. Conan Users
188216
Hazelcast C++ client package is indexed at [Conan Center Index](https://conan.io/center/hazelcast-cpp-client). You can use [Conan package manager](https://conan.io/) to install Hazelcast C++ client. The package name is `hazelcast-cpp-client`.
189217

190218
Please see [example instructions](https://docs.conan.io/en/latest/getting_started.html#an-md5-hash-calculator-using-the-poco-libraries) on how to use conan package manager with your application. In summary,
@@ -204,32 +232,6 @@ $ conan install ..
204232
```
205233
This generates the `conanbuildinfo.cmake` file to be included in your CMakeLists.txt. Please follow the instructions at the [example page](https://docs.conan.io/en/latest/getting_started.html#an-md5-hash-calculator-using-the-poco-libraries) and build your application.
206234

207-
### 1.1.2. Vcpkg Users
208-
Hazelcast C++ client package is available for [Vcpkg](https://github.com/microsoft/vcpkg) users. The port name is `hazelcast-cpp-client`.
209-
210-
Please see [Getting Started](https://github.com/microsoft/vcpkg#getting-started) on how to use Vcpkg package manager with your application. In summary,
211-
212-
```bat
213-
> git clone https://github.com/microsoft/vcpkg
214-
> .\vcpkg\bootstrap-vcpkg.bat
215-
> .\vcpkg\vcpkg install hazelcast-cpp-client
216-
```
217-
The above code snippet will install `hazelcast-cpp-client` with its `boost` dependencies.
218-
219-
After the installation, the library is available for usage. For example, if you are using CMake for your builds, you can use the following cmake build command with the `CMAKE_TOOLCHAIN_FILE` cmake option to be the `vcpkg.cmake`.
220-
```bat
221-
> cmake -B [build directory] -S . -DCMAKE_TOOLCHAIN_FILE=[path to vcpkg]/scripts/buildsystems/vcpkg.cmake
222-
> cmake --build [build directory]
223-
```
224-
225-
You can find more details on using a Vcpkg installed package from different IDEs in your projects from the [Vcpkg Official Getting Started](https://github.com/microsoft/vcpkg#getting-started) documentation.
226-
227-
If you need to use `openssl` feature, then you need to install using the following command:
228-
```bat
229-
> .\vcpkg\vcpkg install hazelcast-cpp-client[openssl] --recurse
230-
```
231-
The above code will install `hazelcast-cpp-client` with its `boost` and `openssl` dependencies.
232-
233235
### 1.1.3. Install From Source Code Using CMake
234236
#### 1.1.3.1. Requirements
235237
1. Linux, macOS or Windows
@@ -276,9 +278,12 @@ See the [advanced installation](#1135-advanced-installation) section for configu
276278

277279
Run `cmake` again to build and install the library:
278280
```sh
279-
cmake --build .
281+
cmake --build .
280282
sudo cmake --build . --target install
281283
```
284+
285+
You could speed up the build process with paralel threads like 'cmake --build . -j 4'
286+
282287
See [this section](#11351-custom-install-location) for information on how to use a different installation location.
283288

284289
#### 1.1.3.4. Windows Users
@@ -429,15 +434,25 @@ Here is how you can compile an example from the examples directory:
429434
g++ -std=c++11 \
430435
examples/path/to/example.cpp \
431436
-DBOOST_THREAD_VERSION=5 \
432-
-lhazelcast-cpp-client -lboost_thread -lboost_chrono
437+
-lhazelcast-cpp-client -lboost_thread -lboost_chrono -lssl -lcrypto
433438
```
434439

440+
If your enviroment could not find openssl library, you could define it like below (As an example: `-L/opt/homebrew/Cellar/[email protected]/1.1.1t/lib`)
441+
442+
```
443+
g++ -std=c++11 \
444+
examples/path/to/example.cpp \
445+
-DBOOST_THREAD_VERSION=5 \
446+
-lhazelcast-cpp-client -lboost_thread -lboost_chrono -lssl -lcrypto
447+
-L/opt/homebrew/Cellar/[email protected]/1.1.1t/lib
448+
```
449+
435450
If a custom installation directory was used during installation, then you may also need to use the `-L` and `-I` options to add the library and include paths to the compiler's search path.
436451
```
437452
g++ -std=c++11 \
438453
examples/path/to/example.cpp \
439454
-I /path/to/install/include -L /path/to/install/lib \
440-
-lhazelcast-cpp-client -lboost_thread -lboost_chrono
455+
-lhazelcast-cpp-client -lboost_thread -lboost_chrono -lssl -lcrypto
441456
```
442457

443458
#### 1.3.3. Windows Users
@@ -600,6 +615,7 @@ The following example first creates a programmatic configuration object. Then, i
600615
int main() {
601616
auto hz = hazelcast::new_client().get(); // Connects to the cluster
602617
std::cout << "Started the Hazelcast C++ client instance " << hz.get_name() << std::endl; // Prints client instance name
618+
hz.shutdown().get();
603619
return 0;
604620
}
605621
```
@@ -628,15 +644,15 @@ Let's manipulate a distributed map on a cluster using the client.
628644
Save the following file as `IT.cpp` and compile it using a command similar to the following (Linux g++ compilation is used for demonstration):
629645

630646
```c++
631-
g++ IT.cpp -o IT -lhazelcast-cpp-client -lboost_thread -lboost_chrono -DBOOST_THREAD_VERSION=5
647+
g++ IT.cpp -o IT -lhazelcast-cpp-client -lboost_thread -lboost_chrono -DBOOST_THREAD_VERSION=5 -lssl -lcrypto --std=c++11
632648
```
633649
Then, you can run the application using the following command:
634650

635651
```
636652
./IT
637653
```
638654

639-
**main.cpp**
655+
**IT.cpp**
640656

641657
```c++
642658
#include <hazelcast/client/hazelcast_client.h>
@@ -651,7 +667,7 @@ int main() {
651667
for (const auto &entry : personnel->entry_set<std::string, std::string>().get()) {
652668
std::cout << entry.first << " is in " << entry.second << " department." << std::endl;
653669
}
654-
670+
hz.shutdown().get();
655671
return 0;
656672
}
657673
```
@@ -683,7 +699,7 @@ Now create a `Sales.cpp` file, compile and run it as shown below.
683699
**Compile:**
684700

685701
```c++
686-
g++ Sales.cpp -o Sales -lhazelcast-cpp-client -lboost_thread -lboost_chrono -DBOOST_THREAD_VERSION=5
702+
g++ Sales.cpp -o Sales -lhazelcast-cpp-client -lboost_thread -lboost_chrono -DBOOST_THREAD_VERSION=5 -lssl -lcrypto --std=c++11
687703
```
688704
**Run**
689705

@@ -710,8 +726,8 @@ auto personnel = hz.get_map("personnel_map").get();
710726
for (const auto &entry : personnel.entry_set().get()) {
711727
std::cout << entry.first << " is in " << entry.second << " department." << std::endl;
712728
}
713-
714-
return 0;
729+
hz.shutdown().get();
730+
return 0;
715731
}
716732
```
717733

@@ -1253,7 +1269,7 @@ The following are configuration element descriptions:
12531269
* `initial_backoff_duration`: Specifies how long to wait (backoff) after the first failure before retrying.
12541270
* `max_backoff_duration`: Specifies the upper limit for the backoff between each cluster connect tries.
12551271
* `multiplier`: Factor to multiply the backoff after a failed retry.
1256-
* `cluster_connect)timeout`: Timeout value for the client to give up to connect to the current cluster. If the client can not connect during this time, then it shuts down and it can not be re-used.
1272+
* `cluster_connect_timeout`: Timeout value for the client to give up to connect to the current cluster. If the client can not connect during this time, then it shuts down and it can not be re-used.
12571273
* `jitter`: Specifies by how much to randomize backoffs.
12581274

12591275
## 5.6. Enabling Client TLS/SSL
@@ -1265,7 +1281,7 @@ As explained in the [TLS/SSL section](#61-tlsssl), Hazelcast members have key st
12651281

12661282
## 5.7. Enabling Hazelcast AWS Discovery
12671283

1268-
The C++ client can discover the existing Hazelcast servers in the Amazon AWS environment. The client queries the Amazon AWS environment using the [describe-instances] (http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html) query of AWS. The client finds only the up and running instances and filters them based on the filter config provided at the `client_aws_config` configuration.
1284+
The C++ client can discover the existing Hazelcast servers in the Amazon AWS environment. The client queries the Amazon AWS environment using the [describe-instances](http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html) query of AWS. The client finds only the up and running instances and filters them based on the filter config provided at the `client_aws_config` configuration.
12691285

12701286
The following is an example configuration:
12711287

@@ -1287,7 +1303,7 @@ and [the AWS examples directory](https://github.com/hazelcast/hazelcast-cpp-clie
12871303
for more details.
12881304

12891305
## 5.8. Enabling Hazelcast Cloud Discovery
1290-
If you are using [Hazelcast Cloud Service](https://cloud.hazelcast.com) and you want to write an application that will utilize the Hazelcast cloud database service, you can use the C++ client. The configuration is very simple, you just need to set the cluster name, discovery token and enable the cloud discovery on network settings. Here is an example configuration:
1306+
If you are using [Hazelcast Viridian](https://viridian.hazelcast.com/) and you want to write an application that will utilize the Hazelcast cloud database service, you can use the C++ client. The configuration is very simple, you just need to set the cluster name, discovery token and enable the cloud discovery on network settings. Here is an example configuration:
12911307

12921308
```c++
12931309
hazelcast::client::client_config config;
@@ -1544,7 +1560,7 @@ If you want to enable the validation of server certificate on the client side an
15441560
auto hz = hazelcast::new_client(std::move(config)).get();
15451561
```
15461562
1547-
The client will connect if the server has a certificate which is properly signed by well known Certificate Authorities(CA). On Windows, you may need to set the well known CA Authorities file path since OpenSSL may not find the well known certifite authorities file. This can be solved by providing the [SSL_CERT_FILE](https://www.openssl.org/docs/man1.1.0/man3/SSL_CTX_set_default_verify_paths.html) environment variable set to point a file path that has all the needed well known certificate authorities. For example, you can get such a file maintained by Mozilla at https://curl.se/docs/caextract.html.
1563+
The client will connect if the server has a certificate which is properly signed by well known Certificate Authorities(CA). On Windows, you may need to set the well known CA Authorities file path since OpenSSL may not find the well known certifite authorities file. This can be solved by providing the [SSL_CERT_FILE](https://www.openssl.org/docs/man1.1.1/man3/SSL_CTX_set_default_verify_paths.html) environment variable set to point a file path that has all the needed well known certificate authorities. For example, you can get such a file maintained by Mozilla at https://curl.se/docs/caextract.html.
15481564
15491565
If the server is using a user generated certificate file which is not signed by the well known CA authorities, then you can use the public certificate of the server to configure the client to connect and verify the server. Here is an example configuration for this:
15501566
@@ -1593,7 +1609,6 @@ In some cases, you may want to limit the cipher suites allowed for a client whil
15931609
```c++
15941610
config.get_network_config().get_ssl_config().
15951611
set_cipher_list("HIGH"); // optional setting (values for string are described at
1596-
// https://www.openssl.org/docs/man1.0.2/apps/ciphers.html and
15971612
// https://www.openssl.org/docs/man1.1.1/man1/ciphers.html
15981613
```
15991614

@@ -1926,6 +1941,7 @@ void listen_with_default_config() {
19261941
} else {
19271942
std::cerr << "Failed to remove the listener " << listenerId << " for topic " << topicName << std::endl;
19281943
}
1944+
client.shutdown().get();
19291945
}
19301946
19311947
void listen_with_config() {
@@ -1952,6 +1968,8 @@ void listen_with_config() {
19521968
} else {
19531969
std::cerr << "Failed to remove the listener " << listenerId << " for topic " << topicName << std::endl;
19541970
}
1971+
1972+
client.shutdown().get();
19551973
}
19561974
```
19571975

@@ -1975,6 +1993,8 @@ std::cout << "Counter new value before adding is: " << pnCounter->get_and_add(2)
19751993
std::cout << "Counter new value is: " << pnCounter->get().get() << std::endl;
19761994

19771995
std::cout << "Decremented counter by one to: " << pnCounter->decrement_and_get().get() << std::endl;
1996+
1997+
hz.shutdown().get();
19781998
```
19791999
19802000
### 7.4.10 Using flake_id_generator
@@ -2280,11 +2300,12 @@ int main() {
22802300
auto initialMemberListener = make_initial_membership_listener();
22812301

22822302
hazelcast::client::cluster *clusterPtr = nullptr;
2283-
boost::uuids::uuid listenerId, initialListenerId;
2303+
boost::uuids::uuid listenerId, initialListenerId;
2304+
std::unique_ptr<client::hazelcast_client> hz;
22842305
try {
2285-
auto hz = hazelcast::new_client().get();
2306+
hz = std::unique_ptr<hazelcast_client>( hazelcast::new_client().get() );
22862307

2287-
hazelcast::client::cluster &cluster = hz.get_cluster().get();
2308+
hazelcast::client::cluster &cluster = hz->get_cluster().get();
22882309
clusterPtr = &cluster;
22892310
auto members = cluster.get_members();
22902311
std::cout << "The following are members in the cluster:" << std::endl;
@@ -2306,21 +2327,23 @@ int main() {
23062327
clusterPtr->remove_membership_listener(listenerId).get();
23072328
clusterPtr->remove_membership_listener(initialListenerId).get();
23082329
}
2330+
hz->shutdown().get();
23092331
exit(-1);
23102332
}
2333+
hz->shutdown().get();
23112334
...
23122335
```
23132336
23142337
#### 7.5.1.3. Listening for Lifecycle Events
23152338
23162339
The `lifecycle_listener` interface notifies for the following events:
23172340
2318-
* `starting`: The client is starting.
2319-
* `started`: The client has started.
2320-
* `shutting_down`: The client is shutting down.
2321-
* `shutdown`: The client’s shutdown has completed.
2322-
* `client_connected`: The client is connected to the cluster.
2323-
* `client_disconnected`: The client is disconnected from the cluster.
2341+
* `STARTING`: The client is starting.
2342+
* `STARTED`: The client has started.
2343+
* `SHUTTING_DOWN`: The client is shutting down.
2344+
* `SHUTDOWN`: The client’s shutdown has completed.
2345+
* `CLIENT_CONNECTED`: The client is connected to the cluster.
2346+
* `CLIENT_DISCONNECTED`: The client is disconnected from the cluster.
23242347
23252348
The following is an example of the `lifecycle_listener` that is added to the `client_config` object and its output.
23262349
@@ -2396,7 +2419,7 @@ int main() {
23962419
map->remove<int, std::string>(1).get();
23972420

23982421
/* ... */
2399-
2422+
hz.shutdown().get();
24002423
return 0;
24012424
}
24022425
```
@@ -2423,6 +2446,7 @@ int main() {
24232446

24242447
/* ... */
24252448

2449+
hz.shutdown().get();
24262450
return 0;
24272451
}
24282452
```
@@ -3084,7 +3108,7 @@ The C++ client provides paging for defined predicates. With its `paging_predicat
30843108
```c++
30853109
auto map = hz.get_map("personMap").get();
30863110
// paging_predicate with inner predicate (value < 10)
3087-
auto predicate = intMap->new_paging_predicate<int, int>(5,
3111+
auto pagingPredicate = intMap->new_paging_predicate<int, int>(5,
30883112
query::greater_less_predicate(client, query::query_constants::THIS_ATTRIBUTE_NAME, 10, false, false));
30893113
30903114
// Set page to retrieve third page
@@ -3482,6 +3506,7 @@ for (auto itr = result->iterator(); itr.has_next();)
34823506
<< '\n';
34833507
}
34843508
}
3509+
hz.shutdown().get();
34853510
```
34863511

34873512
**Note-1**: First call to `sql_result::page_iterator::next()` function will return `ready` future because first page is already loaded as a result of the sql_service::execute call.
@@ -3525,6 +3550,7 @@ auto itr = result->iterator();
35253550
auto page = itr.next().get();
35263551

35273552
std::cout << page.row_count() << std::endl; // This may print zero if no data is yet generated at the server side.
3553+
hz.shutdown().get();
35283554
```
35293555
**Note-5**: `boost::future<std::shared_ptr<sql_result>>` is returned from `sql_service::execute` and `boost::future<std::shared_ptr<sql_page>>` is returned from `sql_result::page_iterator::next()`.
35303556
@@ -3543,6 +3569,7 @@ catch (const hazelcast_sql_exception&)
35433569
{
35443570
// Do error handling
35453571
}
3572+
hz.shutdown().get();
35463573
```
35473574

35483575
``` C++
@@ -3632,6 +3659,8 @@ std::cout << "name : " << age_col_metadata.name
36323659
<< " type : " << int(age_col_metadata.type)
36333660
<< " nullable : " << age_col_metadata.nullable
36343661
<< std::endl;
3662+
3663+
hz.shutdown().get();
36353664
```
36363665
**Note :** There is no metadata for non-`SELECT` queries.
36373666

0 commit comments

Comments
 (0)