annotate OrthancFramework/Sources/DicomNetworking/TimeoutDicomConnectionManager.cpp @ 4792:434843934307 storage-cache

Added a StorageCache in the StorageAccessor
author Alain Mazy <am@osimis.io>
date Thu, 30 Sep 2021 12:14:19 +0200
parents d9473bd5ed43
children 7053502fbf97
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
4437
d9473bd5ed43 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4284
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
8 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
10 * the License, or (at your option) any later version.
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
15 * Lesser General Public License for more details.
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
18 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
19 * <http://www.gnu.org/licenses/>.
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "../PrecompiledHeaders.h"
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "TimeoutDicomConnectionManager.h"
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
2609
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
26 #include "../Logging.h"
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include "../OrthancException.h"
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 namespace Orthanc
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 static boost::posix_time::ptime GetNow()
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 return boost::posix_time::microsec_clock::universal_time();
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
3850
d729d6e8b484 removing useless abstraction IDicomConnectionManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
36
3851
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
37 TimeoutDicomConnectionManager::Lock::Lock(TimeoutDicomConnectionManager& that,
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
38 const std::string& localAet,
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
39 const RemoteModalityParameters& remote) :
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
40 that_(that),
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
41 lock_(that_.mutex_)
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
3851
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
43 // Calling "Touch()" will be done by the "~Lock()" destructor
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
44 that_.OpenInternal(localAet, remote);
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
45 }
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
46
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
47
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
48 TimeoutDicomConnectionManager::Lock::~Lock()
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
49 {
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
50 that_.TouchInternal();
3850
d729d6e8b484 removing useless abstraction IDicomConnectionManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
51 }
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
3850
d729d6e8b484 removing useless abstraction IDicomConnectionManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
53
3863
9973d10bc5c4 switch to DicomStoreUserConnection in Lua routing, C-MOVE handler and straight C-STORE
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3851
diff changeset
54 DicomStoreUserConnection& TimeoutDicomConnectionManager::Lock::GetConnection()
3850
d729d6e8b484 removing useless abstraction IDicomConnectionManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
55 {
3851
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
56 if (that_.connection_.get() == NULL)
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
57 {
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
58 // The allocation should have been done by "that_.Open()" in the constructor
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
59 throw OrthancException(ErrorCode_InternalError);
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
60 }
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
61 else
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
62 {
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
63 return *that_.connection_;
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
64 }
3850
d729d6e8b484 removing useless abstraction IDicomConnectionManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
65 }
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
3851
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
68 // Mutex must be locked
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
69 void TimeoutDicomConnectionManager::TouchInternal()
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 lastUse_ = GetNow();
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
3851
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
75 // Mutex must be locked
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
76 void TimeoutDicomConnectionManager::OpenInternal(const std::string& localAet,
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
77 const RemoteModalityParameters& remote)
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 {
3863
9973d10bc5c4 switch to DicomStoreUserConnection in Lua routing, C-MOVE handler and straight C-STORE
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3851
diff changeset
79 DicomAssociationParameters other(localAet, remote);
9973d10bc5c4 switch to DicomStoreUserConnection in Lua routing, C-MOVE handler and straight C-STORE
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3851
diff changeset
80
3851
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
81 if (connection_.get() == NULL ||
3863
9973d10bc5c4 switch to DicomStoreUserConnection in Lua routing, C-MOVE handler and straight C-STORE
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3851
diff changeset
82 !connection_->GetParameters().IsEqual(other))
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 {
3863
9973d10bc5c4 switch to DicomStoreUserConnection in Lua routing, C-MOVE handler and straight C-STORE
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3851
diff changeset
84 connection_.reset(new DicomStoreUserConnection(other));
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
3851
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
89 // Mutex must be locked
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
90 void TimeoutDicomConnectionManager::CloseInternal()
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 {
2609
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
92 if (connection_.get() != NULL)
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
93 {
4284
756126cd2219 moving all logs from DicomNetworking folder into the "dicom" category
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
94 CLOG(INFO, DICOM) << "Closing inactive DICOM association with modality: "
756126cd2219 moving all logs from DicomNetworking folder into the "dicom" category
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
95 << connection_->GetParameters().GetRemoteModality().GetApplicationEntityTitle();
2609
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
96
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
97 connection_.reset(NULL);
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
98 }
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
3851
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
102 void TimeoutDicomConnectionManager::SetInactivityTimeout(unsigned int milliseconds)
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 {
3851
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
104 boost::mutex::scoped_lock lock(mutex_);
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
105 timeout_ = boost::posix_time::milliseconds(milliseconds);
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
106 CloseInternal();
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
3851
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
110 unsigned int TimeoutDicomConnectionManager::GetInactivityTimeout()
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 {
3851
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
112 boost::mutex::scoped_lock lock(mutex_);
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
113 return static_cast<unsigned int>(timeout_.total_milliseconds());
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
114 }
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
115
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
116
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
117 void TimeoutDicomConnectionManager::CloseIfInactive()
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
118 {
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
119 boost::mutex::scoped_lock lock(mutex_);
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
120
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
121 if (connection_.get() != NULL &&
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
122 (GetNow() - lastUse_) >= timeout_)
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 {
3851
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3850
diff changeset
124 CloseInternal();
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 }