@@ -300,6 +300,50 @@ cass_cluster_free(cluster);
300300It can be disabled by setting the value to a very long timeout or by disabling
301301heartbeats.
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