Page Speed Optimization Libraries  1.7.30.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes
net_instaweb::SystemRewriteDriverFactory Class Reference

A server context with features specific to a psol port on a unix system. More...

#include "system_rewrite_driver_factory.h"

Inheritance diagram for net_instaweb::SystemRewriteDriverFactory:
net_instaweb::RewriteDriverFactory net_instaweb::ApacheRewriteDriverFactory

List of all members.

Public Member Functions

 SystemRewriteDriverFactory (SystemThreadSystem *thread_system, AbstractSharedMem *shared_mem_runtime, StringPiece hostname, int port)
AbstractSharedMem * shared_mem_runtime () const
SharedMemStatistics * AllocateAndInitSharedMemStatistics (bool local, const StringPiece &name, const SystemRewriteOptions &options)
 Creates and ::Initializes a shared memory statistics object.
virtual void NonStaticInitStats (Statistics *statistics)=0
NonceGenerator * DefaultNonceGenerator ()
 Creates a HashedNonceGenerator initialized with data from /dev/random.
bool is_root_process () const
virtual void RootInit ()
virtual void ChildInit ()
virtual void ParentOrChildInit ()
void PostConfig (const std::vector< SystemServerContext * > &server_contexts, GoogleString *error_message, int *error_index, Statistics **global_statistics)
void SharedCircularBufferInit (bool is_root)
virtual Hasher * NewHasher ()
virtual Timer * DefaultTimer ()
virtual ServerContextNewServerContext ()
virtual bool enable_property_cache () const
 Hook so implementations may disable the property cache.
GoogleString hostname_identifier ()
virtual void ShutDown ()
virtual void StopCacheActivity ()
SystemCachescaches ()
virtual void set_message_buffer_size (int x)
UrlAsyncFetcherGetFetcher (SystemRewriteOptions *config)
bool SetHttpsOptions (StringPiece directive, GoogleString *error_message)
void set_track_original_content_length (bool x)
bool track_original_content_length () const
void list_outstanding_urls_on_error (bool x)
virtual int requests_per_host ()
virtual int max_queue_size ()
virtual int queued_per_host ()
virtual bool use_per_vhost_statistics () const

Protected Types

typedef std::set
< SystemServerContext * > 
SystemServerContextSet

Protected Member Functions

virtual void SetupCaches (ServerContext *server_context)
virtual void SetupMessageHandlers ()
virtual void ShutDownMessageHandlers ()
virtual void SetCircularBuffer (SharedCircularBuffer *buffer)
virtual void ShutDownFetchers ()
virtual UrlAsyncFetcherAllocateFetcher (SystemRewriteOptions *config)
virtual FileSystem * DefaultFileSystem ()
virtual NamedLockManager * DefaultLockManager ()

Static Protected Member Functions

static void InitStats (Statistics *statistics)

Protected Attributes

SystemServerContextSet uninitialized_server_contexts_

Detailed Description

A server context with features specific to a psol port on a unix system.


Member Typedef Documentation

Once ServerContexts are initialized via RewriteDriverFactory::InitServerContext, they will be managed by the RewriteDriverFactory. But in the root process the ServerContexts will never be initialized. We track these here so that SystemRewriteDriverFactory::ChildInit can iterate over all the server contexts that need to be ChildInit'd, and so that we can free them in the Root process that does not run ChildInit.


Constructor & Destructor Documentation

net_instaweb::SystemRewriteDriverFactory::SystemRewriteDriverFactory ( SystemThreadSystem thread_system,
AbstractSharedMem *  shared_mem_runtime,
StringPiece  hostname,
int  port 
)

Takes ownership of thread_system.

On Posix systems implementors should leave shared_mem_runtime NULL, otherwise they should implement AbstractSharedMem for their platform and pass in an instance here. The factory takes ownership of the shared memory runtime if one is passed in. Implementors who don't want to support shared memory at all should set PAGESPEED_SUPPORT_POSIX_SHARED_MEM to false and pass in NULL, and the factory will use a NullSharedMem.


Member Function Documentation

Allocates a serf fetcher. Implementations may override this method to supply other kinds of fetchers. For example, ngx_pagespeed may return either a serf fetcher or an nginx-native fetcher depending on options.

virtual NamedLockManager* net_instaweb::SystemRewriteDriverFactory::DefaultLockManager ( ) [protected, virtual]

They may also supply a custom lock manager. The default implementation will use the file system.

Reimplemented from net_instaweb::RewriteDriverFactory.

Finds a fetcher for the settings in this config, sharing with existing fetchers if possible, otherwise making a new one (and its required thread).

static void net_instaweb::SystemRewriteDriverFactory::InitStats ( Statistics *  statistics) [static, protected]

