Drizzled Public API Documentation

replication_services.h
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008-2009 Sun Microsystems, Inc.
00005  *  Copyright (C) 2009-2010 Jay Pipes <jaypipes@gmail.com>
00006  *
00007  *  Authors:
00008  *
00009  *    Jay Pipes <jaypipes@gmail.com>
00010  *
00011  *  This program is free software; you can redistribute it and/or modify
00012  *  it under the terms of the GNU General Public License as published by
00013  *  the Free Software Foundation; version 2 of the License.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU General Public License for more details.
00019  *
00020  *  You should have received a copy of the GNU General Public License
00021  *  along with this program; if not, write to the Free Software
00022  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00023  */
00024 
00025 #pragma once
00026 
00027 #include <drizzled/atomics.h>
00028 #include <drizzled/plugin/replication.h>
00029 
00030 #include <string>
00031 #include <vector>
00032 #include <utility>
00033 
00034 #include <drizzled/visibility.h>
00035 
00036 namespace drizzled
00037 {
00038 
00039 /* some forward declarations needed */
00040 class Session;
00041 class Table;
00042 
00043 namespace plugin
00044 {
00045   class TransactionReplicator;
00046   class TransactionApplier;
00047 }
00048 namespace message
00049 {
00050   class Transaction;
00051 }
00052 
00058 class DRIZZLED_API ReplicationServices
00059 {
00060 public:
00061   typedef uint64_t GlobalTransactionId;
00068   enum MessageType
00069   {
00070     TRANSACTION= 1, /* A GPB Transaction Message */
00071     BLOB= 2 /* A BLOB value */
00072   };
00073   typedef std::pair<plugin::TransactionReplicator *, plugin::TransactionApplier *> ReplicationPair;
00074   typedef std::vector<ReplicationPair> ReplicationStreams;
00087   bool evaluateRegisteredPlugins();
00095   plugin::ReplicationReturnCode pushTransactionMessage(Session &in_session,
00096                                                        message::Transaction &to_push);
00100   ReplicationServices();
00101 
00106   static inline ReplicationServices &singleton()
00107   {
00108     static ReplicationServices replication_services;
00109     return replication_services;
00110   }
00111 
00117   bool isActive() const;
00118 
00122   ReplicationStreams &getReplicationStreams();
00123 
00130   void attachReplicator(plugin::TransactionReplicator *in_replicator);
00131   
00138   void detachReplicator(plugin::TransactionReplicator *in_replicator);
00139   
00147   void attachApplier(plugin::TransactionApplier *in_applier, const std::string &requested_replicator);
00148   
00155   void detachApplier(plugin::TransactionApplier *in_applier);
00156 
00161   uint64_t getLastAppliedTimestamp() const;
00162 private:
00163   typedef std::vector<plugin::TransactionReplicator *> Replicators;
00164   typedef std::vector<std::pair<std::string, plugin::TransactionApplier *> > Appliers;
00169   bool is_active;
00174   atomic<uint64_t> last_applied_timestamp;
00176   Replicators replicators;
00178   Appliers appliers;
00180   ReplicationStreams replication_streams;
00185   void normalizeReplicatorName(std::string &name);
00186 };
00187 
00188 } /* namespace drizzled */
00189