Page Speed Optimization Libraries  1.8.31.2
net/instaweb/system/public/system_server_context.h
Go to the documentation of this file.
00001 // Copyright 2013 Google Inc.
00016 
00017 #ifndef NET_INSTAWEB_SYSTEM_PUBLIC_SYSTEM_SERVER_CONTEXT_H_
00018 #define NET_INSTAWEB_SYSTEM_PUBLIC_SYSTEM_SERVER_CONTEXT_H_
00019 
00020 #include "net/instaweb/rewriter/public/server_context.h"
00021 
00022 #include "net/instaweb/http/public/request_context.h"
00023 #include "net/instaweb/util/public/basictypes.h"
00024 #include "net/instaweb/util/public/scoped_ptr.h"
00025 #include "pagespeed/kernel/base/string_util.h"
00026 #include "pagespeed/kernel/base/string.h"
00027 
00028 namespace net_instaweb {
00029 
00030 class AbstractMutex;
00031 class AsyncFetch;
00032 class GoogleUrl;
00033 class Histogram;
00034 class QueryParams;
00035 class RewriteDriver;
00036 class RewriteDriverFactory;
00037 class RewriteOptions;
00038 class RewriteStats;
00039 class SharedMemStatistics;
00040 class Statistics;
00041 class SystemCaches;
00042 class SystemRewriteDriverFactory;
00043 class SystemRewriteOptions;
00044 class UrlAsyncFetcherStats;
00045 class Variable;
00046 class Writer;
00047 
00049 class SystemServerContext : public ServerContext {
00050  public:
00057   enum AdminSource { kPageSpeedAdmin, kStatistics, kOther };
00058 
00059   SystemServerContext(RewriteDriverFactory* factory,
00060                       StringPiece hostname, int port);
00061   virtual ~SystemServerContext();
00062 
00071   void FlushCacheIfNecessary();
00072 
00073   SystemRewriteOptions* global_system_rewrite_options();
00074   GoogleString hostname_identifier() { return hostname_identifier_; }
00075 
00076   static void InitStats(Statistics* statistics);
00077 
00079   virtual void ChildInit(SystemRewriteDriverFactory* factory);
00080 
00084   void CreateLocalStatistics(Statistics* global_statistics,
00085                              SystemRewriteDriverFactory* factory);
00086 
00089   bool initialized() const { return initialized_; }
00090 
00102   virtual void ApplySessionFetchers(const RequestContextPtr& req,
00103                                     RewriteDriver* driver);
00104 
00107   void AddHtmlRewriteTimeUs(int64 rewrite_time_us);
00108 
00113   virtual void CollapseConfigOverlaysAndComputeSignatures();
00114 
00117   virtual const SystemRewriteOptions* SpdyGlobalConfig() const;
00118 
00121   void ConsoleHandler(const SystemRewriteOptions& options, AdminSource source,
00122                       const QueryParams& query_params, AsyncFetch* fetch);
00123 
00125   void MessageHistoryHandler(AdminSource source, AsyncFetch* fetch);
00126 
00128   void StatisticsGraphsHandler(Writer* writer);
00129 
00133   void AdminPage(bool is_global, const GoogleUrl& stripped_gurl,
00134                  const QueryParams& query_params, const RewriteOptions* options,
00135                  AsyncFetch* fetch);
00136 
00142   void StatisticsPage(bool is_global, const QueryParams& query_params,
00143                       const RewriteOptions* options,
00144                       AsyncFetch* fetch);
00145 
00146  protected:
00159   virtual bool UpdateCacheFlushTimestampMs(int64 timestamp_ms);
00160 
00162   virtual void MaybeApplySpdySessionFetcher(const RequestContextPtr& request,
00163                                             RewriteDriver* driver) {}
00164 
00166   void ConsoleJsonHandler(const QueryParams& params, AsyncFetch* fetch);
00167 
00179   void StatisticsHandler(bool is_global_request, AdminSource source,
00180                          AsyncFetch* fetch);
00181 
00183   void PrintSpdyConfig(AdminSource source, AsyncFetch* fetch);
00184 
00186   void PrintNormalConfig(AdminSource source, AsyncFetch* fetch);
00187 
00190   void PrintCaches(bool is_global, AdminSource source,
00191                    const QueryParams& query_params,
00192                    const RewriteOptions* options,
00193                    AsyncFetch* fetch);
00194 
00196   void PrintHistograms(bool is_global_request, AdminSource source,
00197                        AsyncFetch* fetch);
00198 
00199   Variable* statistics_404_count();
00200 
00201  private:
00202   bool initialized_;
00203   bool use_per_vhost_statistics_;
00204 
00208   scoped_ptr<AbstractMutex> cache_flush_mutex_;
00209   int64 last_cache_flush_check_sec_; 
00210 
00211   Variable* cache_flush_count_;
00212   Variable* cache_flush_timestamp_ms_;
00213 
00214   Histogram* html_rewrite_time_us_histogram_;
00215 
00217   scoped_ptr<Statistics> split_statistics_;
00218 
00220   SharedMemStatistics* local_statistics_;
00221 
00223   scoped_ptr<RewriteStats> local_rewrite_stats_;
00224   scoped_ptr<UrlAsyncFetcherStats> stats_fetcher_;
00225 
00229   GoogleString hostname_identifier_;
00230 
00231   SystemCaches* system_caches_;
00232 
00233   DISALLOW_COPY_AND_ASSIGN(SystemServerContext);
00234 };
00235 
00236 }  
00237 
00238 #endif  ///< NET_INSTAWEB_SYSTEM_PUBLIC_SYSTEM_SERVER_CONTEXT_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines