Mercurial > hg > orthanc-transfers
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 |
rev | line source |
---|---|
0 | 1 /** |
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 | 4 * |
5 * This program is free software: you can redistribute it and/or | |
6 * modify it under the terms of the GNU Affero General Public License | |
7 * as published by the Free Software Foundation, either version 3 of | |
8 * the License, or (at your option) any later version. | |
9 * | |
10 * This program is distributed in the hope that it will be useful, but | |
11 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * Affero General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU Affero General Public License | |
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 **/ | |
18 | |
19 | |
20 #include "PluginContext.h" | |
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 | 23 #include <Logging.h> |
0 | 24 |
25 | |
26 namespace OrthancPlugins | |
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 | 29 size_t targetBucketSize, |
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 | 34 pushTransactions_(maxPushTransactions), |
35 semaphore_(threadsCount), | |
12 | 36 pluginUuid_(Orthanc::Toolbox::GenerateUuid()), |
0 | 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 | 41 { |
42 cache_.SetMaxMemorySize(memoryCacheSize); | |
43 | |
17 | 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 | 46 << OrthancPlugins::ConvertToMegabytes(memoryCacheSize) << " MB"; |
47 LOG(INFO) << "Transfers accelerator will aim at HTTP queries of size: " | |
17 | 48 << OrthancPlugins::ConvertToKilobytes(targetBucketSize_) << " KB"; |
0 | 49 LOG(INFO) << "Transfers accelerator will be able to receive up to " |
17 | 50 << maxPushTransactions << " push transaction(s) at once"; |
51 LOG(INFO) << "Transfers accelerator will retry " | |
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 | 55 } |
56 | |
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 | 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 | 61 return singleton_; |
62 } | |
63 | |
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 | 66 size_t targetBucketSize, |
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 | 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 | 74 } |
75 | |
76 | |
77 PluginContext& PluginContext::GetInstance() | |
78 { | |
79 if (GetSingleton().get() == NULL) | |
80 { | |
81 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
82 } | |
83 else | |
84 { | |
85 return *GetSingleton(); | |
86 } | |
87 } | |
88 | |
89 | |
90 void PluginContext::Finalize() | |
91 { | |
92 if (GetSingleton().get() != NULL) | |
93 { | |
94 GetSingleton().reset(); | |
95 } | |
96 } | |
97 } |