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
54{
55public:
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() */
67protected:
68 virtual void
70 {
71 Thread::run();
72 }
73
74private:
75 void init_client_configs();
76 void init_instance_configs();
77 void init_replicaset_configs();
78
79private:
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
Client configuration.
Client configuration.
MongoDB replica set configuration.
MongoDB Thread.
MongoDBThread()
Constructor.
virtual ~MongoDBThread()
Destructor.
virtual void run()
Stub to see name in backtrace for easier debugging.
virtual void finalize()
Finalize the thread.
virtual mongocxx::client * create_client(const std::string &config_name="")
Create a new MongoDB client.
virtual void init()
Initialize the thread.
virtual void delete_client(mongocxx::client *client)
Delete a client.
virtual void loop()
Code to execute in the thread.
Thread aspect provide a new aspect.
Thread aspect that allows to obtain the current time from the clock.
Definition: clock.h:34
Thread aspect to access configuration data.
Definition: configurable.h:33
Thread aspect to log output.
Definition: logging.h:33
MongoDBAspect initializer/finalizer.
Interface for a MongoDB connection creator.
Aspect for thread producing threads.
Thread class encapsulation of pthreads.
Definition: thread.h:46