DbEnv::repmgr_msg_dispatch()

#include <db_cxx.h>

int
DbEnv::repmgr_msg_dispatch(
        void (*msg_dispatch_fcn) (DbEnv *env, DbChannel *channel, 
                                  Dbt *request, u_int32_t nrequest,
                                  u_int32_t cb_flags), 
        u_int32_t flags); 

Sets the message dispatch function. This function is responsible for receiving messages sent from remote sites using either the DbChannel::send_msg() or DbChannel::send_request() methods. If the message received by this function was sent using the DbChannel::send_msg() method then no response is required. If the message was sent using the DbChannel::send_request() method, then this function must send a response using the DbChannel::send_msg() method.

For best results, the DbEnv::repmgr_msg_dispatch() method should be called before the Replication Manager has been started.

The DbEnv::repmgr_msg_dispatch() method either returns a non-zero error value or throws an exception that encapsulates a non-zero error value on failure, and returns 0 on success.

Parameters

msg_dispatch_fcn

This parameter is the application-specific function used to handle messages sent over Replication Manager message channels. It takes four parameters:

  • channel

    Provides the DbChannel to be used to send a response back to the originator of the message. If the message was sent by the remote site using DbChannel::send_request() then this function should send a response back to the originator using the channel provided on this parameter. The message should be sent by calling DbChannel::send_msg() exactly once.

    This channel is valid only during the current invocation of the dispatch function; it is destroyed when the dispatch function returns. The application may not save a copy of the pointer and use it later elsewhere. Methods that do not make sense in the context of a message dispatch function (such as DbChannel::send_request() and DbChannel::close() ) will be rejected with EINVAL.

  • request

    Array of Dbts containing the message received from the remote site.

  • nrequest

    Specifies the number of elements in the request array.

  • cb_flags

    This flag is DB_REPMGR_NEED_RESPONSE if the message requires a response. Otherwise, it is 0.

This function does not return a value. If the function encounters an error, you can reflect the error back to the originator of the message by formatting an error message of your own design into the response.

flags

This parameter is currently unused, and must be set to 0.

Errors

The DbEnv::repmgr_msg_dispatch() method may fail and throw a DbException exception, encapsulating one of the following non-zero errors, or return one of the following non-zero errors:

EINVAL

If this method is called from a Base API application, or if an invalid flag value or parameter was specified.

Class

DbEnv

See Also

Replication and Related Methods