Page Speed Optimization Libraries
1.2.24.1
|
00001 // Copyright 2010 Google Inc. 00017 00018 #ifndef NET_INSTAWEB_APACHE_APACHE_REWRITE_DRIVER_FACTORY_H_ 00019 #define NET_INSTAWEB_APACHE_APACHE_REWRITE_DRIVER_FACTORY_H_ 00020 00021 #include <map> 00022 #include <set> 00023 #include <vector> 00024 00025 #include "net/instaweb/rewriter/public/rewrite_driver_factory.h" 00026 #include "net/instaweb/util/public/basictypes.h" 00027 #include "net/instaweb/util/public/md5_hasher.h" 00028 #include "net/instaweb/util/public/scoped_ptr.h" 00029 #include "net/instaweb/util/public/string.h" 00030 #include "net/instaweb/util/public/string_util.h" 00031 00032 struct apr_pool_t; 00033 struct request_rec; 00034 struct server_rec; 00035 00036 namespace net_instaweb { 00037 00038 class AbstractSharedMem; 00039 class ApacheCache; 00040 class ApacheConfig; 00041 class ApacheMessageHandler; 00042 class ApacheServerContext; 00043 class AprMemCache; 00044 class AsyncCache; 00045 class CacheInterface; 00046 class FileSystem; 00047 class Hasher; 00048 class MessageHandler; 00049 class ModSpdyFetchController; 00050 class NamedLockManager; 00051 class QueuedWorkerPool; 00052 class RewriteDriver; 00053 class RewriteOptions; 00054 class SerfUrlAsyncFetcher; 00055 class ServerContext; 00056 class SharedCircularBuffer; 00057 class SharedMemRefererStatistics; 00058 class SharedMemStatistics; 00059 class SlowWorker; 00060 class StaticJavascriptManager; 00061 class Statistics; 00062 class Timer; 00063 class UrlAsyncFetcher; 00064 class UrlFetcher; 00065 class UrlPollableAsyncFetcher; 00066 class Writer; 00067 00069 class ApacheRewriteDriverFactory : public RewriteDriverFactory { 00070 public: 00071 static const char kMemcached[]; 00072 static const char kStaticJavaScriptPrefix[]; 00073 00074 ApacheRewriteDriverFactory(server_rec* server, const StringPiece& version); 00075 virtual ~ApacheRewriteDriverFactory(); 00076 00077 virtual Hasher* NewHasher(); 00078 00084 UrlPollableAsyncFetcher* SubResourceFetcher(); 00085 00086 GoogleString hostname_identifier() { return hostname_identifier_; } 00087 00088 AbstractSharedMem* shared_mem_runtime() const { 00089 return shared_mem_runtime_.get(); 00090 } 00091 SharedMemRefererStatistics* shared_mem_referer_statistics() const { 00092 return shared_mem_referer_statistics_.get(); 00093 } 00098 ApacheMessageHandler* apache_message_handler() { 00099 return apache_message_handler_; 00100 } 00122 bool is_root_process() const { return is_root_process_; } 00123 void RootInit(); 00124 void ChildInit(); 00125 00126 void DumpRefererStatistics(Writer* writer); 00127 00128 SlowWorker* slow_worker() { return slow_worker_.get(); } 00129 00132 Statistics* MakeGlobalSharedMemStatistics(bool logging, 00133 int64 logging_interval_ms, 00134 const GoogleString& logging_file); 00135 00137 SharedMemStatistics* AllocateAndInitSharedMemStatistics( 00138 const StringPiece& name, const bool logging, 00139 const int64 logging_interval_ms, const GoogleString& logging_file); 00140 00141 ApacheServerContext* MakeApacheServerContext(server_rec* server); 00142 00146 void set_fetch_with_gzip(bool x) { fetch_with_gzip_ = x; } 00147 bool fetch_with_gzip() const { return fetch_with_gzip_; } 00148 00151 void set_track_original_content_length(bool x) { 00152 track_original_content_length_ = x; 00153 } 00154 bool track_original_content_length() const { 00155 return track_original_content_length_; 00156 } 00157 00158 void set_num_rewrite_threads(int x) { num_rewrite_threads_ = x; } 00159 int num_rewrite_threads() const { return num_rewrite_threads_; } 00160 void set_num_expensive_rewrite_threads(int x) { 00161 num_expensive_rewrite_threads_ = x; 00162 } 00163 int num_expensive_rewrite_threads() const { 00164 return num_expensive_rewrite_threads_; 00165 } 00166 00167 void set_message_buffer_size(int x) { 00168 message_buffer_size_ = x; 00169 } 00170 00175 void list_outstanding_urls_on_error(bool x) { 00176 list_outstanding_urls_on_error_ = x; 00177 } 00178 00179 bool use_per_vhost_statistics() const { 00180 return use_per_vhost_statistics_; 00181 } 00182 00183 void set_use_per_vhost_statistics(bool x) { 00184 use_per_vhost_statistics_ = x; 00185 } 00186 00187 bool enable_property_cache() const { 00188 return enable_property_cache_; 00189 } 00190 00191 void set_enable_property_cache(bool x) { 00192 enable_property_cache_ = x; 00193 } 00194 00196 bool inherit_vhost_config() const { 00197 return inherit_vhost_config_; 00198 } 00199 00200 void set_inherit_vhost_config(bool x) { 00201 inherit_vhost_config_ = x; 00202 } 00203 00204 bool disable_loopback_routing() const { 00205 return disable_loopback_routing_; 00206 } 00207 00208 void set_disable_loopback_routing(bool x) { 00209 disable_loopback_routing_ = x; 00210 } 00211 00212 bool install_crash_handler() const { 00213 return install_crash_handler_; 00214 } 00215 00216 void set_install_crash_handler(bool x) { 00217 install_crash_handler_ = x; 00218 } 00219 00224 ApacheCache* GetCache(ApacheConfig* config); 00225 00227 AprMemCache* NewAprMemCache(const GoogleString& spec); 00228 00236 CacheInterface* GetMemcached(ApacheConfig* config, CacheInterface* l2_cache); 00237 00240 CacheInterface* GetFilesystemMetadataCache(ApacheConfig* config); 00241 00244 void StopAsyncGets(); 00245 00249 UrlAsyncFetcher* GetFetcher(ApacheConfig* config); 00250 00253 SerfUrlAsyncFetcher* GetSerfFetcher(ApacheConfig* config); 00254 00258 bool PoolDestroyed(ApacheServerContext* rm); 00259 00262 virtual RewriteOptions* NewRewriteOptions(); 00263 00266 virtual RewriteOptions* NewRewriteOptionsForQuery(); 00267 00271 static void InitStats(Statistics* statistics); 00272 static void Initialize(); 00273 static void Terminate(); 00274 00276 void PrintMemCacheStats(GoogleString* out); 00277 00283 void ApplySessionFetchers(ApacheServerContext* manager, 00284 RewriteDriver* driver, request_rec* req); 00285 00290 static bool TreatRequestAsSpdy(request_rec* req); 00291 00292 protected: 00293 virtual UrlFetcher* DefaultUrlFetcher(); 00294 virtual UrlAsyncFetcher* DefaultAsyncUrlFetcher(); 00295 virtual void StopCacheActivity(); 00296 00298 virtual MessageHandler* DefaultHtmlParseMessageHandler(); 00299 virtual MessageHandler* DefaultMessageHandler(); 00300 virtual FileSystem* DefaultFileSystem(); 00301 virtual Timer* DefaultTimer(); 00302 virtual void SetupCaches(ServerContext* resource_manager); 00303 virtual NamedLockManager* DefaultLockManager(); 00304 virtual QueuedWorkerPool* CreateWorkerPool(WorkerPoolName name); 00305 00308 virtual bool ShouldWriteResourcesToFileSystem() { return false; } 00309 00312 void ParentOrChildInit(); 00316 void SharedCircularBufferInit(bool is_root); 00319 void SharedMemRefererStatisticsInit(bool is_root); 00320 00323 virtual void ShutDown(); 00324 00326 virtual void InitStaticJavascriptManager( 00327 StaticJavascriptManager* static_js_manager); 00328 00329 private: 00332 void AutoDetectThreadCounts(); 00333 00334 apr_pool_t* pool_; 00335 server_rec* server_rec_; 00336 scoped_ptr<SharedMemStatistics> shared_mem_statistics_; 00337 scoped_ptr<AbstractSharedMem> shared_mem_runtime_; 00338 scoped_ptr<SharedCircularBuffer> shared_circular_buffer_; 00339 scoped_ptr<SlowWorker> slow_worker_; 00340 00345 GoogleString version_; 00346 00347 bool statistics_frozen_; 00348 bool is_root_process_; 00349 bool fetch_with_gzip_; 00350 bool track_original_content_length_; 00351 bool list_outstanding_urls_on_error_; 00352 00353 scoped_ptr<SharedMemRefererStatistics> shared_mem_referer_statistics_; 00354 00358 const GoogleString hostname_identifier_; 00364 ApacheMessageHandler* apache_message_handler_; 00369 ApacheMessageHandler* apache_html_parse_message_handler_; 00370 00378 typedef std::set<ApacheServerContext*> ApacheServerContextSet; 00379 ApacheServerContextSet uninitialized_managers_; 00380 00384 bool use_per_vhost_statistics_; 00385 00387 bool enable_property_cache_; 00388 00390 bool inherit_vhost_config_; 00391 00394 bool disable_loopback_routing_; 00395 00397 bool install_crash_handler_; 00398 00400 bool thread_counts_finalized_; 00401 00403 int num_rewrite_threads_; 00404 int num_expensive_rewrite_threads_; 00405 00406 int max_mod_spdy_fetch_threads_; 00407 00410 int message_buffer_size_; 00411 00421 typedef std::map<GoogleString, ApacheCache*> PathCacheMap; 00422 PathCacheMap path_cache_map_; 00423 00439 typedef std::map<GoogleString, CacheInterface*> MemcachedMap; 00440 MemcachedMap memcached_map_; 00441 scoped_ptr<QueuedWorkerPool> memcached_pool_; 00442 std::vector<AprMemCache*> memcache_servers_; 00443 std::vector<AsyncCache*> async_caches_; 00444 00448 typedef std::map<GoogleString, UrlAsyncFetcher*> FetcherMap; 00449 FetcherMap fetcher_map_; 00450 typedef std::map<GoogleString, SerfUrlAsyncFetcher*> SerfFetcherMap; 00451 SerfFetcherMap serf_fetcher_map_; 00452 MD5Hasher cache_hasher_; 00453 00455 scoped_ptr<ModSpdyFetchController> mod_spdy_fetch_controller_; 00456 00457 DISALLOW_COPY_AND_ASSIGN(ApacheRewriteDriverFactory); 00458 }; 00459 00460 } 00461 00462 #endif ///< NET_INSTAWEB_APACHE_APACHE_REWRITE_DRIVER_FACTORY_H_