Page Speed Optimization Libraries  1.7.30.2
net/instaweb/system/public/system_rewrite_driver_factory.h
Go to the documentation of this file.
00001 // Copyright 2013 Google Inc.
00016 
00017 #ifndef NET_INSTAWEB_SYSTEM_PUBLIC_SYSTEM_REWRITE_DRIVER_FACTORY_H_
00018 #define NET_INSTAWEB_SYSTEM_PUBLIC_SYSTEM_REWRITE_DRIVER_FACTORY_H_
00019 
00020 #include <map>
00021 #include <set>
00022 #include <vector>
00023 
00024 #include "net/instaweb/rewriter/public/rewrite_driver_factory.h"
00025 
00026 #include "net/instaweb/util/public/basictypes.h"
00027 #include "pagespeed/kernel/base/scoped_ptr.h"
00028 #include "pagespeed/kernel/base/string.h"
00029 #include "pagespeed/kernel/base/string_util.h"
00030 
00031 namespace net_instaweb {
00032 
00033 class AbstractSharedMem;
00034 class FileSystem;
00035 class Hasher;
00036 class NamedLockManager;
00037 class NonceGenerator;
00038 class ServerContext;
00039 class SharedCircularBuffer;
00040 class SharedMemStatistics;
00041 class Statistics;
00042 class SystemCaches;
00043 class SystemRewriteOptions;
00044 class SystemServerContext;
00045 class SystemThreadSystem;
00046 class Timer;
00047 class UrlAsyncFetcher;
00048 
00050 class SystemRewriteDriverFactory : public RewriteDriverFactory {
00051  public:
00060   SystemRewriteDriverFactory(SystemThreadSystem* thread_system,
00061                              AbstractSharedMem* shared_mem_runtime,
00062                              StringPiece hostname, int port);
00063   virtual ~SystemRewriteDriverFactory();
00064 
00065   AbstractSharedMem* shared_mem_runtime() const {
00066     return shared_mem_runtime_.get();
00067   }
00068 
00070   SharedMemStatistics* AllocateAndInitSharedMemStatistics(
00071       bool local, const StringPiece& name, const SystemRewriteOptions& options);
00072 
00075   virtual void NonStaticInitStats(Statistics* statistics) = 0;
00076 
00078   NonceGenerator* DefaultNonceGenerator();
00079 
00103   bool is_root_process() const { return is_root_process_; }
00104   virtual void RootInit();
00105   virtual void ChildInit();
00106 
00109   virtual void ParentOrChildInit();
00110 
00118   void PostConfig(const std::vector<SystemServerContext*>& server_contexts,
00119                   GoogleString* error_message,
00120                   int* error_index,
00121                   Statistics** global_statistics);
00122 
00126   void SharedCircularBufferInit(bool is_root);
00127 
00128   virtual Hasher* NewHasher();
00129   virtual Timer* DefaultTimer();
00130   virtual ServerContext* NewServerContext();
00131 
00133   virtual bool enable_property_cache() const {
00134     return true;
00135   }
00136 
00137   GoogleString hostname_identifier() { return hostname_identifier_; }
00138 
00141   virtual void ShutDown();
00142 
00143   virtual void StopCacheActivity();
00144 
00145   SystemCaches* caches() { return caches_.get(); }
00146 
00147   virtual void set_message_buffer_size(int x) {
00148     message_buffer_size_ = x;
00149   }
00150 
00154   UrlAsyncFetcher* GetFetcher(SystemRewriteOptions* config);
00155 
00163   bool SetHttpsOptions(StringPiece directive, GoogleString* error_message);
00164 
00167   void set_track_original_content_length(bool x) {
00168     track_original_content_length_ = x;
00169   }
00170   bool track_original_content_length() const {
00171     return track_original_content_length_;
00172   }
00173 
00178   void list_outstanding_urls_on_error(bool x) {
00179     list_outstanding_urls_on_error_ = x;
00180   }
00181 
00185   virtual int requests_per_host() { return 4; }
00186   virtual int max_queue_size() { return 500 * requests_per_host(); }
00187   virtual int queued_per_host() { return 500 * requests_per_host(); }
00188 
00191   virtual bool use_per_vhost_statistics() const { return true; }
00192 
00193  protected:
00196   static void InitStats(Statistics* statistics);
00197 
00198   virtual void SetupCaches(ServerContext* server_context);
00199 
00201   virtual void SetupMessageHandlers() {}
00202   virtual void ShutDownMessageHandlers() {}
00203   virtual void SetCircularBuffer(SharedCircularBuffer* buffer) {}
00204 
00207   virtual void ShutDownFetchers() {}
00208 
00216   typedef std::set<SystemServerContext*> SystemServerContextSet;
00217   SystemServerContextSet uninitialized_server_contexts_;
00218 
00222   virtual UrlAsyncFetcher* AllocateFetcher(SystemRewriteOptions* config);
00223 
00224   virtual FileSystem* DefaultFileSystem();
00225   virtual NamedLockManager* DefaultLockManager();
00226 
00227  private:
00230   Statistics* SetUpGlobalSharedMemStatistics(
00231       const SystemRewriteOptions& options);
00232 
00236   GoogleString GetFetcherKey(bool include_slurping_config,
00237                              const SystemRewriteOptions* config);
00238 
00243   UrlAsyncFetcher* GetBaseFetcher(SystemRewriteOptions* config);
00244 
00245   virtual UrlAsyncFetcher* DefaultAsyncUrlFetcher();
00246 
00247   scoped_ptr<SharedMemStatistics> shared_mem_statistics_;
00250   StringVector local_shm_stats_segment_names_;
00251   scoped_ptr<AbstractSharedMem> shared_mem_runtime_;
00252   scoped_ptr<SharedCircularBuffer> shared_circular_buffer_;
00253 
00254   bool statistics_frozen_;
00255   bool is_root_process_;
00256 
00260   const GoogleString hostname_identifier_;
00261 
00264   int message_buffer_size_;
00265 
00267   scoped_ptr<SystemCaches> caches_;
00268 
00269   bool track_original_content_length_;
00270   bool list_outstanding_urls_on_error_;
00271 
00284   typedef std::map<GoogleString, UrlAsyncFetcher*> FetcherMap;
00285   FetcherMap base_fetcher_map_;
00286   FetcherMap fetcher_map_;
00287 
00288   GoogleString https_options_;
00289 
00291   SystemThreadSystem* system_thread_system_;
00292 
00293   DISALLOW_COPY_AND_ASSIGN(SystemRewriteDriverFactory);
00294 };
00295 
00296 }  
00297 
00298 #endif  ///< NET_INSTAWEB_SYSTEM_PUBLIC_SYSTEM_REWRITE_DRIVER_FACTORY_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines