Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Member Functions | List of all members
net_instaweb::CentralControllerCallback< TransactionContext > Class Template Referenceabstract

#include "central_controller_callback.h"

Inheritance diagram for net_instaweb::CentralControllerCallback< TransactionContext >:
net_instaweb::Function

Public Member Functions

void SetTransactionContext (TransactionContext *ctx)
 
- Public Member Functions inherited from net_instaweb::Function
void set_quit_requested_pointer (AtomicBool *x)
 
bool quit_requested () const
 
void CallRun ()
 
void CallCancel ()
 
void set_delete_after_callback (bool x)
 
void Reset ()
 

Protected Member Functions

 CentralControllerCallback (Sequence *sequence)
 
virtual void Run ()
 
virtual void Cancel ()
 

Detailed Description

template<typename TransactionContext>
class net_instaweb::CentralControllerCallback< TransactionContext >

CentralControllerCallback is a Function specialization that encapsulates a call to the CentralController. Users are expected to interact with this via a purpose-specific subclass, eg: ExpensiveOperationCallback.

Calls to the CentralController are expected to go via an RPC interface. Since the Run operation may be expensive, it is important to not block the RPC dispatcher thread, so this callback "re-queues" itself onto a Sequence to do the actual work.

If the CentralController successfully processes the request, Run() will be called. At this point, the CentralController may have allocated resources which must be returned. However, it is also possible that the callback will be load-shed from the Sequence. It is important that the CentralController is always notified when it can reclaim the resources, even if the actual operation is load-shed. This is where the TransactionContext comes in; it guarantees to notify the controller to release any held resources exactly once, either upon destruction of the context or by explicit calls from the consumer class(es). Construction and exact semantics of the TransactionContext are managed by the CentralController implementation.

The TransactionContext is also the way a caller can signal information to the CentralController. For instance, it may implement a Success() or Failure() method. For the case where the operation performed by the caller outlives the Run() callback, a scoped_ptr to the context is passed into RunImpl(), which may "steal" the pointer.

The CentralController also has the option of denying the operation, which will result in a call to Cancel(). This will also happen in the case of an RPC error. It is the responsibility of the TransactionContext to clean up in the case where an RPC failure occurs partway through a transaction.

Member Function Documentation

template<typename TransactionContext >
void net_instaweb::CentralControllerCallback< TransactionContext >::Cancel ( )
protectedvirtual

override

Server rejected the request or RPC error. Enqueue a Cancellation. Will synchronously call CancelAfterRequeue if sequence_ is shutdown.

Reimplemented from net_instaweb::Function.

template<typename TransactionContext >
void net_instaweb::CentralControllerCallback< TransactionContext >::Run ( )
protectedvirtual

Function interface. These will be invoked on the RPC thread, so must be quick. They just enqueue calls on sequence_ to the actual implementations (RunAfterRequeue & CancelAfterRequeue). override

Now enqueue the call to actually run. Will synchronously call CancelAfterRequeue if sequence_ is shutdown.

Implements net_instaweb::Function.

template<typename TransactionContext>
void net_instaweb::CentralControllerCallback< TransactionContext >::SetTransactionContext ( TransactionContext *  ctx)

Called by the CentralController at some point before Run or Cancel. Takes ownership of the transaction context.

Todo:
TODO(cheesy): It would be nice if this wasn't public, but that causes mutual visibility headaches with the context implementations.

The documentation for this class was generated from the following file: