Skip to content

Commit 1838a04

Browse files
Michael Feromikefero
authored andcommitted
doc: Host event (state change) callback
* Cleaned up TODOs for query tracing and notifications
1 parent fd4bf24 commit 1838a04

2 files changed

Lines changed: 45 additions & 2 deletions

File tree

cpp-driver/topics/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,7 @@ Here are some features that are missing from the C/C++ driver, but are included
253253
with other drivers. The schedule for these features can be found on [JIRA].
254254
255255
- Compression
256-
- Query tracing
257-
- Event registration and notification
256+
- Schema event registration and notification
258257
- Callback interfaces for load balancing, authentication, reconnection and retry
259258
260259
[cpp-driver-centos6]: http://downloads.datastax.com/cpp-driver/centos/6/cassandra

cpp-driver/topics/configuration/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,50 @@ cass_cluster_free(cluster);
300300
It can be disabled by setting the value to a very long timeout or by disabling
301301
heartbeats.
302302
303+
### Host State Changes
304+
305+
The status and membership of a node can change within the life-cycle of the
306+
cluster. A host listener callback can be used to detect these changes.
307+
308+
**Important**: The driver runs the host listener callback on a thread that is
309+
different from the application. Any data accessed in the
310+
callback must be immutable or synchronized with a mutex,
311+
semaphore, etc.
312+
313+
```c
314+
void on_host_listener(CassHostListenerEvent event, CassInet inet, void* data) {
315+
/* Get the string representation of the inet address */
316+
char address[CASS_INET_STRING_LENGTH];
317+
cass_inet_string(inet, address);
318+
319+
/* Perform application logic for host listener event */
320+
if (event == CASS_HOST_LISTENER_EVENT_ADD) {
321+
printf("Host %s has been ADDED\n", address);
322+
} else if (event == CASS_HOST_LISTENER_EVENT_REMOVE) {
323+
printf("Host %s has been REMOVED\n", address);
324+
} else if (event == CASS_HOST_LISTENER_EVENT_UP) {
325+
printf("Host %s is UP\n", address);
326+
} else if (event == CASS_HOST_LISTENER_EVENT_DOWN) {
327+
printf("Host %s is DOWN\n", address);
328+
}
329+
}
330+
331+
int main() {
332+
CassCluster* cluster = cass_cluster_new();
333+
334+
/* Register the host listener callback */
335+
cass_cluster_set_host_listener_callback(cluster, on_host_listener, NULL);
336+
337+
/* ... */
338+
339+
cass_cluster_free(cluster);
340+
}
341+
```
342+
343+
**Note**: Expensive (e.g. slow) operations should not be performed in host
344+
listener callbacks. Performing expensive operations in a callback
345+
will block or slow the driver's normal operation.
346+
303347
### Performance Tips
304348

305349
#### Use a single persistent session

0 commit comments

Comments
 (0)