Name

lcb_set_configuration_callback — Set callback for cluster topology changes

Synopsis

cc [ flag … ] file… -lcouchbase [ library … ]

#include <libcouchbase/couchbase.h>
lcb_configuration_callback lcb_set_configuration_callback(lcb_t instance, lcb_configuration_callback callback);

DESCRIPTION

lcb_set_configuration_callback() is used to set a new callback function to handle configuration changes received from the cluster for the given instance.

The callback parameter is a the callback function to call whenever a new configuration is received from the cluster. Passing NULL as the callback function may be used to query the current callback function. The lcb_configuration_callback is a function with the following signature:

void function(lcb_t instance, lcb_configuration_t config);

instance is the libcouchbase instance that this response is called from. The config parameter is the type of configuration change:

LCB_CONFIGURATION_NEW        A new cluster configuration was
                             received.
LCB_CONFIGURATION_CHANGED    Changes to the current cluster
                             configuration was received.
LCB_CONFIGURATION_UNCHANGED  The current cluster sent out
                             notifications, but nothing new
                             in configuration.

RETURN VALUES

lcb_set_configuration_callback() returns the previous callback function.

EXAMPLES

Example 1: Query the current callback

#include <libcouchbase/couchbase.h>
...
lcb_t instance;
...
lcb_configuration_callback old;
old = lcb_set_configuration_callback(instance, NULL);
...

Example 2: Install custom callback

#include <libcouchbase/couchbase.h>
...
static void callback(lcb_t instance, lcb_configuration_t config)
{
   switch (config) {
   case LCB_CONFIGURATION_NEW:
      fprintf(stdout, "Received new cluster configuration\n");
      break;
case LCB_CONFIGURATION_CHANGED:
   fprintf(stderr, "Received cluster change notification0);
   break;
   case LCB_CONFIGURATION_UNCHANGED:
      fprintf(stderr, "Received cluster notification0);
      break;
   default:
      fprintf(stderr, "Unknown configuration type received0);
   }
}
...
lcb_t instance;
...
lcb_set_configuration_callback(instance, callback);
...

ATTRIBUTES

See lcb_attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPE ATTRIBUTE VALUE

Interface Stability

Committed

MT-Level

MT-Safe

COPYRIGHT

Copyright 2010-2013 Couchbase, Inc.

SEE ALSO

Learn more at http://www.couchbase.com/communities/c.

libcouchbase(3lib), lcb_create(3couchbase), lcb_attributes(5)