Mercurial > hg > orthanc-transfers
annotate Framework/PushMode/ActivePushTransactions.cpp @ 77:1e396fb509ca default
updated copyright, as Orthanc Team now replaces Osimis
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 30 May 2024 22:44:10 +0200 |
parents | 44a0430d7899 |
children |
rev | line source |
---|---|
0 | 1 /** |
2 * Transfers accelerator plugin for Orthanc | |
77
1e396fb509ca
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
33
diff
changeset
|
3 * Copyright (C) 2018-2023 Osimis S.A., Belgium |
1e396fb509ca
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
33
diff
changeset
|
4 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
1e396fb509ca
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
33
diff
changeset
|
5 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "ActivePushTransactions.h" | |
23 | |
24 #include "../DownloadArea.h" | |
25 | |
25
dfc43678aecb
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
26 #include <Compatibility.h> // For std::unique_ptr |
20 | 27 #include <Logging.h> |
0 | 28 |
29 | |
30 namespace OrthancPlugins | |
31 { | |
32 class ActivePushTransactions::Transaction : public boost::noncopyable | |
33 { | |
34 private: | |
35 DownloadArea area_; | |
36 std::vector<TransferBucket> buckets_; | |
37 BucketCompression compression_; | |
38 | |
39 public: | |
40 Transaction(const std::vector<DicomInstanceInfo>& instances, | |
41 const std::vector<TransferBucket>& buckets, | |
42 BucketCompression compression) : | |
43 area_(instances), | |
44 buckets_(buckets), | |
45 compression_(compression) | |
46 { | |
47 } | |
48 | |
49 DownloadArea& GetDownloadArea() | |
50 { | |
51 return area_; | |
52 } | |
53 | |
54 BucketCompression GetCompression() const | |
55 { | |
56 return compression_; | |
57 } | |
58 | |
59 const TransferBucket& GetBucket(size_t index) const | |
60 { | |
61 if (index >= buckets_.size()) | |
62 { | |
63 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
64 } | |
65 else | |
66 { | |
67 return buckets_[index]; | |
68 } | |
69 } | |
70 | |
71 void Store(size_t bucketIndex, | |
72 const void* data, | |
73 size_t size) | |
74 { | |
75 area_.WriteBucket(GetBucket(bucketIndex), data, size, compression_); | |
76 } | |
77 }; | |
78 | |
79 | |
8
4c3437217518
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
80 void ActivePushTransactions::FinalizeTransaction(const std::string& transactionUuid, |
0 | 81 bool commit) |
82 { | |
83 boost::mutex::scoped_lock lock(mutex_); | |
84 | |
85 Content::iterator found = content_.find(transactionUuid); | |
86 if (found == content_.end()) | |
87 { | |
88 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); | |
89 } | |
90 | |
91 assert(found->second != NULL); | |
92 if (commit) | |
93 { | |
8
4c3437217518
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
94 found->second->GetDownloadArea().Commit(); |
0 | 95 } |
96 | |
97 delete found->second; | |
98 content_.erase(found); | |
99 index_.Invalidate(transactionUuid); | |
100 } | |
101 | |
102 | |
103 ActivePushTransactions::~ActivePushTransactions() | |
104 { | |
105 for (Content::iterator it = content_.begin(); it != content_.end(); ++it) | |
106 { | |
107 LOG(WARNING) << "Discarding an uncommitted push transaction " | |
108 << "in the transfers accelerator: " << it->first; | |
109 | |
110 assert(it->second != NULL); | |
111 delete it->second; | |
112 } | |
113 } | |
114 | |
115 | |
116 void ActivePushTransactions::ListTransactions(std::vector<std::string>& target) | |
117 { | |
118 boost::mutex::scoped_lock lock(mutex_); | |
119 | |
120 target.clear(); | |
121 target.reserve(content_.size()); | |
122 | |
123 for (Content::const_iterator it = content_.begin(); | |
124 it != content_.end(); ++it) | |
125 { | |
126 target.push_back(it->first); | |
127 } | |
128 } | |
129 | |
130 | |
131 std::string ActivePushTransactions::CreateTransaction(const std::vector<DicomInstanceInfo>& instances, | |
132 const std::vector<TransferBucket>& buckets, | |
133 BucketCompression compression) | |
134 { | |
135 std::string uuid = Orthanc::Toolbox::GenerateUuid(); | |
25
dfc43678aecb
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
136 std::unique_ptr<Transaction> tmp(new Transaction(instances, buckets, compression)); |
0 | 137 |
138 LOG(INFO) << "Creating transaction to receive " << instances.size() | |
139 << " instances (" << ConvertToMegabytes(tmp->GetDownloadArea().GetTotalSize()) | |
140 << "MB) in push mode: " << uuid; | |
141 | |
142 { | |
143 boost::mutex::scoped_lock lock(mutex_); | |
144 | |
145 // Drop the oldest active transaction, if not enough place | |
146 if (content_.size() == maxSize_) | |
147 { | |
148 std::string oldest = index_.RemoveOldest(); | |
149 | |
150 Content::iterator transaction = content_.find(oldest); | |
151 assert(transaction != content_.end() && | |
152 transaction->second != NULL); | |
153 | |
154 delete transaction->second; | |
155 content_.erase(transaction); | |
156 | |
157 LOG(WARNING) << "An inactive push transaction has been discarded: " << oldest; | |
158 } | |
159 | |
160 index_.Add(uuid); | |
161 content_[uuid] = tmp.release(); | |
162 } | |
163 | |
164 return uuid; | |
165 } | |
166 | |
167 | |
8
4c3437217518
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
168 void ActivePushTransactions::Store(const std::string& transactionUuid, |
0 | 169 size_t bucketIndex, |
170 const void* data, | |
171 size_t size) | |
172 { | |
173 boost::mutex::scoped_lock lock(mutex_); | |
174 | |
175 Content::iterator found = content_.find(transactionUuid); | |
176 if (found == content_.end()) | |
177 { | |
178 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); | |
179 } | |
180 | |
181 assert(found->second != NULL); | |
182 | |
183 index_.MakeMostRecent(transactionUuid); | |
184 | |
185 found->second->Store(bucketIndex, data, size); | |
186 } | |
187 } |