OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
process::FlagManager Class Reference

#include <feature_flags.h>

Collaboration diagram for process::FlagManager:

Public Member Functions

void Set (const std::string &name, const std::string &version, bool enabled, FlagState::Type state, ContextVec &context_infos)
 
void Unset (const std::string &name)
 
bool IsFlagEnabled (const std::string &name, bool default_state, const ContextVec &c_vec) const
 
void ClearFlags ()
 
size_t GetFlagMapCount () const
 
void Register (Flag *flag)
 
void Unregister (const Flag *flag)
 
bool IsRegistered (const Flag *flag) const
 
size_t GetIntMapCount () const
 
FlagConfigVec GetFlagInfos () const
 

Static Public Member Functions

static FlagManagerGetInstance ()
 

Private Types

typedef std::map< std::string,
FlagConfig
FlagMap
 
typedef std::map< std::string,
FlagConfig >::iterator 
flag_map_itr
 
typedef std::map< std::string,
FlagConfig >::const_iterator 
flag_map_citr
 
typedef std::multimap
< std::string, Flag * > 
InterestMap
 
typedef std::multimap
< std::string, Flag * >
::const_iterator 
int_map_const_itr
 
typedef std::multimap
< std::string, Flag * >
::iterator 
int_map_itr
 

Private Member Functions

 FlagManager ()
 
FlagConfigVec GetFlagInfosUnlocked () const
 
 DISALLOW_COPY_AND_ASSIGN (FlagManager)
 

Private Attributes

tbb::mutex mutex_
 
FlagMap flag_map_
 
InterestMap int_map_
 

Static Private Attributes

static boost::scoped_ptr
< FlagManager
instance_
 

Friends

class Flag
 
class FlagConfigManager
 
class FlagUveManager
 

Detailed Description


FlagManager class responsible for providing functionality to maintain both feature flags capability by users and the feature modules are interested in. It will also interface with analytics/introspect to provide data on the feature flags capability in each module.

Accordingly, the class will provide APIs

  1. to interface with the north-bound server providing information on user capability feature flags and the feature flags available in the system (capability list)
  2. to interface with the modules. These include client APIs for the modules a. to query if a feature is enabled/disabled b. to get user capability information for a feature flag c. to capture module interest in relevant feature flags
  3. to interface with analytics and send module level feature flag information to analytics/introspect

Definition at line 445 of file feature_flags.h.

Member Typedef Documentation

typedef std::map<std::string, FlagConfig>::const_iterator process::FlagManager::flag_map_citr
private

Definition at line 546 of file feature_flags.h.

typedef std::map<std::string, FlagConfig>::iterator process::FlagManager::flag_map_itr
private

Definition at line 545 of file feature_flags.h.

typedef std::map<std::string, FlagConfig> process::FlagManager::FlagMap
private

=============================================

FlagMap - User Configuration/Capability list

Map that maintains flag information capability by user User configures flag name, whether it is enabled and optional flag context info.

Definition at line 544 of file feature_flags.h.

typedef std::multimap<std::string, Flag *>::const_iterator process::FlagManager::int_map_const_itr
private

Definition at line 563 of file feature_flags.h.

typedef std::multimap<std::string, Flag *>::iterator process::FlagManager::int_map_itr
private

Definition at line 564 of file feature_flags.h.

typedef std::multimap<std::string, Flag *> process::FlagManager::InterestMap
private

===================================

InterestMap - Module interest list

Map that maintains flags modules are interested in Modules provide name, description and a default value NOTE: modules can define the same flag in multiple ways based on varying the context. Hence the InteretMap can have multiple entries for the same flag. For a given (flag name, context_info) though there will be one unique entry in the InterestMap

Definition at line 562 of file feature_flags.h.

Constructor & Destructor Documentation

process::FlagManager::FlagManager ( )
inlineprivate

Definition at line 530 of file feature_flags.h.

Member Function Documentation

void process::FlagManager::ClearFlags ( )

Remove all flag data from FlagMap

Definition at line 231 of file feature_flags.cc.

process::FlagManager::DISALLOW_COPY_AND_ASSIGN ( FlagManager  )
private
FlagConfigVec process::FlagManager::GetFlagInfos ( ) const

Analytics helper APIs

