Fledge
An open source edge computing platform for industrial users
ConnectionManager Class Reference

Singleton class to manage Postgres connection pool. More...

#include <connection_manager.h>

Collaboration diagram for ConnectionManager:

Public Member Functions

void growPool (unsigned int)
 Grow the connection pool by the number of connections specified. More...
 
unsigned int shrinkPool (unsigned int)
 Attempt to shrink the number of connections in the idle pool. More...
 
Connectionallocate ()
 Allocate a connection from the idle pool. More...
 
void release (Connection *)
 Release a connection back to the idle pool for reallocation. More...
 
void shutdown ()
 Called at shutdown. More...
 
void setError (const char *, const char *, bool)
 Set the last error information for a plugin. More...
 
PLUGIN_ERRORgetError ()
 
void setMaxReadingRows (long rows)
 
void growPool (unsigned int)
 
unsigned int shrinkPool (unsigned int)
 
Connectionallocate ()
 
bool attachNewDb (std::string &path, std::string &alias)
 Attach a database to all the connections, idle and inuse. More...
 
bool attachRequestNewDb (int newDbId, sqlite3 *dbHandle)
 Adds to all the connections a request to attach a database. More...
 
bool detachNewDb (std::string &alias)
 Detach a database from all the connections. More...
 
void release (Connection *)
 
void shutdown ()
 
void setError (const char *, const char *, bool)
 
PLUGIN_ERRORgetError ()
 
void background ()
 Background thread used to execute periodic tasks and oversee the database activity. More...
 
void setVacuumInterval (long hours)
 
bool allowMoreDatabases ()
 Determine if we can allow another database to be created and attached to all the connections. More...
 
void setConfiguration (ConfigCategory *category)
 
std::string getDBConfiguration ()
 Return the pragma configuration for the database.
 
void growPool (unsigned int)
 
unsigned int shrinkPool (unsigned int)
 
Connectionallocate ()
 
void release (Connection *)
 
void shutdown ()
 
void setError (const char *, const char *, bool)
 
PLUGIN_ERRORgetError ()
 
void background ()
 
void setVacuumInterval (long hours)
 
void setPersist (bool persist, const std::string &filename="")
 
bool persist ()
 
std::string filename ()
 
void setPurgeBlockSize (unsigned long purgeBlockSize)
 Set the purge block size in each of the connections. More...
 

Static Public Member Functions

static ConnectionManagergetInstance ()
 Return the singleton instance of the connection manager. More...
 
static ConnectionManagergetInstance ()
 
static ConnectionManagergetInstance ()
 

Protected Attributes

bool m_trace
 
bool m_shutdown
 
std::thread * m_background
 
long m_vacuumInterval
 
unsigned int m_descriptorLimit
 
unsigned int m_attachedDatabases
 
DiskSpaceMonitorm_diskSpaceMonitor
 
ConfigCategorym_config
 
bool m_persist
 
std::string m_filename
 
unsigned long m_purgeBlockSize
 

Detailed Description

Singleton class to manage Postgres connection pool.

Singleton class to manage SQLite3 connection pool.

Member Function Documentation

◆ allocate()

Connection * ConnectionManager::allocate ( )

Allocate a connection from the idle pool.

If no connection is available add a new connection

◆ allowMoreDatabases()

bool ConnectionManager::allowMoreDatabases ( )

Determine if we can allow another database to be created and attached to all the connections.

Returns
True if we can create another database.

◆ attachNewDb()

bool ConnectionManager::attachNewDb ( std::string &  path,
std::string &  alias 
)

Attach a database to all the connections, idle and inuse.

Parameters
path- path of the database to attach
alias- alias to be assigned to the attached database

◆ attachRequestNewDb()

bool ConnectionManager::attachRequestNewDb ( int  newDbId,
sqlite3 *  dbHandle 
)

Adds to all the connections a request to attach a database.

  • Parameters
    newDbId- database id to attach
    dbHandle- dbhandle for which the attach request should NOT be added

◆ background()

void ConnectionManager::background ( )

Background thread used to execute periodic tasks and oversee the database activity.

We will run the SQLite vacuum command periodically to allow space to be reclaimed

We will runt he SQLite vacuum command periodically to allow space to be reclaimed

◆ detachNewDb()

bool ConnectionManager::detachNewDb ( std::string &  alias)

Detach a database from all the connections.

◆ getInstance()

ConnectionManager * ConnectionManager::getInstance ( )
static

Return the singleton instance of the connection manager.

if none was created then create it.

◆ growPool()

void ConnectionManager::growPool ( unsigned int  delta)

Grow the connection pool by the number of connections specified.

Parameters
deltaThe number of connections to add to the pool

◆ release()

void ConnectionManager::release ( Connection conn)

Release a connection back to the idle pool for reallocation.

Parameters
connThe connection to release.

◆ setError()

void ConnectionManager::setError ( const char *  source,
const char *  description,
bool  retryable 
)

Set the last error information for a plugin.

Parameters
sourceThe source of the error
descriptionThe error description
retryableFlag to determien if the error condition is transient

◆ setPurgeBlockSize()

void ConnectionManager::setPurgeBlockSize ( unsigned long  purgeBlockSize)

Set the purge block size in each of the connections.

Parameters
purgeBlockSizeThe requested purgeBlockSize

◆ shrinkPool()

unsigned int ConnectionManager::shrinkPool ( unsigned int  delta)

Attempt to shrink the number of connections in the idle pool.

Parameters
deltaNumber of connections to attempt to remove
Returns
The number of connections removed.

◆ shutdown()

void ConnectionManager::shutdown ( )

Called at shutdown.

Shrink the idle pool, this will have the side effect of closing the connections to the database.


The documentation for this class was generated from the following files: