Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
simulated_delay_fetcher.h
Go to the documentation of this file.
1 /*
2  * Copyright 2014 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_SIMULATED_DELAY_FETCHER_H_
20 #define NET_INSTAWEB_HTTP_PUBLIC_SIMULATED_DELAY_FETCHER_H_
21 
22 #include <map>
23 
30 #include "pagespeed/kernel/base/thread_annotations.h"
31 
32 namespace net_instaweb {
33 
34 class AbstractMutex;
35 class AsyncFetch;
36 class MessageHandler;
37 class Scheduler;
38 class ThreadSystem;
39 class Timer;
40 
45  public:
47  static const char kPayload[];
48 
55  SimulatedDelayFetcher(ThreadSystem* thread_system,
56  Timer* timer,
57  Scheduler* scheduler,
58  MessageHandler* handler,
59  FileSystem* file_system,
60  StringPiece delay_map_path,
61  StringPiece request_log_path,
62  int request_log_flush_frequency);
63 
64  virtual ~SimulatedDelayFetcher();
65 
66  virtual void Fetch(const GoogleString& url,
67  MessageHandler* message_handler,
68  AsyncFetch* fetch);
69 
70  private:
71  typedef std::map<GoogleString, int> DelayMap;
72  void ProduceReply(AsyncFetch* fetch);
73  void ParseDelayMap(StringPiece delay_map_path);
74 
75  Timer* timer_;
76  Scheduler* scheduler_;
77  MessageHandler* message_handler_;
78  FileSystem* file_system_;
79  DelayMap delays_ms_;
80  int request_log_flush_frequency_;
81 
83  int request_log_outstanding_ GUARDED_BY(mutex_.get());
84  FileSystem::OutputFile* request_log_ PT_GUARDED_BY(mutex_.get());
85 
86 
87 };
88 
89 }
90 
91 #endif
SimulatedDelayFetcher(ThreadSystem *thread_system, Timer *timer, Scheduler *scheduler, MessageHandler *handler, FileSystem *file_system, StringPiece delay_map_path, StringPiece request_log_path, int request_log_flush_frequency)
Definition: scoped_ptr.h:30
Definition: simulated_delay_fetcher.h:44
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
Definition: async_fetch.h:53
Definition: file_system.h:76
virtual void Fetch(const GoogleString &url, MessageHandler *message_handler, AsyncFetch *fetch)
Definition: thread_system.h:40
Definition: message_handler.h:39
Definition: scheduler.h:47
Timer interface, made virtual so it can be mocked for tests.
Definition: timer.h:27
Definition: url_async_fetcher.h:33
static const char kPayload[]
The payload that this will deliver.
Definition: simulated_delay_fetcher.h:47
Definition: file_system.h:113