OpenSDN source code
|
#include <feature_flags.h>
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 FlagManager * | GetInstance () |
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 |
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
Definition at line 445 of file feature_flags.h.
|
private |
Definition at line 546 of file feature_flags.h.
|
private |
Definition at line 545 of file feature_flags.h.
|
private |
=============================================
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.
|
private |
Definition at line 563 of file feature_flags.h.
|
private |
Definition at line 564 of file feature_flags.h.
|
private |
===================================
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.
|
inlineprivate |
Definition at line 530 of file feature_flags.h.
void process::FlagManager::ClearFlags | ( | ) |
Remove all flag data from FlagMap
Definition at line 231 of file feature_flags.cc.
|
private |
FlagConfigVec process::FlagManager::GetFlagInfos | ( | ) | const |
API for helper class to get flag configuration information. Returns vector<FlagConfig>
Definition at line 500 of file feature_flags.cc.
|
private |
Add flag only if module is interested. This information is available in the InterestMap.
Definition at line 480 of file feature_flags.cc.
size_t process::FlagManager::GetFlagMapCount | ( | ) | const |
Get the number of flags in FlagMap
Definition at line 235 of file feature_flags.cc.
|
static |
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
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.
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.
void process::FlagManager::Register | ( | Flag * | flag | ) |
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.
void process::FlagManager::Set | ( | const std::string & | name, |
const std::string & | version, | ||
bool | enabled, | ||
FlagState::Type | state, | ||
ContextVec & | context_infos | ||
) |
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,
Definition at line 239 of file feature_flags.cc.
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.
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.
|
friend |
Definition at line 526 of file feature_flags.h.
|
friend |
Definition at line 527 of file feature_flags.h.
|
friend |
Definition at line 528 of file feature_flags.h.
|
private |
Definition at line 573 of file feature_flags.h.
|
staticprivate |
FlagManager instance
Definition at line 570 of file feature_flags.h.
|
private |
Definition at line 574 of file feature_flags.h.
|
mutableprivate |
Definition at line 571 of file feature_flags.h.