AbstractConnectionPool.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/AbstractConnectionPool.h
22 
23  \brief This class defines the basic interface for a connection pool.
24 */
25 
26 #ifndef __TERRALIB_DATAACCESS_INTERNAL_ABSTRACTCONNECTIONPOOL_H
27 #define __TERRALIB_DATAACCESS_INTERNAL_ABSTRACTCONNECTIONPOOL_H
28 
29 // TerraLib
30 #include "../Config.h"
31 
32 // STL
33 #include <string>
34 
35 // Boost
36 #include <boost/utility.hpp>
37 
38 namespace te
39 {
40  namespace da
41  {
42  /*!
43  \class AbstractConnectionPool
44 
45  \brief This class defines the basic interface for a connection pool.
46 
47  A connection pool keeps a cache of physical connections to a data source.
48  These connections can be reused by the application when it receives new
49  requests for a connection.
50 
51  A connection pool is a way to improve performance and scalability when
52  multiple clients can share a smaller number of physical database connections.
53  It manages a set of connections to be used by the applications. In TerraLib,
54  each data source can have its own connection pool.
55 
56  This class takes part of the data source connection framework and it
57  is optionally used in a data source driver implementation.
58 
59  Notice that a given data source object can have its own connection pool.
60  So each data source can control the number of simultaneous opened connections.
61 
62  \sa ConnectionPoolManager
63  */
64  class TEDATAACCESSEXPORT AbstractConnectionPool : public boost::noncopyable
65  {
66  public:
67 
68  /** @name Pure Virtual Methods
69  * Methods that subclasses must implement.
70  */
71  //@{
72 
73  /*!
74  \brief It initializes the connections to be managed by the pool.
75 
76  \exception Exception It throws an exception if it is not possible to initialize the pool.
77 
78  \note Successive calls won't have effect.
79 
80  \note Thread-safe.
81  */
82  virtual void initialize() = 0;
83 
84  /*!
85  \brief It closes all connections and clears all resources managed by the pool.
86 
87  \exception Exception It may throws an exception if there is a connection in use or if it is not possible to stop the pool.
88 
89  \note Successive calls won't have effect.
90 
91  \note Thread-safe.
92  */
93  virtual void finalize() = 0;
94 
95  /*!
96  \brief It releases the connections that are not in use for a long time.
97 
98  This method will try to keep the pool with the minimum number
99  of opened connections. It will be invoked by the
100  connection pool manager when its thread wakeup.
101  It must check the idle connections and must destroy them.
102 
103  \note Thread-safe.
104  */
105  virtual void idle() = 0;
106 
107  /*!
108  \brief It checks if all the connections in the pool are valid (the communication channel is ok).
109 
110  \return It returns true if all the connections are valid (the communication channel is ok), otherwise it returns false.
111 
112  \note Thread-safe.
113  */
114  virtual bool isValid() const = 0;
115 
116  /*!
117  \brief It returns true if the connection pool is initialized, otherwise it returns false.
118 
119  \return True if the connection pool is initialized, otherwise it returns false.
120 
121  \note Thread-safe.
122  */
123  virtual bool isInitialized() const = 0;
124 
125  /*!
126  \brief It returns the number of connections in the pool.
127 
128  \return The number of the connections in the pool.
129 
130  \note Thread-safe.
131  */
132  virtual std::size_t getPoolSize() const = 0;
133 
134  /*!
135  \brief It returns the initial number of connections opened by the pool at its startup.
136 
137  \return The initial number of connections opened by the pool at its startup.
138 
139  \note Thread-safe.
140  */
141  virtual std::size_t getInitialPoolSize() const = 0;
142 
143  /*!
144  \brief It sets the initial number of connections opened by the pool at its startup.
145 
146  \param size It specifies the initial number of connections that
147  must be opened by the pool at its startup.
148 
149  \note The pool must be reset before the changes take effect.
150 
151  \note Thread-safe.
152  */
153  virtual void setInitialPoolSize(std::size_t size) = 0;
154 
155  /*!
156  \brief It returns the minimum number of connections managed by the pool.
157 
158  \return The minimum number of connections managed by the pool.
159 
160  \note Thread-safe.
161  */
162  virtual std::size_t getMinPoolSize() const = 0;
163 
164  /*!
165  \brief It sets the minimum number of connections managed by the pool.
166 
167  \param size The minimum number of connections that the pool must manage.
168 
169  \note The pool must be reset before the changes take effect.
170 
171  \note Thread-safe.
172  */
173  virtual void setMinPoolSize(std::size_t size) = 0;
174 
175  /*!
176  \brief It returns the maximum number of connections managed by the pool.
177 
178  \return The maximum number of connections managed by the pool.
179 
180  \note Thread-safe.
181  */
182  virtual std::size_t getMaxPoolSize() const = 0;
183 
184  /*!
185  \brief It sets the maximum number of connections managed by the pool.
186 
187  \param size The maximum number of connections that the pool must manage.
188 
189  \note The pool must be reset before the changes take effect.
190 
191  \note Thread-safe.
192  */
193  virtual void setMaxPoolSize(std::size_t size) = 0;
194 
195  //@}
196 
197  protected:
198 
199  /*! \brief Default constructor. */
201 
202  /*! \brief Virtual destructor. */
204  };
205 
206  } // end namespace da
207 } // end namespace te
208 
209 
210 #endif // __TERRALIB_DATAACCESS_INTERNAL_ABSTRACTCONNECTIONPOOL_H
211 
212 
virtual ~AbstractConnectionPool()
Virtual destructor.
AbstractConnectionPool()
Default constructor.
URI C++ Library.
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