Initializes all the statistics objects created transitively by SystemRewriteDriverFactory. Only subclasses should call this.

Reimplemented from net_instaweb::RewriteDriverFactory.

Reimplemented in net_instaweb::ApacheRewriteDriverFactory.

For shared memory resources the general setup we follow is to have the first running process (aka the root) create the necessary segments and fill in their shared data structures, while processes created to actually handle requests attach to already existing shared data structures.

During normal server startup[1], RootInit() must be called from the root process and ChildInit() in every child process.

Keep in mind, however, that when fork() is involved a process may effectively see both calls, in which case the 'ChildInit' call would come second and override the previous root status. Both calls are also invoked in the debug single-process mode (In Apache, "httpd -X".).

Note that these are not static methods -- they are invoked on every SystemRewriteDriverFactory instance, which exist for the global configuration as well as all the virtual hosts.

Implementations should override RootInit and ChildInit for their setup. See ApacheRewriteDriverFactory for an example.

[1] Besides normal startup, Apache also uses a temporary process to syntax check the config file. That basically looks like a complete normal startup and shutdown to the code.

When Serf gets a system error during polling, to avoid spamming the log we just print the number of outstanding fetch URLs. To debug this it's useful to print the complete set of URLs, in which case this should be turned on.

Creates a new ServerContext* object. ServerContext itself must be overridden per Factory as it has at least one pure virtual method.

Implements net_instaweb::RewriteDriverFactory.

virtual void net_instaweb::SystemRewriteDriverFactory::NonStaticInitStats ( Statistics *  statistics) [pure virtual]

Hook for subclasses to init their stats and call SystemRewriteDriverFactory::InitStats().

Implemented in net_instaweb::ApacheRewriteDriverFactory.

This helper method contains init procedures invoked by both RootInit() and ChildInit()

Reimplemented in net_instaweb::ApacheRewriteDriverFactory.

void net_instaweb::SystemRewriteDriverFactory::PostConfig ( const std::vector< SystemServerContext * > &  server_contexts,
GoogleString *  error_message,
int *  error_index,
Statistics **  global_statistics 
)

After the whole configuration has been read, we need to do additional configuration that requires a global view.

  • server_contexts should be all server contexts on the system
  • error_message and error_index are set if there's an error, and error_index is the index in server_contexts of the one with the issue.
  • global_statistics is lazily initialized to a shared memory statistics owned by this factory if any of the server contexts require it.

When RateLimitBackgroundFetches is enabled the fetcher needs to apply some limits. An implementation may need to tune these based on conditions only observable at startup, in which case they can override these.

Reimplemented in net_instaweb::ApacheRewriteDriverFactory.

Tracks the size of resources fetched from origin and populates the X-Original-Content-Length header for resources derived from them.

bool net_instaweb::SystemRewriteDriverFactory::SetHttpsOptions ( StringPiece  directive,
GoogleString *  error_message 
)

Parses a comma-separated list of HTTPS options. If successful, applies the options to the fetcher and returns true. If the options were invalid, error_message is populated and false is returned.

It is *not* considered an error in this context to attempt to enable HTTPS when support is not compiled in. However, an error message will be logged in the server log, and the option-setting will have no effect.

virtual void net_instaweb::SystemRewriteDriverFactory::SetupCaches ( ServerContext server_context) [protected, virtual]

Called from InitServerContext, but virtualized separately as it is platform-specific. This method must call on the server context: set_http_cache, set_metadata_cache, set_filesystem_metadata_cache, and MakePropertyCaches.

Implements net_instaweb::RewriteDriverFactory.

Reimplemented in net_instaweb::ApacheRewriteDriverFactory.

virtual void net_instaweb::SystemRewriteDriverFactory::SetupMessageHandlers ( ) [inline, protected, virtual]
Todo:
TODO(jefftk): create SystemMessageHandler and get rid of these hooks.

Reimplemented in net_instaweb::ApacheRewriteDriverFactory.

Initialize SharedCircularBuffer and pass it to SystemMessageHandler and SystemHtmlParseMessageHandler. is_root is true if this is invoked from root (ie. parent) process.

Release all the resources. It also calls the base class ShutDown to release the base class resources.

Reimplemented from net_instaweb::RewriteDriverFactory.

virtual void net_instaweb::SystemRewriteDriverFactory::ShutDownFetchers ( ) [inline, protected, virtual]

Can be overridden by subclasses to shutdown any fetchers we don't know about.

Reimplemented in net_instaweb::ApacheRewriteDriverFactory.

By default statistics are collected separately for each virtual host. Allow implementations to indicate that they don't support this.

Reimplemented in net_instaweb::ApacheRewriteDriverFactory.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines