Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2013-2016, Regents of the University of California. |
Alexander Afanasyev | 8811b35 | 2013-01-02 12:51:15 -0800 | [diff] [blame] | 4 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame^] | 5 | * This file is part of ChronoShare, a decentralized file sharing application over NDN. |
Alexander Afanasyev | 8811b35 | 2013-01-02 12:51:15 -0800 | [diff] [blame] | 6 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame^] | 7 | * ChronoShare is free software: you can redistribute it and/or modify it under the terms |
| 8 | * of the GNU General Public License as published by the Free Software Foundation, either |
| 9 | * version 3 of the License, or (at your option) any later version. |
Alexander Afanasyev | 8811b35 | 2013-01-02 12:51:15 -0800 | [diff] [blame] | 10 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame^] | 11 | * ChronoShare is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. |
Alexander Afanasyev | 8811b35 | 2013-01-02 12:51:15 -0800 | [diff] [blame] | 14 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame^] | 15 | * You should have received copies of the GNU General Public License along with |
| 16 | * ChronoShare, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | * See AUTHORS.md for complete list of ChronoShare authors and contributors. |
Alexander Afanasyev | 8811b35 | 2013-01-02 12:51:15 -0800 | [diff] [blame] | 19 | */ |
| 20 | |
Alexander Afanasyev | f4cde4e | 2016-12-25 13:42:57 -0800 | [diff] [blame] | 21 | #include "fetch-manager.hpp" |
Alexander Afanasyev | 49a1852 | 2013-01-18 17:49:04 -0800 | [diff] [blame] | 22 | #include <boost/make_shared.hpp> |
| 23 | #include <boost/ref.hpp> |
| 24 | #include <boost/throw_exception.hpp> |
Zhenkai Zhu | 354d46d | 2013-02-06 13:49:48 -0800 | [diff] [blame] | 25 | #include <boost/lexical_cast.hpp> |
Alexander Afanasyev | 548d38d | 2013-01-26 16:36:06 -0800 | [diff] [blame] | 26 | |
Alexander Afanasyev | f4cde4e | 2016-12-25 13:42:57 -0800 | [diff] [blame] | 27 | #include "simple-interval-generator.hpp" |
| 28 | #include "logging.hpp" |
Alexander Afanasyev | fc72036 | 2013-01-24 21:49:48 -0800 | [diff] [blame] | 29 | |
Alexander Afanasyev | ff8d9dc | 2013-01-26 00:45:08 -0800 | [diff] [blame] | 30 | INIT_LOGGER ("FetchManager"); |
Alexander Afanasyev | 49a1852 | 2013-01-18 17:49:04 -0800 | [diff] [blame] | 31 | |
| 32 | using namespace boost; |
| 33 | using namespace std; |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame] | 34 | using namespace Ndnx; |
Alexander Afanasyev | 49a1852 | 2013-01-18 17:49:04 -0800 | [diff] [blame] | 35 | |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 36 | //The disposer object function |
| 37 | struct fetcher_disposer { void operator() (Fetcher *delete_this) { delete delete_this; } }; |
| 38 | |
Alexander Afanasyev | 548d38d | 2013-01-26 16:36:06 -0800 | [diff] [blame] | 39 | static const string SCHEDULE_FETCHES_TAG = "ScheduleFetches"; |
| 40 | |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame] | 41 | FetchManager::FetchManager (Ndnx::NdnxWrapperPtr ndnx, |
Alexander Afanasyev | 473346f | 2013-02-07 14:14:45 -0800 | [diff] [blame] | 42 | const Mapping &mapping, |
| 43 | const Name &broadcastForwardingHint, |
| 44 | uint32_t parallelFetches, // = 3 |
| 45 | const SegmentCallback &defaultSegmentCallback, |
| 46 | const FinishCallback &defaultFinishCallback, |
| 47 | const FetchTaskDbPtr &taskDb |
| 48 | ) |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame] | 49 | : m_ndnx (ndnx) |
Zhenkai Zhu | 3d1beca | 2013-01-23 14:55:32 -0800 | [diff] [blame] | 50 | , m_mapping (mapping) |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 51 | , m_maxParallelFetches (parallelFetches) |
| 52 | , m_currentParallelFetches (0) |
Alexander Afanasyev | 548d38d | 2013-01-26 16:36:06 -0800 | [diff] [blame] | 53 | , m_scheduler (new Scheduler) |
Zhenkai Zhu | ab9215c | 2013-01-28 23:42:28 -0800 | [diff] [blame] | 54 | , m_executor (new Executor(1)) |
Zhenkai Zhu | a014738 | 2013-01-29 15:57:27 -0800 | [diff] [blame] | 55 | , m_defaultSegmentCallback(defaultSegmentCallback) |
| 56 | , m_defaultFinishCallback(defaultFinishCallback) |
Zhenkai Zhu | da68688 | 2013-01-29 22:32:24 -0800 | [diff] [blame] | 57 | , m_taskDb(taskDb) |
Alexander Afanasyev | 473346f | 2013-02-07 14:14:45 -0800 | [diff] [blame] | 58 | , m_broadcastHint (broadcastForwardingHint) |
Alexander Afanasyev | 8811b35 | 2013-01-02 12:51:15 -0800 | [diff] [blame] | 59 | { |
Alexander Afanasyev | 548d38d | 2013-01-26 16:36:06 -0800 | [diff] [blame] | 60 | m_scheduler->start (); |
Zhenkai Zhu | ab9215c | 2013-01-28 23:42:28 -0800 | [diff] [blame] | 61 | m_executor->start(); |
Alexander Afanasyev | 548d38d | 2013-01-26 16:36:06 -0800 | [diff] [blame] | 62 | |
Alexander Afanasyev | 4aecad8 | 2013-01-31 15:27:08 -0800 | [diff] [blame] | 63 | m_scheduleFetchesTask = Scheduler::schedulePeriodicTask (m_scheduler, |
| 64 | make_shared<SimpleIntervalGenerator> (300), // no need to check to often. if needed, will be rescheduled |
| 65 | bind (&FetchManager::ScheduleFetches, this), SCHEDULE_FETCHES_TAG); |
Zhenkai Zhu | da68688 | 2013-01-29 22:32:24 -0800 | [diff] [blame] | 66 | // resume un-finished fetches if there is any |
| 67 | if (m_taskDb) |
| 68 | { |
| 69 | m_taskDb->foreachTask(bind(&FetchManager::Enqueue, this, _1, _2, _3, _4, _5)); |
| 70 | } |
Alexander Afanasyev | 49a1852 | 2013-01-18 17:49:04 -0800 | [diff] [blame] | 71 | } |
Alexander Afanasyev | a199f97 | 2013-01-02 19:37:26 -0800 | [diff] [blame] | 72 | |
Alexander Afanasyev | 49a1852 | 2013-01-18 17:49:04 -0800 | [diff] [blame] | 73 | FetchManager::~FetchManager () |
| 74 | { |
Alexander Afanasyev | 548d38d | 2013-01-26 16:36:06 -0800 | [diff] [blame] | 75 | m_scheduler->shutdown (); |
Zhenkai Zhu | ab9215c | 2013-01-28 23:42:28 -0800 | [diff] [blame] | 76 | m_executor->shutdown(); |
| 77 | |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame] | 78 | m_ndnx.reset (); |
Alexander Afanasyev | 1d1cc83 | 2013-02-05 20:03:36 -0800 | [diff] [blame] | 79 | |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 80 | m_fetchList.clear_and_dispose (fetcher_disposer ()); |
Alexander Afanasyev | 49a1852 | 2013-01-18 17:49:04 -0800 | [diff] [blame] | 81 | } |
Alexander Afanasyev | 8811b35 | 2013-01-02 12:51:15 -0800 | [diff] [blame] | 82 | |
Zhenkai Zhu | a014738 | 2013-01-29 15:57:27 -0800 | [diff] [blame] | 83 | // Enqueue using default callbacks |
| 84 | void |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame] | 85 | FetchManager::Enqueue (const Ndnx::Name &deviceName, const Ndnx::Name &baseName, |
Zhenkai Zhu | a014738 | 2013-01-29 15:57:27 -0800 | [diff] [blame] | 86 | uint64_t minSeqNo, uint64_t maxSeqNo, int priority) |
| 87 | { |
| 88 | Enqueue(deviceName, baseName, m_defaultSegmentCallback, m_defaultFinishCallback, minSeqNo, maxSeqNo, priority); |
| 89 | } |
| 90 | |
Alexander Afanasyev | 49a1852 | 2013-01-18 17:49:04 -0800 | [diff] [blame] | 91 | void |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame] | 92 | FetchManager::Enqueue (const Ndnx::Name &deviceName, const Ndnx::Name &baseName, |
Zhenkai Zhu | 3d1beca | 2013-01-23 14:55:32 -0800 | [diff] [blame] | 93 | const SegmentCallback &segmentCallback, const FinishCallback &finishCallback, |
| 94 | uint64_t minSeqNo, uint64_t maxSeqNo, int priority/*PRIORITY_NORMAL*/) |
Alexander Afanasyev | 49a1852 | 2013-01-18 17:49:04 -0800 | [diff] [blame] | 95 | { |
Zhenkai Zhu | 454bae2 | 2013-01-24 19:27:54 -0800 | [diff] [blame] | 96 | // Assumption for the following code is minSeqNo <= maxSeqNo |
| 97 | if (minSeqNo > maxSeqNo) |
| 98 | { |
| 99 | return; |
| 100 | } |
| 101 | |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 102 | // we may need to guarantee that LookupLocator will gives an answer and not throw exception... |
Alexander Afanasyev | 21a166e | 2013-01-20 16:04:41 -0800 | [diff] [blame] | 103 | Name forwardingHint; |
Zhenkai Zhu | 3d1beca | 2013-01-23 14:55:32 -0800 | [diff] [blame] | 104 | forwardingHint = m_mapping (deviceName); |
Alexander Afanasyev | 21a166e | 2013-01-20 16:04:41 -0800 | [diff] [blame] | 105 | |
Alexander Afanasyev | 1d1cc83 | 2013-02-05 20:03:36 -0800 | [diff] [blame] | 106 | if (m_taskDb) |
| 107 | { |
| 108 | m_taskDb->addTask(deviceName, baseName, minSeqNo, maxSeqNo, priority); |
| 109 | } |
Zhenkai Zhu | da68688 | 2013-01-29 22:32:24 -0800 | [diff] [blame] | 110 | |
Alexander Afanasyev | bc8bf23 | 2013-01-29 11:19:17 -0800 | [diff] [blame] | 111 | unique_lock<mutex> lock (m_parellelFetchMutex); |
| 112 | |
| 113 | _LOG_TRACE ("++++ Create fetcher: " << baseName); |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame] | 114 | Fetcher *fetcher = new Fetcher (m_ndnx, |
Alexander Afanasyev | bc8bf23 | 2013-01-29 11:19:17 -0800 | [diff] [blame] | 115 | m_executor, |
| 116 | segmentCallback, |
| 117 | finishCallback, |
Zhenkai Zhu | da68688 | 2013-01-29 22:32:24 -0800 | [diff] [blame] | 118 | bind (&FetchManager::DidFetchComplete, this, _1, _2, _3), |
Alexander Afanasyev | bc8bf23 | 2013-01-29 11:19:17 -0800 | [diff] [blame] | 119 | bind (&FetchManager::DidNoDataTimeout, this, _1), |
| 120 | deviceName, baseName, minSeqNo, maxSeqNo, |
| 121 | boost::posix_time::seconds (30), |
| 122 | forwardingHint); |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 123 | |
| 124 | switch (priority) |
| 125 | { |
| 126 | case PRIORITY_HIGH: |
Alexander Afanasyev | bc8bf23 | 2013-01-29 11:19:17 -0800 | [diff] [blame] | 127 | _LOG_TRACE ("++++ Push front fetcher: " << fetcher->GetName ()); |
| 128 | m_fetchList.push_front (*fetcher); |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 129 | break; |
| 130 | |
| 131 | case PRIORITY_NORMAL: |
| 132 | default: |
Alexander Afanasyev | bc8bf23 | 2013-01-29 11:19:17 -0800 | [diff] [blame] | 133 | _LOG_TRACE ("++++ Push back fetcher: " << fetcher->GetName ()); |
| 134 | m_fetchList.push_back (*fetcher); |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 135 | break; |
| 136 | } |
| 137 | |
Alexander Afanasyev | bc8bf23 | 2013-01-29 11:19:17 -0800 | [diff] [blame] | 138 | _LOG_DEBUG ("++++ Reschedule fetcher task"); |
Alexander Afanasyev | 548d38d | 2013-01-26 16:36:06 -0800 | [diff] [blame] | 139 | m_scheduler->rescheduleTaskAt (m_scheduleFetchesTask, 0); |
| 140 | // ScheduleFetches (); // will start a fetch if m_currentParallelFetches is less than max, otherwise does nothing |
Alexander Afanasyev | 49a1852 | 2013-01-18 17:49:04 -0800 | [diff] [blame] | 141 | } |
Alexander Afanasyev | e41e7d2 | 2013-01-19 15:13:47 -0800 | [diff] [blame] | 142 | |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 143 | void |
| 144 | FetchManager::ScheduleFetches () |
Alexander Afanasyev | e41e7d2 | 2013-01-19 15:13:47 -0800 | [diff] [blame] | 145 | { |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 146 | unique_lock<mutex> lock (m_parellelFetchMutex); |
| 147 | |
Alexander Afanasyev | 548d38d | 2013-01-26 16:36:06 -0800 | [diff] [blame] | 148 | boost::posix_time::ptime currentTime = date_time::second_clock<boost::posix_time::ptime>::universal_time (); |
Alexander Afanasyev | f975623 | 2013-01-28 16:42:20 -0800 | [diff] [blame] | 149 | boost::posix_time::ptime nextSheduleCheck = currentTime + posix_time::seconds (300); // no reason to have anything, but just in case |
Alexander Afanasyev | 548d38d | 2013-01-26 16:36:06 -0800 | [diff] [blame] | 150 | |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 151 | for (FetchList::iterator item = m_fetchList.begin (); |
| 152 | m_currentParallelFetches < m_maxParallelFetches && item != m_fetchList.end (); |
| 153 | item++) |
| 154 | { |
Alexander Afanasyev | 21a166e | 2013-01-20 16:04:41 -0800 | [diff] [blame] | 155 | if (item->IsActive ()) |
Alexander Afanasyev | f8b22bf | 2013-01-26 17:28:11 -0800 | [diff] [blame] | 156 | { |
| 157 | _LOG_DEBUG ("Item is active"); |
| 158 | continue; |
| 159 | } |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 160 | |
Zhenkai Zhu | 354d46d | 2013-02-06 13:49:48 -0800 | [diff] [blame] | 161 | if (item->IsTimedWait ()) |
| 162 | { |
| 163 | _LOG_DEBUG ("Item is in timed-wait"); |
| 164 | continue; |
| 165 | } |
| 166 | |
Alexander Afanasyev | 548d38d | 2013-01-26 16:36:06 -0800 | [diff] [blame] | 167 | if (currentTime < item->GetNextScheduledRetry ()) |
Alexander Afanasyev | f8b22bf | 2013-01-26 17:28:11 -0800 | [diff] [blame] | 168 | { |
Alexander Afanasyev | f975623 | 2013-01-28 16:42:20 -0800 | [diff] [blame] | 169 | if (item->GetNextScheduledRetry () < nextSheduleCheck) |
| 170 | nextSheduleCheck = item->GetNextScheduledRetry (); |
| 171 | |
Alexander Afanasyev | f8b22bf | 2013-01-26 17:28:11 -0800 | [diff] [blame] | 172 | _LOG_DEBUG ("Item is delayed"); |
| 173 | continue; |
| 174 | } |
Alexander Afanasyev | 548d38d | 2013-01-26 16:36:06 -0800 | [diff] [blame] | 175 | |
Alexander Afanasyev | ff8d9dc | 2013-01-26 00:45:08 -0800 | [diff] [blame] | 176 | _LOG_DEBUG ("Start fetching of " << item->GetName ()); |
| 177 | |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 178 | m_currentParallelFetches ++; |
Alexander Afanasyev | bc8bf23 | 2013-01-29 11:19:17 -0800 | [diff] [blame] | 179 | _LOG_TRACE ("++++ RESTART PIPELINE: " << item->GetName ()); |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 180 | item->RestartPipeline (); |
| 181 | } |
Alexander Afanasyev | f975623 | 2013-01-28 16:42:20 -0800 | [diff] [blame] | 182 | |
Alexander Afanasyev | e10e5f2 | 2013-02-08 22:10:13 -0800 | [diff] [blame] | 183 | m_scheduler->rescheduleTaskAt (m_scheduleFetchesTask, (nextSheduleCheck - currentTime).total_seconds ()); |
Alexander Afanasyev | e41e7d2 | 2013-01-19 15:13:47 -0800 | [diff] [blame] | 184 | } |
| 185 | |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 186 | void |
Alexander Afanasyev | d6c2a90 | 2013-01-19 21:24:30 -0800 | [diff] [blame] | 187 | FetchManager::DidNoDataTimeout (Fetcher &fetcher) |
Alexander Afanasyev | e41e7d2 | 2013-01-19 15:13:47 -0800 | [diff] [blame] | 188 | { |
Alexander Afanasyev | ff8d9dc | 2013-01-26 00:45:08 -0800 | [diff] [blame] | 189 | _LOG_DEBUG ("No data timeout for " << fetcher.GetName () << " with forwarding hint: " << fetcher.GetForwardingHint ()); |
| 190 | |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 191 | { |
| 192 | unique_lock<mutex> lock (m_parellelFetchMutex); |
| 193 | m_currentParallelFetches --; |
| 194 | // no need to do anything with the m_fetchList |
| 195 | } |
Alexander Afanasyev | d6c2a90 | 2013-01-19 21:24:30 -0800 | [diff] [blame] | 196 | |
Alexander Afanasyev | 84894d3 | 2013-02-08 22:27:12 -0800 | [diff] [blame] | 197 | if (fetcher.GetForwardingHint ().size () == 0) |
Alexander Afanasyev | 548d38d | 2013-01-26 16:36:06 -0800 | [diff] [blame] | 198 | { |
Alexander Afanasyev | 84894d3 | 2013-02-08 22:27:12 -0800 | [diff] [blame] | 199 | // will be tried initially and again after empty forwarding hint |
Alexander Afanasyev | 548d38d | 2013-01-26 16:36:06 -0800 | [diff] [blame] | 200 | |
| 201 | /// @todo Handle potential exception |
| 202 | Name forwardingHint; |
| 203 | forwardingHint = m_mapping (fetcher.GetDeviceName ()); |
Alexander Afanasyev | 84894d3 | 2013-02-08 22:27:12 -0800 | [diff] [blame] | 204 | |
| 205 | if (forwardingHint.size () == 0) |
| 206 | { |
| 207 | // make sure that we will try broadcast forwarding hint eventually |
| 208 | fetcher.SetForwardingHint (m_broadcastHint); |
| 209 | } |
| 210 | else |
| 211 | { |
| 212 | fetcher.SetForwardingHint (forwardingHint); |
| 213 | } |
| 214 | } |
| 215 | else if (fetcher.GetForwardingHint () == m_broadcastHint) |
| 216 | { |
| 217 | // will be tried after broadcast forwarding hint |
| 218 | fetcher.SetForwardingHint (Name ("/")); |
Alexander Afanasyev | 548d38d | 2013-01-26 16:36:06 -0800 | [diff] [blame] | 219 | } |
| 220 | else |
| 221 | { |
Alexander Afanasyev | 84894d3 | 2013-02-08 22:27:12 -0800 | [diff] [blame] | 222 | // will be tried after normal forwarding hint |
Alexander Afanasyev | 473346f | 2013-02-07 14:14:45 -0800 | [diff] [blame] | 223 | fetcher.SetForwardingHint (m_broadcastHint); |
Alexander Afanasyev | 548d38d | 2013-01-26 16:36:06 -0800 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | double delay = fetcher.GetRetryPause (); |
| 227 | if (delay < 1) // first time |
| 228 | { |
| 229 | delay = 1; |
| 230 | } |
| 231 | else |
| 232 | { |
| 233 | delay = std::min (2*delay, 300.0); // 5 minutes max |
| 234 | } |
| 235 | |
| 236 | fetcher.SetRetryPause (delay); |
| 237 | fetcher.SetNextScheduledRetry (date_time::second_clock<boost::posix_time::ptime>::universal_time () + posix_time::seconds (delay)); |
Alexander Afanasyev | f975623 | 2013-01-28 16:42:20 -0800 | [diff] [blame] | 238 | |
| 239 | m_scheduler->rescheduleTaskAt (m_scheduleFetchesTask, 0); |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | void |
Zhenkai Zhu | da68688 | 2013-01-29 22:32:24 -0800 | [diff] [blame] | 243 | FetchManager::DidFetchComplete (Fetcher &fetcher, const Name &deviceName, const Name &baseName) |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 244 | { |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 245 | { |
| 246 | unique_lock<mutex> lock (m_parellelFetchMutex); |
| 247 | m_currentParallelFetches --; |
Alexander Afanasyev | 1d1cc83 | 2013-02-05 20:03:36 -0800 | [diff] [blame] | 248 | |
| 249 | if (m_taskDb) |
| 250 | { |
| 251 | m_taskDb->deleteTask(deviceName, baseName); |
| 252 | } |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 253 | } |
Alexander Afanasyev | d6c2a90 | 2013-01-19 21:24:30 -0800 | [diff] [blame] | 254 | |
Zhenkai Zhu | 354d46d | 2013-02-06 13:49:48 -0800 | [diff] [blame] | 255 | // like TCP timed-wait |
| 256 | m_scheduler->scheduleOneTimeTask(m_scheduler, 10, boost::bind(&FetchManager::TimedWait, this, ref(fetcher)), boost::lexical_cast<string>(baseName)); |
| 257 | |
Alexander Afanasyev | f975623 | 2013-01-28 16:42:20 -0800 | [diff] [blame] | 258 | m_scheduler->rescheduleTaskAt (m_scheduleFetchesTask, 0); |
Alexander Afanasyev | e41e7d2 | 2013-01-19 15:13:47 -0800 | [diff] [blame] | 259 | } |
Zhenkai Zhu | 354d46d | 2013-02-06 13:49:48 -0800 | [diff] [blame] | 260 | |
| 261 | void |
| 262 | FetchManager::TimedWait (Fetcher &fetcher) |
| 263 | { |
| 264 | unique_lock<mutex> lock (m_parellelFetchMutex); |
| 265 | _LOG_TRACE ("+++++ removing fetcher: " << fetcher.GetName ()); |
| 266 | m_fetchList.erase_and_dispose (FetchList::s_iterator_to (fetcher), fetcher_disposer ()); |
| 267 | } |