~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/default_replicator/default_replicator.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-03-18 12:12:31 UTC
  • Revision ID: james.westby@ubuntu.com-20100318121231-k6g1xe6cshbwa0f8
Tags: upstream-2010.03.1347
ImportĀ upstreamĀ versionĀ 2010.03.1347

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008-2009 Sun Microsystems
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 */
 
20
 
 
21
/**
 
22
 * @file
 
23
 *
 
24
 * Defines the implementation of the default replicator.
 
25
 *
 
26
 * @see drizzled/plugin/transaction_replicator.h
 
27
 * @see drizzled/plugin/transaction_applier.h
 
28
 *
 
29
 * @details
 
30
 *
 
31
 * This is a very simple implementation.  All we do is pass along the 
 
32
 * event to the supplier.  This is meant as a skeleton replicator only.
 
33
 */
 
34
 
 
35
#include "config.h"
 
36
#include <drizzled/plugin/registry.h>
 
37
#include <drizzled/plugin.h>
 
38
#include <drizzled/gettext.h>
 
39
#include <drizzled/plugin/transaction_applier.h>
 
40
 
 
41
#include "default_replicator.h"
 
42
 
 
43
#include <vector>
 
44
#include <string>
 
45
 
 
46
using namespace std;
 
47
using namespace drizzled;
 
48
 
 
49
static bool sysvar_default_replicator_enable= false;
 
50
 
 
51
bool DefaultReplicator::isEnabled() const
 
52
{
 
53
  return sysvar_default_replicator_enable;
 
54
}
 
55
 
 
56
void DefaultReplicator::enable()
 
57
{
 
58
  sysvar_default_replicator_enable= true;
 
59
}
 
60
 
 
61
void DefaultReplicator::disable()
 
62
{
 
63
  sysvar_default_replicator_enable= false;
 
64
}
 
65
 
 
66
void DefaultReplicator::replicate(plugin::TransactionApplier *in_applier, message::Transaction &to_replicate)
 
67
{
 
68
  /* 
 
69
   * We do absolutely nothing but call the applier's apply() method, passing
 
70
   * along the supplied Transaction.  Yep, told you it was simple...
 
71
   */
 
72
  in_applier->apply(to_replicate);
 
73
}
 
74
 
 
75
static DefaultReplicator *default_replicator= NULL; /* The singleton replicator */
 
76
 
 
77
static int init(plugin::Registry &registry)
 
78
{
 
79
  default_replicator= new DefaultReplicator("default_replicator");
 
80
  registry.add(default_replicator);
 
81
  return 0;
 
82
}
 
83
 
 
84
static int deinit(plugin::Registry &registry)
 
85
{
 
86
  if (default_replicator)
 
87
  {
 
88
    registry.remove(default_replicator);
 
89
    delete default_replicator;
 
90
  }
 
91
  return 0;
 
92
}
 
93
 
 
94
static DRIZZLE_SYSVAR_BOOL(
 
95
  enable,
 
96
  sysvar_default_replicator_enable,
 
97
  PLUGIN_VAR_NOCMDARG,
 
98
  N_("Enable default replicator"),
 
99
  NULL, /* check func */
 
100
  NULL, /* update func */
 
101
  false /* default */);
 
102
 
 
103
static drizzle_sys_var* default_replicator_system_variables[]= {
 
104
  DRIZZLE_SYSVAR(enable),
 
105
  NULL
 
106
};
 
107
 
 
108
DRIZZLE_DECLARE_PLUGIN
 
109
{
 
110
  DRIZZLE_VERSION_ID,
 
111
  "default_replicator",
 
112
  "0.1",
 
113
  "Jay Pipes",
 
114
  N_("Default Replicator"),
 
115
  PLUGIN_LICENSE_GPL,
 
116
  init, /* Plugin Init */
 
117
  deinit, /* Plugin Deinit */
 
118
  default_replicator_system_variables, /* system variables */
 
119
  NULL    /* config options */
 
120
}
 
121
DRIZZLE_DECLARE_PLUGIN_END;