Drizzled Public API Documentation

replication_slave.h

00001 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2011 David Shrewsbury
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 #pragma once
00022 
00023 #include <plugin/slave/queue_consumer.h>
00024 #include <plugin/slave/queue_producer.h>
00025 #include <plugin/slave/replication_schema.h>
00026 #include <drizzled/plugin/daemon.h>
00027 #include <boost/thread.hpp>
00028 
00029 namespace drizzled
00030 {
00031   class Session;
00032 }
00033 
00034 namespace slave
00035 {
00036 
00037 class ReplicationSlave : public drizzled::plugin::Daemon
00038 {
00039 public:
00040 
00041   ReplicationSlave(const std::string &config)
00042     : drizzled::plugin::Daemon("Replication Slave"),
00043       _config_file(config),
00044       _initial_max_commit_id(0)
00045   {}
00046   
00047   ~ReplicationSlave()
00048   {
00049     _consumer_thread.interrupt();
00050     _producer_thread.interrupt();
00051   }
00052 
00053   void startup(drizzled::Session &session);
00054 
00058   const std::string &getError() const
00059   {
00060     return _error;
00061   }
00062 
00074   void setMaxCommitId(uint64_t value)
00075   {
00076     /* must tell producer to set its cached value */
00077     _producer.setCachedMaxCommitId(value);
00078     /* setting this indicates that we should store it permanently */
00079     _initial_max_commit_id= value;
00080   }
00081 
00082 private:
00083   std::string _config_file;
00084   std::string _error;
00085 
00086   QueueConsumer _consumer;
00087   QueueProducer _producer;
00088 
00090   boost::thread _consumer_thread;
00091 
00093   boost::thread _producer_thread;
00094 
00095   uint64_t _initial_max_commit_id;
00096 
00106   bool initWithConfig();
00107 };
00108   
00109 } /* namespace slave */
00110