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