Page Speed Optimization Libraries  1.4.26.1
net/instaweb/apache/apache_rewrite_driver_factory.h
Go to the documentation of this file.
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 
00024 #include "net/instaweb/rewriter/public/rewrite_driver_factory.h"
00025 #include "net/instaweb/system/public/system_rewrite_driver_factory.h"
00026 #include "net/instaweb/util/public/basictypes.h"
00027 #include "net/instaweb/util/public/cache_interface.h"
00028 #include "net/instaweb/util/public/scoped_ptr.h"
00029 #include "net/instaweb/util/public/shared_mem_cache.h"
00030 #include "net/instaweb/util/public/string.h"
00031 #include "net/instaweb/util/public/string_util.h"
00032 
00033 struct apr_pool_t;
00034 struct server_rec;
00035 
00036 namespace net_instaweb {
00037 
00038 class AbstractSharedMem;
00039 class ApacheConfig;
00040 class ApacheMessageHandler;
00041 class ApacheServerContext;
00042 class FileSystem;
00043 class Hasher;
00044 class MessageHandler;
00045 class ModSpdyFetchController;
00046 class NamedLockManager;
00047 class QueuedWorkerPool;
00048 class RewriteOptions;
00049 class SerfUrlAsyncFetcher;
00050 class ServerContext;
00051 class SharedCircularBuffer;
00052 class SharedMemStatistics;
00053 class SlowWorker;
00054 class StaticAssetManager;
00055 class Statistics;
00056 class SystemCaches;
00057 class Timer;
00058 class UrlAsyncFetcher;
00059 class UrlFetcher;
00060 class UrlPollableAsyncFetcher;
00061 class Writer;
00062 
00064 class ApacheRewriteDriverFactory : public SystemRewriteDriverFactory {
00065  public:
00068   static const char kStaticAssetPrefix[];
00069 
00070   ApacheRewriteDriverFactory(server_rec* server, const StringPiece& version);
00071   virtual ~ApacheRewriteDriverFactory();
00072 
00073   virtual Hasher* NewHasher();
00074 
00080   UrlPollableAsyncFetcher* SubResourceFetcher();
00081 
00082   GoogleString hostname_identifier() { return hostname_identifier_; }
00083 
00084   AbstractSharedMem* shared_mem_runtime() const {
00085     return shared_mem_runtime_.get();
00086   }
00091   ApacheMessageHandler* apache_message_handler() {
00092     return apache_message_handler_;
00093   }
00115   bool is_root_process() const { return is_root_process_; }
00116   void RootInit();
00117   void ChildInit();
00118 
00121   Statistics* MakeGlobalSharedMemStatistics(bool logging,
00122                                             int64 logging_interval_ms,
00123                                             const GoogleString& logging_file);
00124 
00126   SharedMemStatistics* AllocateAndInitSharedMemStatistics(
00127       const StringPiece& name, const bool logging,
00128       const int64 logging_interval_ms, const GoogleString& logging_file);
00129 
00130   virtual ApacheServerContext* MakeApacheServerContext(server_rec* server);
00131   ServerContext* NewServerContext();
00132 
00133 
00137   void set_fetch_with_gzip(bool x) { fetch_with_gzip_ = x; }
00138   bool fetch_with_gzip() const { return fetch_with_gzip_; }
00139 
00142   void set_track_original_content_length(bool x) {
00143     track_original_content_length_ = x;
00144   }
00145   bool track_original_content_length() const {
00146     return track_original_content_length_;
00147   }
00148 
00149   void set_num_rewrite_threads(int x) { num_rewrite_threads_ = x; }
00150   int num_rewrite_threads() const { return num_rewrite_threads_; }
00151   void set_num_expensive_rewrite_threads(int x) {
00152     num_expensive_rewrite_threads_ = x;
00153   }
00154   int num_expensive_rewrite_threads() const {
00155     return num_expensive_rewrite_threads_;
00156   }
00157 
00158   void set_message_buffer_size(int x) {
00159     message_buffer_size_ = x;
00160   }
00161 
00166   void list_outstanding_urls_on_error(bool x) {
00167     list_outstanding_urls_on_error_ = x;
00168   }
00169 
00170   bool use_per_vhost_statistics() const {
00171     return use_per_vhost_statistics_;
00172   }
00173 
00174   void set_use_per_vhost_statistics(bool x) {
00175     use_per_vhost_statistics_ = x;
00176   }
00177 
00178   bool enable_property_cache() const {
00179     return enable_property_cache_;
00180   }
00181 
00182   void set_enable_property_cache(bool x) {
00183     enable_property_cache_ = x;
00184   }
00185 
00187   bool inherit_vhost_config() const {
00188     return inherit_vhost_config_;
00189   }
00190 
00191   void set_inherit_vhost_config(bool x) {
00192     inherit_vhost_config_ = x;
00193   }
00194 
00195   bool disable_loopback_routing() const {
00196     return disable_loopback_routing_;
00197   }
00198 
00199   void set_disable_loopback_routing(bool x) {
00200     disable_loopback_routing_ = x;
00201   }
00202 
00203   bool install_crash_handler() const {
00204     return install_crash_handler_;
00205   }
00206 
00207   void set_install_crash_handler(bool x) {
00208     install_crash_handler_ = x;
00209   }
00210 
00211   SystemCaches* caches() { return caches_.get(); }
00212 
00215   virtual bool UseBeaconResultsInFilters() const {
00216     return true;
00217   }
00218 
00222   UrlAsyncFetcher* GetFetcher(ApacheConfig* config);
00223 
00226   SerfUrlAsyncFetcher* GetSerfFetcher(ApacheConfig* config);
00227 
00231   bool PoolDestroyed(ApacheServerContext* rm);
00232 
00235   virtual RewriteOptions* NewRewriteOptions();
00236 
00239   virtual RewriteOptions* NewRewriteOptionsForQuery();
00240 
00244   static void InitStats(Statistics* statistics);
00245   static void Initialize();
00246   static void Terminate();
00247 
00255   bool SetHttpsOptions(StringPiece directive, GoogleString* error_message);
00256 
00257   ModSpdyFetchController* mod_spdy_fetch_controller() {
00258     return mod_spdy_fetch_controller_.get();
00259   }
00260 
00261  protected:
00262   virtual UrlFetcher* DefaultUrlFetcher();
00263   virtual UrlAsyncFetcher* DefaultAsyncUrlFetcher();
00264   virtual void StopCacheActivity();
00265 
00267   virtual MessageHandler* DefaultHtmlParseMessageHandler();
00268   virtual MessageHandler* DefaultMessageHandler();
00269   virtual FileSystem* DefaultFileSystem();
00270   virtual Timer* DefaultTimer();
00271   virtual void SetupCaches(ServerContext* resource_manager);
00272   virtual NamedLockManager* DefaultLockManager();
00273   virtual QueuedWorkerPool* CreateWorkerPool(WorkerPoolCategory pool,
00274                                              StringPiece name);
00275 
00278   virtual bool ShouldWriteResourcesToFileSystem() { return false; }
00279 
00282   void ParentOrChildInit();
00286   void SharedCircularBufferInit(bool is_root);
00287 
00290   virtual void ShutDown();
00291 
00293   virtual void InitStaticAssetManager(StaticAssetManager* static_asset_manager);
00294 
00295  private:
00296   typedef SharedMemCache<64> MetadataShmCache;
00297   struct MetadataShmCacheInfo {
00298     MetadataShmCacheInfo() : cache_backend(NULL) {}
00299 
00301     scoped_ptr<CacheInterface> cache_to_use; 
00302     MetadataShmCache* cache_backend;
00303   };
00304 
00307   void AutoDetectThreadCounts();
00308 
00309   apr_pool_t* pool_;
00310   server_rec* server_rec_;
00311   scoped_ptr<SharedMemStatistics> shared_mem_statistics_;
00312   scoped_ptr<AbstractSharedMem> shared_mem_runtime_;
00313   scoped_ptr<SharedCircularBuffer> shared_circular_buffer_;
00314   scoped_ptr<SlowWorker> slow_worker_;
00315 
00320   GoogleString version_;
00321 
00322   bool statistics_frozen_;
00323   bool is_root_process_;
00324   bool fetch_with_gzip_;
00325   bool track_original_content_length_;
00326   bool list_outstanding_urls_on_error_;
00327 
00331   const GoogleString hostname_identifier_;
00337   ApacheMessageHandler* apache_message_handler_;
00342   ApacheMessageHandler* apache_html_parse_message_handler_;
00343 
00351   typedef std::set<ApacheServerContext*> ApacheServerContextSet;
00352   ApacheServerContextSet uninitialized_managers_;
00353 
00357   bool use_per_vhost_statistics_;
00358 
00360   bool enable_property_cache_;
00361 
00363   bool inherit_vhost_config_;
00364 
00367   bool disable_loopback_routing_;
00368 
00370   bool install_crash_handler_;
00371 
00373   bool thread_counts_finalized_;
00374 
00376   int num_rewrite_threads_;
00377   int num_expensive_rewrite_threads_;
00378 
00379   int max_mod_spdy_fetch_threads_;
00380 
00383   int message_buffer_size_;
00384 
00388   typedef std::map<GoogleString, UrlAsyncFetcher*> FetcherMap;
00389   FetcherMap fetcher_map_;
00390   typedef std::map<GoogleString, SerfUrlAsyncFetcher*> SerfFetcherMap;
00391   SerfFetcherMap serf_fetcher_map_;
00392 
00394   scoped_ptr<ModSpdyFetchController> mod_spdy_fetch_controller_;
00395 
00396   GoogleString https_options_;
00397 
00399   scoped_ptr<SystemCaches> caches_;
00400 
00401   DISALLOW_COPY_AND_ASSIGN(ApacheRewriteDriverFactory);
00402 };
00403 
00404 }  
00405 
00406 #endif  ///< NET_INSTAWEB_APACHE_APACHE_REWRITE_DRIVER_FACTORY_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines