Mercurial > hg > orthanc-transfers
annotate Framework/PushMode/ActivePushTransactions.cpp @ 37:9708addb5a87
added 'Resources' and 'Originator' in the jobs 'Content'
author | Alain Mazy <am@osimis.io> |
---|---|
date | Wed, 08 Jun 2022 17:11:13 +0200 |
parents | 44a0430d7899 |
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 "ActivePushTransactions.h" | |
21 | |
22 #include "../DownloadArea.h" | |
23 | |
25
dfc43678aecb
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
24 #include <Compatibility.h> // For std::unique_ptr |
20 | 25 #include <Logging.h> |
0 | 26 |
27 | |
28 namespace OrthancPlugins | |
29 { | |
30 class ActivePushTransactions::Transaction : public boost::noncopyable | |
31 { | |
32 private: | |
33 DownloadArea area_; | |
34 std::vector<TransferBucket> buckets_; | |
35 BucketCompression compression_; | |
36 | |
37 public: | |
38 Transaction(const std::vector<DicomInstanceInfo>& instances, | |
39 const std::vector<TransferBucket>& buckets, | |
40 BucketCompression compression) : | |
41 area_(instances), | |
42 buckets_(buckets), | |
43 compression_(compression) | |
44 { | |
45 } | |
46 | |
47 DownloadArea& GetDownloadArea() | |
48 { | |
49 return area_; | |
50 } | |
51 | |
52 BucketCompression GetCompression() const | |
53 { | |
54 return compression_; | |
55 } | |
56 | |
57 const TransferBucket& GetBucket(size_t index) const | |
58 { | |
59 if (index >= buckets_.size()) | |
60 { | |
61 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
62 } | |
63 else | |
64 { | |
65 return buckets_[index]; | |
66 } | |
67 } | |
68 | |
69 void Store(size_t bucketIndex, | |
70 const void* data, | |
71 size_t size) | |
72 { | |
73 area_.WriteBucket(GetBucket(bucketIndex), data, size, compression_); | |
74 } | |
75 }; | |
76 | |
77 | |
8
4c3437217518
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
78 void ActivePushTransactions::FinalizeTransaction(const std::string& transactionUuid, |
0 | 79 bool commit) |
80 { | |
81 boost::mutex::scoped_lock lock(mutex_); | |
82 | |
83 Content::iterator found = content_.find(transactionUuid); | |
84 if (found == content_.end()) | |
85 { | |
86 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); | |
87 } | |
88 | |
89 assert(found->second != NULL); | |
90 if (commit) | |
91 { | |
8
4c3437217518
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
92 found->second->GetDownloadArea().Commit(); |
0 | 93 } |
94 | |
95 delete found->second; | |
96 content_.erase(found); | |
97 index_.Invalidate(transactionUuid); | |
98 } | |
99 | |
100 | |
101 ActivePushTransactions::~ActivePushTransactions() | |
102 { | |
103 for (Content::iterator it = content_.begin(); it != content_.end(); ++it) | |
104 { | |
105 LOG(WARNING) << "Discarding an uncommitted push transaction " | |
106 << "in the transfers accelerator: " << it->first; | |
107 | |
108 assert(it->second != NULL); | |
109 delete it->second; | |
110 } | |
111 } | |
112 | |
113 | |
114 void ActivePushTransactions::ListTransactions(std::vector<std::string>& target) | |
115 { | |
116 boost::mutex::scoped_lock lock(mutex_); | |
117 | |
118 target.clear(); | |
119 target.reserve(content_.size()); | |
120 | |
121 for (Content::const_iterator it = content_.begin(); | |
122 it != content_.end(); ++it) | |
123 { | |
124 target.push_back(it->first); | |
125 } | |
126 } | |
127 | |
128 | |
129 std::string ActivePushTransactions::CreateTransaction(const std::vector<DicomInstanceInfo>& instances, | |
130 const std::vector<TransferBucket>& buckets, | |
131 BucketCompression compression) | |
132 { | |
133 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
|
134 std::unique_ptr<Transaction> tmp(new Transaction(instances, buckets, compression)); |
0 | 135 |
136 LOG(INFO) << "Creating transaction to receive " << instances.size() | |
137 << " instances (" << ConvertToMegabytes(tmp->GetDownloadArea().GetTotalSize()) | |
138 << "MB) in push mode: " << uuid; | |
139 | |
140 { | |
141 boost::mutex::scoped_lock lock(mutex_); | |
142 | |
143 // Drop the oldest active transaction, if not enough place | |
144 if (content_.size() == maxSize_) | |
145 { | |
146 std::string oldest = index_.RemoveOldest(); | |
147 | |
148 Content::iterator transaction = content_.find(oldest); | |
149 assert(transaction != content_.end() && | |
150 transaction->second != NULL); | |
151 | |
152 delete transaction->second; | |
153 content_.erase(transaction); | |
154 | |
155 LOG(WARNING) << "An inactive push transaction has been discarded: " << oldest; | |
156 } | |
157 | |
158 index_.Add(uuid); | |
159 content_[uuid] = tmp.release(); | |
160 } | |
161 | |
162 return uuid; | |
163 } | |
164 | |
165 | |
8
4c3437217518
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
166 void ActivePushTransactions::Store(const std::string& transactionUuid, |
0 | 167 size_t bucketIndex, |
168 const void* data, | |
169 size_t size) | |
170 { | |
171 boost::mutex::scoped_lock lock(mutex_); | |
172 | |
173 Content::iterator found = content_.find(transactionUuid); | |
174 if (found == content_.end()) | |
175 { | |
176 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); | |
177 } | |
178 | |
179 assert(found->second != NULL); | |
180 | |
181 index_.MakeMostRecent(transactionUuid); | |
182 | |
183 found->second->Store(bucketIndex, data, size); | |
184 } | |
185 } |