ConnectionPoolManager.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/dataaccess/datasource/ConnectionPoolManager.h
22 
23  \brief A singleton for managing the connection pools available in the system.
24 */
25 
26 #ifndef __TERRALIB_DATAACCESS_INTERNAL_CONNECTIONPOOLMANAGER_H
27 #define __TERRALIB_DATAACCESS_INTERNAL_CONNECTIONPOOLMANAGER_H
28 
29 // TerraLib
30 #include "../../common/Singleton.h"
31 #include "../Config.h"
32 
33 // STL
34 #include <vector>
35 
36 // Boost
37 #include <boost/thread.hpp>
38 #include <boost/thread/mutex.hpp>
39 
40 namespace te
41 {
42  namespace da
43  {
44  class AbstractConnectionPool;
45 
46  /*!
47  \class ConnectionPoolManager
48 
49  \brief A singleton for managing the connection pools available in the system.
50 
51  \sa AbstractConnectionPool
52  */
53  class TEDATAACCESSEXPORT ConnectionPoolManager : public te::common::Singleton<ConnectionPoolManager>
54  {
56 
57  public:
58 
59  /*!
60  \brief It adds the given pool to the list of monitored pools.
61 
62  \param pool The pool to be monitored.
63  */
64  void add(AbstractConnectionPool* pool);
65 
66  /*!
67  \brief It removes (un-register) the pool from the monitoring list.
68 
69  \param pool The pool to be removed from the monitoring list.
70  */
71  void remove(AbstractConnectionPool* pool);
72 
73  /*! \brief It starts a new thread of execution that will monitore all the connection pools. */
74  void start();
75 
76  /*! \brief It stops the connection pools monitoring thread. */
77  void stop();
78 
79  /*!
80  \brief It returns true if the manager was already started.
81 
82  \return True if the manager was already started and are monitoring the pools.
83  */
84  bool isInitialized() const;
85 
86  protected:
87 
88  /*! \brief Singleton constructor is protected. */
90 
91  /*! \brief Singleton destructor is protected. */
93 
94  public:
95 
96  /*!
97  \brief This static method encapsulates the execution thread that monitores all the pools.
98 
99  \note This method will be excuted every x seconds.
100  */
101  void monitore();
102 
103  private:
104 
105  std::vector<AbstractConnectionPool*> m_pools; //!< The list of monitored pools.
106  boost::mutex m_mtx; //!< A mutex to lock the manager access.
107  boost::thread m_thread; //!< The monitoring thread.
108  bool m_initialized; //!< A flag that indicates if the manager is monitoring the pools.
109  };
110 
111  } // end namespace da
112 } // end namespace te
113 
114 #endif // __TERRALIB_DATAACCESS_INTERNAL_CONNECTIONPOOLMANAGER_H
115 
116 
bool m_initialized
A flag that indicates if the manager is monitoring the pools.
boost::thread m_thread
The monitoring thread.
URI C++ Library.
std::vector< AbstractConnectionPool * > m_pools
The list of monitored pools.
A singleton for managing the connection pools available in the system.
boost::mutex m_mtx
A mutex to lock the manager access.
This class defines the basic interface for a connection pool.
#define TEDATAACCESSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:97
Template support for singleton pattern.
Definition: Singleton.h:100