44
using namespace drizzled;
43
46
namespace drizzle_plugin {
47
namespace logging_gearman {
45
49
namespace po= boost::program_options;
51
bool updateHost(Session *, set_var*);
52
bool updateFunction(Session *, set_var*);
47
53
/* TODO make this dynamic as needed */
48
54
static const int MAX_MSG_LEN= 32*1024;
288
* This function changes the current gearman host to the parameter passed to the function.
290
* @return True on success, False on error.
292
bool setHost(std::string &new_host)
294
gearman_return_t tmp_ret;
297
New server is added to the list of servers using gearman_client_add_server.
298
If the call does not result in error, then all the servers are removed from the list and
299
new server only is added. This is done to ensure that a bad server url does not replace
300
the existing server url.
301
TODO Create a new instance of gearman_client_st and add the new server in it. If success, release the
302
old gearman_client_st and use new instance of gearman_client_st everywhere.
304
tmp_ret= gearman_client_add_server(&_gearman_client,
305
new_host.c_str(), 0);
306
if (tmp_ret != GEARMAN_SUCCESS)
308
drizzled::errmsg_printf(drizzled::error::ERROR, _("fail gearman_client_add_server(): %s"),
309
gearman_client_error(&_gearman_client));
313
gearman_client_remove_servers(&_gearman_client);
314
gearman_client_add_server(&_gearman_client, new_host.c_str(), 0);
315
sysvar_host= new_host;
320
* This function changes the gearman function with the new one.
322
* @return True on success (as we dont have to do anything except updating the function string, this always return true.)
324
bool setFunction(std::string &new_function)
326
sysvar_function= new_function;
333
* @return sysvar_host
335
std::string& getHost()
341
* Getter for function
343
* @return sysvar_function
345
std::string& getFunction()
347
return sysvar_function;
282
351
static LoggingGearman *handler= NULL;
284
static int logging_gearman_plugin_init(drizzled::module::Context &context)
354
* This function is called when the value of gearman host is updated dynamically from the drizzle server
356
* @return False on success, True on error
358
bool updateHost(Session *, set_var* var)
360
if (not var->value->str_value.empty())
362
std::string newHost(var->value->str_value.data());
363
if (handler->setHost(newHost))
364
return false; //success
366
return true; // error
368
errmsg_printf(error::ERROR, _("logging_gearman_host cannot be NULL"));
369
return true; // error
373
* This function is called when the value of gearman function is updated dynamically
375
* @return False on error, True on success
377
bool updateFunction(Session *, set_var* var)
379
if (not var->value->str_value.empty())
381
std::string newFunction(var->value->str_value.data());
382
if (handler->setFunction(newFunction))
383
return false; //success
385
return true; // error
387
errmsg_printf(error::ERROR, _("logging_gearman_function cannot be NULL"));
388
return true; // error
392
static int init(drizzled::module::Context &context)
286
394
const drizzled::module::option_map &vm= context.getOptions();
288
396
handler= new LoggingGearman(vm["host"].as<std::string>(),
289
397
vm["function"].as<std::string>());
290
398
context.add(handler);
291
context.registerVariable(new drizzled::sys_var_const_string_val("host", vm["host"].as<std::string>()));
292
context.registerVariable(new drizzled::sys_var_const_string_val("function", vm["function"].as<std::string>()));
399
context.registerVariable(new sys_var_std_string("host", handler->getHost(), NULL, &updateHost));
400
context.registerVariable(new sys_var_std_string("function", handler->getFunction(), NULL, &updateFunction));
315
424
N_("Logs queries to a Gearman server"),
316
425
drizzled::PLUGIN_LICENSE_GPL,
317
drizzle_plugin::logging_gearman_plugin_init,
426
drizzle_plugin::logging_gearman::init,
319
drizzle_plugin::init_options
428
drizzle_plugin::logging_gearman::init_options
321
430
DRIZZLE_DECLARE_PLUGIN_END;