Fawkes API  Fawkes Development Version
mongodb_thread.h
1 
2 /***************************************************************************
3  * mongodb_thread.h - MongoDB thread
4  *
5  * Created: Sun Dec 05 23:25:20 2010
6  * Copyright 2006-2015 Tim Niemueller [www.niemueller.de]
7  ****************************************************************************/
8 
9 /* This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Library General Public License for more details.
18  *
19  * Read the full text in the LICENSE.GPL file in the doc directory.
20  */
21 
22 #ifndef _PLUGINS_MONGODB_MONGODB_THREAD_H_
23 #define _PLUGINS_MONGODB_MONGODB_THREAD_H_
24 
25 #include <aspect/aspect_provider.h>
26 #include <aspect/clock.h>
27 #include <aspect/configurable.h>
28 #include <aspect/logging.h>
29 #include <aspect/thread_producer.h>
30 #include <core/threading/thread.h>
31 #include <plugins/mongodb/aspect/mongodb_conncreator.h>
32 #include <plugins/mongodb/aspect/mongodb_inifin.h>
33 
34 #include <mongocxx/instance.hpp>
35 
36 // from MongoDB
37 #include <list>
38 #include <memory>
39 #include <mongocxx/client.hpp>
40 #include <string>
41 #include <vector>
42 
46 
47 class MongoDBThread : public fawkes::Thread,
48  public fawkes::LoggingAspect,
50  public fawkes::ClockAspect,
54 {
55 public:
56  MongoDBThread();
57  virtual ~MongoDBThread();
58 
59  virtual void init();
60  virtual void loop();
61  virtual void finalize();
62 
63  virtual mongocxx::client *create_client(const std::string &config_name = "");
64  virtual void delete_client(mongocxx::client *client);
65 
66  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
67 protected:
68  virtual void
69  run()
70  {
71  Thread::run();
72  }
73 
74 private:
75  void init_client_configs();
76  void init_instance_configs();
77  void init_replicaset_configs();
78 
79 private:
80  std::map<std::string, std::shared_ptr<MongoDBClientConfig>> client_configs_;
81  std::map<std::string, std::shared_ptr<MongoDBInstanceConfig>> instance_configs_;
82  std::map<std::string, std::shared_ptr<MongoDBReplicaSetConfig>> replicaset_configs_;
83 
84  fawkes::MongoDBAspectIniFin mongodb_aspect_inifin_;
85  std::unique_ptr<mongocxx::instance> instance_;
86 };
87 
88 #endif
MongoDBThread
Definition: mongodb_thread.h:46
MongoDBClientConfig
Client configuration.
Definition: mongodb_client_config.h:35
MongoDBThread::finalize
virtual void finalize()
Finalize the thread.
Definition: mongodb_thread.cpp:203
fawkes::MongoDBConnCreator
Definition: mongodb_conncreator.h:40
MongoDBThread::~MongoDBThread
virtual ~MongoDBThread()
Destructor.
Definition: mongodb_thread.cpp:48
fawkes::ThreadProducerAspect
Definition: thread_producer.h:36
fawkes::AspectProviderAspect
Definition: aspect_provider.h:39
MongoDBThread::loop
virtual void loop()
Code to execute in the thread.
Definition: mongodb_thread.cpp:226
MongoDBThread::delete_client
virtual void delete_client(mongocxx::client *client)
Delete a client.
Definition: mongodb_thread.cpp:246
fawkes::MongoDBAspectIniFin
Definition: mongodb_inifin.h:37
MongoDBReplicaSetConfig
Definition: mongodb_replicaset_config.h:46
fawkes::LoggingAspect
Definition: logging.h:36
MongoDBThread::MongoDBThread
MongoDBThread()
Constructor.
Definition: mongodb_thread.cpp:40
MongoDBThread::init
virtual void init()
Initialize the thread.
Definition: mongodb_thread.cpp:53
MongoDBThread::run
virtual void run()
Stub to see name in backtrace for easier debugging.
Definition: mongodb_thread.h:68
MongoDBInstanceConfig
Client configuration.
Definition: mongodb_instance_config.h:40
MongoDBThread::create_client
virtual mongocxx::client * create_client(const std::string &config_name="")
Create a new MongoDB client.
Definition: mongodb_thread.cpp:231
fawkes::Thread
Definition: thread.h:44
fawkes::ConfigurableAspect
Definition: configurable.h:36
fawkes::ClockAspect
Definition: clock.h:38