~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/net/instaweb/http/public/simulated_delay_fetcher.h

  • Committer: Vivian
  • Date: 2015-12-04 18:20:11 UTC
  • Revision ID: git-v1:a36f2bc32e884f7473b3a47040e5411306144d7d
* Do not extract psol.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
17
 
// Author: morlovich@google.com (Maksim Orlovich)
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
 
 
24
 
#include "net/instaweb/http/public/url_async_fetcher.h"
25
 
#include "net/instaweb/util/public/basictypes.h"
26
 
#include "net/instaweb/util/public/string.h"
27
 
#include "net/instaweb/util/public/string_util.h"
28
 
#include "pagespeed/kernel/base/file_system.h"
29
 
#include "pagespeed/kernel/base/scoped_ptr.h"
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
 
 
41
 
// SimulatedDelayFetcher lets one configure various per-host delays, and will
42
 
// make hardcoded replies according to those replies. This exists to help run
43
 
// simulations of server behavior with sites of widely various speeds.
44
 
class SimulatedDelayFetcher : public UrlAsyncFetcher {
45
 
 public:
46
 
  // The payload that this will deliver.
47
 
  static const char kPayload[];
48
 
 
49
 
  // delay_map_path is the path to the file describing the delays for each host
50
 
  // The format is: foo.com=4;bar.com=42;baz.com=43; (line breaks are permitted)
51
 
  // The delays are in milliseconds.
52
 
  //
53
 
  // request_log_path will be used to log when each request was received.
54
 
  // (Not when it was served).
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
 
 
82
 
  scoped_ptr<AbstractMutex> mutex_;
83
 
  int request_log_outstanding_ GUARDED_BY(mutex_.get());
84
 
  FileSystem::OutputFile* request_log_ PT_GUARDED_BY(mutex_.get());
85
 
 
86
 
  DISALLOW_COPY_AND_ASSIGN(SimulatedDelayFetcher);
87
 
};
88
 
 
89
 
}  // namespace net_instaweb
90
 
 
91
 
#endif  // NET_INSTAWEB_HTTP_PUBLIC_SIMULATED_DELAY_FETCHER_H_