1 //
2 // SessionPoolContainer.h
3 //
4 // Library: Data
5 // Package: SessionPooling
6 // Module: SessionPoolContainer
7 //
8 // Definition of the SessionPoolContainer class.
9 //
10 // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
11 // and Contributors.
12 //
13 // SPDX-License-Identifier: BSL-1.0
14 //
15
16
17 #ifndef Data_SessionPoolContainer_INCLUDED
18 #define Data_SessionPoolContainer_INCLUDED
19
20
21 #include "Poco/Data/Data.h"
22 #include "Poco/Data/Session.h"
23 #include "Poco/Data/SessionPool.h"
24 #include "Poco/String.h"
25 #include "Poco/Mutex.h"
26
27
28 namespace Poco {
29 namespace Data {
30
31
32 class Data_API SessionPoolContainer
33 /// This class implements container of session pools.
34 {
35 public:
36 SessionPoolContainer();
37 /// Creates the SessionPoolContainer for sessions with the given session parameters.
38
39 ~SessionPoolContainer();
40 /// Destroys the SessionPoolContainer.
41
42 void add(SessionPool* pPool);
43 /// Adds existing session pool to the container.
44 /// Throws SessionPoolExistsException if pool already exists.
45
46 Session add(const std::string& sessionKey,
47 const std::string& connectionString,
48 int minSessions = 1,
49 int maxSessions = 32,
50 int idleTime = 60);
51 /// Adds a new session pool to the container and returns a Session from
52 /// newly created pool. If pool already exists, request to add is silently
53 /// ignored and session is returned from the existing pool.
54
55 bool has(const std::string& name) const;
56 /// Returns true if the requested name exists, false otherwise.
57
58 bool isActive(const std::string& sessionKey,
59 const std::string& connectionString = "") const;
60 /// Returns true if the session is active (i.e. not shut down).
61 /// If connectionString is empty string, sessionKey must be a
62 /// fully qualified session name as registered with the pool
63 /// container.
64
65 Session get(const std::string& name);
66 /// Returns the requested Session.
67 /// Throws NotFoundException if session is not found.
68
69 SessionPool& getPool(const std::string& name);
70 /// Returns a SessionPool reference.
71 /// Throws NotFoundException if session is not found.
72
73 void remove(const std::string& name);
74 /// Removes a SessionPool.
75
76 int count() const;
77 /// Returns the number of session pols in the container.
78
79 void shutdown();
80 /// Shuts down all the held pools.
81
82 private:
83 typedef std::map<std::string, AutoPtr<SessionPool>, Poco::CILess> SessionPoolMap;
84
85 SessionPoolContainer(const SessionPoolContainer&);
86 SessionPoolContainer& operator = (const SessionPoolContainer&);
87
88 SessionPoolMap _sessionPools;
89 Poco::FastMutex _mutex;
90 };
91
92
has(const std::string & name)93 inline bool SessionPoolContainer::has(const std::string& name) const
94 {
95 return _sessionPools.find(name) != _sessionPools.end();
96 }
97
98
remove(const std::string & name)99 inline void SessionPoolContainer::remove(const std::string& name)
100 {
101 _sessionPools.erase(name);
102 }
103
104
count()105 inline int SessionPoolContainer::count() const
106 {
107 return static_cast<int>(_sessionPools.size());
108 }
109
110
111 } } // namespace Poco::Data
112
113
114 #endif // Data_SessionPoolContainer_INCLUDED
115