1 /*
2   Licensed to the Apache Software Foundation (ASF) under one
3   or more contributor license agreements.  See the NOTICE file
4   distributed with this work for additional information
5   regarding copyright ownership.  The ASF licenses this file
6   to you under the Apache License, Version 2.0 (the
7   "License"); you may not use this file except in compliance
8   with the License.  You may obtain a copy of the License at
9 
10   http://www.apache.org/licenses/LICENSE-2.0
11 
12   Unless required by applicable law or agreed to in writing, software
13   distributed under the License is distributed on an "AS IS" BASIS,
14   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   See the License for the specific language governing permissions and
16   limitations under the License.
17 */
18 
19 /**
20  * @file  fetch_policy_simple.cc
21  * @brief Simple fetch policy.
22  */
23 
24 #include "fetch_policy_simple.h"
25 
26 bool
init(const char * parameters)27 FetchPolicySimple::init(const char *parameters)
28 {
29   PrefetchDebug("initialized %s fetch policy", name());
30   return true;
31 }
32 
33 bool
acquire(const std::string & url)34 FetchPolicySimple::acquire(const std::string &url)
35 {
36   bool ret;
37   if (_urls.end() == _urls.find(url)) {
38     _urls[url] = true;
39     ret        = true;
40   } else {
41     ret = false;
42   }
43 
44   log("acquire", url, ret);
45   return ret;
46 }
47 
48 bool
release(const std::string & url)49 FetchPolicySimple::release(const std::string &url)
50 {
51   bool ret;
52   if (_urls.end() == _urls.find(url)) {
53     ret = false;
54   } else {
55     _urls.erase(url);
56     ret = true;
57   }
58 
59   log("release", url, ret);
60   return ret;
61 }
62 
63 inline const char *
name()64 FetchPolicySimple::name()
65 {
66   return "simple";
67 }
68 
69 inline size_t
getSize()70 FetchPolicySimple::getSize()
71 {
72   return _urls.size();
73 }
74 
75 inline size_t
getMaxSize()76 FetchPolicySimple::getMaxSize()
77 {
78   /* Unlimited */
79   return 0;
80 }
81