comparison Framework/Plugins/IndexConnectionsPool.h @ 374:4a3985088723 db-protobuf

moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 28 Mar 2023 14:51:17 +0200
parents
children 824d70ce85ff
comparison
equal deleted inserted replaced
373:be7de633695c 374:4a3985088723
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
7 *
8 * This program is free software: you can redistribute it and/or
9 * modify it under the terms of the GNU Affero General Public License
10 * as published by the Free Software Foundation, either version 3 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 **/
21
22
23 #pragma once
24
25 #include "IndexBackend.h"
26
27 #include <MultiThreading/SharedMessageQueue.h>
28
29 namespace OrthancDatabases
30 {
31 class IndexConnectionsPool : public boost::noncopyable
32 {
33 private:
34 class ManagerReference;
35
36 std::unique_ptr<IndexBackend> backend_;
37 OrthancPluginContext* context_;
38 boost::shared_mutex connectionsMutex_;
39 size_t countConnections_;
40 std::list<DatabaseManager*> connections_;
41 Orthanc::SharedMessageQueue availableConnections_;
42
43 public:
44 IndexConnectionsPool(IndexBackend* backend,
45 size_t countConnections);
46
47 ~IndexConnectionsPool();
48
49 OrthancPluginContext* GetContext() const
50 {
51 return context_;
52 }
53
54 void OpenConnections();
55
56 void CloseConnections();
57
58 class Accessor : public boost::noncopyable
59 {
60 private:
61 boost::shared_lock<boost::shared_mutex> lock_;
62 IndexConnectionsPool& pool_;
63 DatabaseManager* manager_;
64
65 public:
66 Accessor(IndexConnectionsPool& pool);
67
68 ~Accessor();
69
70 IndexBackend& GetBackend() const;
71
72 DatabaseManager& GetManager() const;
73 };
74 };
75 }