API for helper class to get flag configuration information. Returns vector<FlagConfig>

Definition at line 500 of file feature_flags.cc.

Here is the call graph for this function:

FlagConfigVec process::FlagManager::GetFlagInfosUnlocked ( ) const
private

Add flag only if module is interested. This information is available in the InterestMap.

Definition at line 480 of file feature_flags.cc.

Here is the call graph for this function:

size_t process::FlagManager::GetFlagMapCount ( ) const

Get the number of flags in FlagMap

Definition at line 235 of file feature_flags.cc.

FlagManager * process::FlagManager::GetInstance ( )
static

Definition at line 224 of file feature_flags.cc.

Here is the call graph for this function:

size_t process::FlagManager::GetIntMapCount ( ) const

Get the number of flags in InterestMap

Definition at line 476 of file feature_flags.cc.

bool process::FlagManager::IsFlagEnabled ( const std::string &  name,
bool  default_state,
const ContextVec c_vec 
) const

Request from module to check if a feature flag is enabled Module provides flag name and context for which it wants to check if flag is enabled.

Check if Feature Flag is enabled given the name and optional ContextInfo. Feature is enabled under following conditions

  1. Feature flag present in FlagMap and is enabled OR
  2. Feature flag present in FlagMap but is not enabled However, default value is set to enabled AND
  3. If context is provided and matches what is configured in the FlagMap. If feature is not present in the FlagMap meaning that user has not configured the flag, the modules can use their own default values.

Get flag config

Check if Flag is enabled in config

Check if context matches user config

Context does not match

Flag not present in FlagMap. Modules will use their default state.

Definition at line 352 of file feature_flags.cc.

Here is the call graph for this function:

bool process::FlagManager::IsRegistered ( const Flag flag) const

Check if module has registered this feature flag

Definition at line 462 of file feature_flags.cc.

Here is the call graph for this function:

void process::FlagManager::Register ( Flag flag)

InterestMap APIs

Update InterestMap with feature flags modules are interested in. The Flag object will be updated when user configuration is received by the FlagManager.

Set value of flag if already present in FlagMap Also invoke cb to let modules know about the presence of user configuration for this flag

Insert into InterestMap

Definition at line 409 of file feature_flags.cc.

Here is the call graph for this function:

void process::FlagManager::Set ( const std::string &  name,
const std::string &  version,
bool  enabled,
FlagState::Type  state,
ContextVec context_infos 
)

FlagMap APIs

Process feature flags config and update FlagMap

Create a FlagConfig instance and add it to FlagMap if not present. If already present, update it.

Flag already present in FlagMap. Check if something changed and update.

New feature flag. Insert into FlagMap

New feature flag configured or change in existing flag definition. If module is interested in this flag,

  1. invoke all callbacks registered by the module for this flag.
  2. Set enabled property of Flag in InterestMap so that when modules using this flag query to check if it is enabled, the updated result is returned.

Definition at line 239 of file feature_flags.cc.

Here is the call graph for this function:

void process::FlagManager::Unregister ( const Flag flag)

Module is no longer interested in the flag. Remove from InterestMap

Definition at line 441 of file feature_flags.cc.

Here is the call graph for this function:

void process::FlagManager::Unset ( const std::string &  name)

Feature flag removed from config. Process delete.

Remove from FlagMap

Inform modules of the change

Definition at line 321 of file feature_flags.cc.

Here is the call graph for this function:

Friends And Related Function Documentation

friend class Flag
friend

Definition at line 526 of file feature_flags.h.

friend class FlagConfigManager
friend

Definition at line 527 of file feature_flags.h.

friend class FlagUveManager
friend

Definition at line 528 of file feature_flags.h.

Member Data Documentation

FlagMap process::FlagManager::flag_map_
private

Definition at line 573 of file feature_flags.h.

boost::scoped_ptr< FlagManager > process::FlagManager::instance_
staticprivate

FlagManager Class Method Implementations

FlagManager instance

Definition at line 570 of file feature_flags.h.

InterestMap process::FlagManager::int_map_
private

Definition at line 574 of file feature_flags.h.

tbb::mutex process::FlagManager::mutex_
mutableprivate

Definition at line 571 of file feature_flags.h.


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