Fledge
An open source edge computing platform for industrial users
connection_manager.h
1 #ifndef _CONNECTION_MANAGER_H
2 #define _CONNECTION_MANAGER_H
3 /*
4  * Fledge storage service.
5  *
6  * Copyright (c) 2017 OSisoft, LLC
7  *
8  * Released under the Apache 2.0 Licence
9  *
10  * Author: Mark Riddoch
11  */
12 
13 #include <plugin_api.h>
14 #include <list>
15 #include <mutex>
16 
17 class Connection;
18 
23  public:
25  void growPool(unsigned int);
26  unsigned int shrinkPool(unsigned int);
28  void release(Connection *);
29  void shutdown();
30  void setError(const char *, const char *, bool);
31  PLUGIN_ERROR *getError()
32  {
33  return &lastError;
34  }
35  void setMaxReadingRows(long rows)
36  {
37  m_maxReadingRows = rows;
38  }
39 
40  private:
42  static ConnectionManager *instance;
43  std::list<Connection *> idle;
44  std::list<Connection *> inUse;
45  std::mutex idleLock;
46  std::mutex inUseLock;
47  std::mutex errorLock;
48  PLUGIN_ERROR lastError;
49  bool m_logSQL;
50  long m_maxReadingRows;
51 };
52 
53 #endif
void growPool(unsigned int)
Grow the connection pool by the number of connections specified.
Definition: connection_manager.cpp:59
unsigned int shrinkPool(unsigned int)
Attempt to shrink the number of connections in the idle pool.
Definition: connection_manager.cpp:82
Connection * allocate()
Allocate a connection from the idle pool.
Definition: connection_manager.cpp:110
Singleton class to manage Postgres connection pool.
Definition: connection_manager.h:22
void shutdown()
Called at shutdown.
Definition: connection_manager.cpp:35
static ConnectionManager * getInstance()
Return the singleton instance of the connection manager.
Definition: connection_manager.cpp:44
void release(Connection *)
Release a connection back to the idle pool for reallocation.
Definition: connection_manager.cpp:142
void setError(const char *, const char *, bool)
Set the last error information for a plugin.
Definition: connection_manager.cpp:159
Definition: connection.h:32
Structure used by plugins to return error information.
Definition: plugin_api.h:44