annotate Plugin/PluginContext.cpp @ 72:d60d1a3a7357 OrthancTransfers-1.4

fix md5
author Alain Mazy <am@osimis.io>
date Tue, 26 Mar 2024 10:16:15 +0100
parents b09adb6aa199
children 1e396fb509ca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Transfers accelerator plugin for Orthanc
33
44a0430d7899 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 25
diff changeset
3 * Copyright (C) 2018-2021 Osimis S.A., Belgium
0
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 *
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * modify it under the terms of the GNU Affero General Public License
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * as published by the Free Software Foundation, either version 3 of
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * the License, or (at your option) any later version.
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 *
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful, but
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * Affero General Public License for more details.
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 *
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU Affero General Public License
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 **/
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 #include "PluginContext.h"
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
25
dfc43678aecb replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
22 #include <Compatibility.h> // For std::unique_ptr
20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 19
diff changeset
23 #include <Logging.h>
0
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 namespace OrthancPlugins
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 {
8
4c3437217518 fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
28 PluginContext::PluginContext(size_t threadsCount,
0
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 size_t targetBucketSize,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 size_t maxPushTransactions,
10
c9e28e31262e new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 9
diff changeset
31 size_t memoryCacheSize,
55
b09adb6aa199 new PeerConnectivityTimeout configuration
Alain Mazy <am@osimis.io>
parents: 33
diff changeset
32 unsigned int maxHttpRetries,
b09adb6aa199 new PeerConnectivityTimeout configuration
Alain Mazy <am@osimis.io>
parents: 33
diff changeset
33 unsigned int peerConnectivityTimeout) :
0
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 pushTransactions_(maxPushTransactions),
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 semaphore_(threadsCount),
12
34b1875c8e3a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
36 pluginUuid_(Orthanc::Toolbox::GenerateUuid()),
0
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 threadsCount_(threadsCount),
10
c9e28e31262e new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 9
diff changeset
38 targetBucketSize_(targetBucketSize),
55
b09adb6aa199 new PeerConnectivityTimeout configuration
Alain Mazy <am@osimis.io>
parents: 33
diff changeset
39 maxHttpRetries_(maxHttpRetries),
b09adb6aa199 new PeerConnectivityTimeout configuration
Alain Mazy <am@osimis.io>
parents: 33
diff changeset
40 peerConnectivityTimeout_(peerConnectivityTimeout)
0
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 cache_.SetMaxMemorySize(memoryCacheSize);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
17
7d56105ab084 improved logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
44 LOG(INFO) << "Transfers accelerator will use " << threadsCount_ << " thread(s) to run HTTP queries";
55
b09adb6aa199 new PeerConnectivityTimeout configuration
Alain Mazy <am@osimis.io>
parents: 33
diff changeset
45 LOG(INFO) << "Transfers accelerator will keep local DICOM files in a memory cache of size: "
0
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 << OrthancPlugins::ConvertToMegabytes(memoryCacheSize) << " MB";
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 LOG(INFO) << "Transfers accelerator will aim at HTTP queries of size: "
17
7d56105ab084 improved logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
48 << OrthancPlugins::ConvertToKilobytes(targetBucketSize_) << " KB";
0
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 LOG(INFO) << "Transfers accelerator will be able to receive up to "
17
7d56105ab084 improved logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
50 << maxPushTransactions << " push transaction(s) at once";
7d56105ab084 improved logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
51 LOG(INFO) << "Transfers accelerator will retry "
7d56105ab084 improved logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
52 << maxHttpRetries_ << " time(s) if some HTTP query fails";
55
b09adb6aa199 new PeerConnectivityTimeout configuration
Alain Mazy <am@osimis.io>
parents: 33
diff changeset
53 LOG(INFO) << "Transfers accelerator will use "
b09adb6aa199 new PeerConnectivityTimeout configuration
Alain Mazy <am@osimis.io>
parents: 33
diff changeset
54 << peerConnectivityTimeout_ << " seconds as a timeout when checking peers connectivity";
0
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
25
dfc43678aecb replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
58 std::unique_ptr<PluginContext>& PluginContext::GetSingleton()
0
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
25
dfc43678aecb replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
60 static std::unique_ptr<PluginContext> singleton_;
0
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 return singleton_;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
8
4c3437217518 fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
65 void PluginContext::Initialize(size_t threadsCount,
0
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 size_t targetBucketSize,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 size_t maxPushTransactions,
10
c9e28e31262e new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 9
diff changeset
68 size_t memoryCacheSize,
55
b09adb6aa199 new PeerConnectivityTimeout configuration
Alain Mazy <am@osimis.io>
parents: 33
diff changeset
69 unsigned int maxHttpRetries,
b09adb6aa199 new PeerConnectivityTimeout configuration
Alain Mazy <am@osimis.io>
parents: 33
diff changeset
70 unsigned int peerConnectivityTimeout)
0
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
8
4c3437217518 fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
72 GetSingleton().reset(new PluginContext(threadsCount, targetBucketSize,
55
b09adb6aa199 new PeerConnectivityTimeout configuration
Alain Mazy <am@osimis.io>
parents: 33
diff changeset
73 maxPushTransactions, memoryCacheSize, maxHttpRetries, peerConnectivityTimeout));
0
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 PluginContext& PluginContext::GetInstance()
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 if (GetSingleton().get() == NULL)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 else
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 return *GetSingleton();
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 void PluginContext::Finalize()
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 if (GetSingleton().get() != NULL)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 GetSingleton().reset();
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 }