Page Speed Optimization Libraries  1.9.32.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
rate_controller.h
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #ifndef NET_INSTAWEB_HTTP_PUBLIC_RATE_CONTROLLER_H_
20 #define NET_INSTAWEB_HTTP_PUBLIC_RATE_CONTROLLER_H_
21 
22 #include <map>
23 
26 #include "net/instaweb/util/public/ref_counted_ptr.h"
29 
30 namespace net_instaweb {
31 
32 class AbstractMutex;
33 class AsyncFetch;
34 class MessageHandler;
35 class Statistics;
36 class ThreadSystem;
37 class TimedVariable;
38 class UpDownCounter;
39 class UrlAsyncFetcher;
40 
54  public:
55  static const char kQueuedFetchCount[];
56  static const char kDroppedFetchCount[];
57  static const char kCurrentGlobalFetchQueueSize[];
58 
59  RateController(int max_global_queue_size,
60  int per_host_outgoing_request_threshold,
61  int per_host_queued_request_threshold,
62  ThreadSystem* thread_system,
63  Statistics* statistics);
64 
65  virtual ~RateController();
66 
68  void ShutDown() { shutdown_.set_value(true); }
69  bool is_shut_down() const { return shutdown_.value(); }
70 
73  void Fetch(UrlAsyncFetcher* fetcher,
74  const GoogleString& url,
75  MessageHandler* message_handler,
76  AsyncFetch* fetch);
77 
79  static void InitStats(Statistics* statistics);
80 
81  private:
82  class HostFetchInfo;
83  class CustomFetch;
84  friend class CustomFetch;
85 
86  typedef RefCountedPtr<HostFetchInfo> HostFetchInfoPtr;
87 
88  typedef std::map<GoogleString, HostFetchInfoPtr*> HostFetchInfoMap;
89 
91  void DeleteFetchInfoIfPossible(const HostFetchInfoPtr& fetch_info);
92 
94  const int max_global_queue_size_;
96  const int per_host_outgoing_request_threshold_;
98  const int per_host_queued_request_threshold_;
99  ThreadSystem* thread_system_;
100 
102  HostFetchInfoMap fetch_info_map_;
103  scoped_ptr<AbstractMutex> mutex_;
104 
105  TimedVariable* queued_fetch_count_;
106  TimedVariable* dropped_fetch_count_;
109  UpDownCounter* current_global_fetch_queue_size_;
110 
111  AtomicBool shutdown_;
112 
113  DISALLOW_COPY_AND_ASSIGN(RateController);
114 };
115 
116 }
117 
118 #endif
void ShutDown()
Makes any further fetches quick-fail.
Definition: rate_controller.h:68
Definition: rate_controller.h:53
static void InitStats(Statistics *statistics)
Initializes statistics variables associated with this class.
void Fetch(UrlAsyncFetcher *fetcher, const GoogleString &url, MessageHandler *message_handler, AsyncFetch *fetch)