2
* Copyright 2012 Google Inc.
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
17
// Author: morlovich@google.com (Maksim Orlovich)
19
// ModSpdyFetchController coordinates a threadpool and a rate controller between
20
// multiple ModSpdyFetcher objects. The basic usage pattern is that
21
// ModSpdyFetcher::Fetch calls ModSpdyFetchController::ScheduleBlockingFetch,
22
// which will then cause ModSpdyFetcher::BlockingFetch to be called on a
23
// thread in a hopefully intelligent manner.
25
#ifndef NET_INSTAWEB_APACHE_MOD_SPDY_FETCH_CONTROLLER_H_
26
#define NET_INSTAWEB_APACHE_MOD_SPDY_FETCH_CONTROLLER_H_
28
#include "net/instaweb/http/public/rate_controller.h"
29
#include "net/instaweb/util/public/atomic_bool.h"
30
#include "net/instaweb/util/public/basictypes.h"
31
#include "net/instaweb/util/public/queued_worker_pool.h"
32
#include "net/instaweb/util/public/string.h"
34
namespace net_instaweb {
43
class ModSpdyFetchController {
45
// Note: RateController::InitStats must have been called before using this.
46
ModSpdyFetchController(int num_threads,
47
ThreadSystem* thread_system,
49
Statistics* statistics);
50
~ModSpdyFetchController();
52
// This must be called for every statistics object in use before using this.
53
static void InitStats(Statistics* statistics);
55
// Arranges for fetcher->BlockingFetch to be called on our thread pool.
56
void ScheduleBlockingFetch(
57
ModSpdyFetcher* fetcher, const GoogleString& url, Statistics* stats,
58
MessageHandler* message_handler, AsyncFetch* fetch);
60
// Makes any further fetches quick-fail, and makes us more careful about
61
// using external dependencies on things like stats.
62
void ShutDown() { shutdown_.set_value(true); }
63
bool is_shut_down() const { return shutdown_.value(); }
65
Timer* timer() const { return timer_; }
68
class FetchDispatcher;
71
RateController rate_controller_;
72
QueuedWorkerPool thread_pool_;
74
DISALLOW_COPY_AND_ASSIGN(ModSpdyFetchController);
77
} // namespace net_instaweb
79
#endif // NET_INSTAWEB_APACHE_MOD_SPDY_FETCH_CONTROLLER_H_