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 // from MongoDB
35 #include <mongo/client/dbclient.h>
36 
37 #include <list>
38 #include <memory>
39 #include <string>
40 #include <vector>
41 
45 
47  public fawkes::LoggingAspect,
49  public fawkes::ClockAspect,
53 {
54 public:
55  MongoDBThread();
56  virtual ~MongoDBThread();
57 
58  virtual void init();
59  virtual void loop();
60  virtual void finalize();
61 
62  virtual mongo::DBClientBase *create_client(const std::string &config_name = "");
63  virtual void delete_client(mongo::DBClientBase *client);
64 
65  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
66 protected:
67  virtual void
68  run()
69  {
70  Thread::run();
71  }
72 
73 private:
74  void init_client_configs();
75  void init_instance_configs();
76  void init_replicaset_configs();
77 
78 private:
79  std::map<std::string, std::shared_ptr<MongoDBClientConfig>> client_configs_;
80  std::map<std::string, std::shared_ptr<MongoDBInstanceConfig>> instance_configs_;
81  std::map<std::string, std::shared_ptr<MongoDBReplicaSetConfig>> replicaset_configs_;
82 
83  fawkes::MongoDBAspectIniFin mongodb_aspect_inifin_;
84 };
85 
86 #endif
Thread aspect that allows to obtain the current time from the clock.
Definition: clock.h:33
virtual void finalize()
Finalize the thread.
Client configuration.
Thread class encapsulation of pthreads.
Definition: thread.h:45
virtual ~MongoDBThread()
Destructor.
virtual void loop()
Code to execute in the thread.
MongoDB Thread.
MongoDB replica set configuration.
MongoDBAspect initializer/finalizer.
Thread aspect to log output.
Definition: logging.h:32
Interface for a MongoDB connection creator.
Aspect for thread producing threads.
Thread aspect provide a new aspect.
virtual mongo::DBClientBase * create_client(const std::string &config_name="")
Create a new MongoDB client.
Thread aspect to access configuration data.
Definition: configurable.h:32
MongoDBThread()
Constructor.
virtual void delete_client(mongo::DBClientBase *client)
Delete a client.
virtual void run()
Stub to see name in backtrace for easier debugging.
Client configuration.
virtual void init()
Initialize the thread.