Holds persistent global system state. More...
#include <SystemState.h>
Public Member Functions | |
SystemState () | |
Constructor. More... | |
SystemState (const MetaLog::EntityHeader &header_) | |
Constructor from MetaLog entity. More... | |
virtual | ~SystemState () |
Destructor. More... | |
bool | admin_set (const std::vector< SystemVariable::Spec > &specs) |
Set a vector of variables by administrator. More... | |
bool | admin_set (int code, bool value) |
Set a variable by administrator. More... | |
bool | auto_set (int code, bool value, const String &reason) |
Set a variable by automated condition. More... | |
void | get (std::vector< SystemVariable::Spec > &specs, uint64_t *generation) |
Get system variables and generation number. More... | |
bool | get_notifications (std::vector< NotificationMessage > ¬ifications) |
Get pending notifications. More... | |
void | get_non_default (std::vector< SystemVariable::Spec > &specs, uint64_t *generation=0) |
Get system state variables that are not set to their default value. More... | |
const String | name () override |
Return name of entity. More... | |
void | display (std::ostream &os) override |
Return textual representation of entity state. More... | |
void | decode (const uint8_t **bufp, size_t *remainp, uint16_t definition_version) override |
Decodes system state. More... | |
Public Member Functions inherited from Hypertable::MetaLog::Entity | |
Entity (int32_t type) | |
Constructor from entity type. More... | |
Entity (const EntityHeader &header_) | |
Constructor from entity header. More... | |
virtual | ~Entity () |
Destructor. More... | |
void | lock () |
Locks the entity's mutex. More... | |
void | unlock () |
Unlocks the entity's mutex. More... | |
void | mark_for_removal () |
Marks entity for removal. More... | |
bool | marked_for_removal () |
Checks if entity is marked for removal. More... | |
int64_t | id () const |
Returns the entity ID. More... | |
Public Member Functions inherited from Hypertable::Serializable | |
virtual size_t | encoded_length () const |
Returns serialized object length. More... | |
virtual void | encode (uint8_t **bufp) const |
Writes serialized representation of object to a buffer. More... | |
virtual void | decode (const uint8_t **bufp, size_t *remainp) |
Reads serialized representation of object from a buffer. More... | |
Private Member Functions | |
uint8_t | encoding_version () const override |
Returns encoding version. More... | |
size_t | encoded_length_internal () const override |
Returns internal serialized length. More... | |
void | encode_internal (uint8_t **bufp) const override |
Writes serialized representation of object to a buffer. More... | |
void | decode_internal (uint8_t version, const uint8_t **bufp, size_t *remainp) override |
Reads serialized representation of object from a buffer. More... | |
void | decode_old (const uint8_t **bufp, size_t *remainp) |
Private Attributes | |
uint64_t | m_generation |
Generation number incremented with each state change. More... | |
std::vector< SystemVariable::Spec > | m_admin_specified |
Administratively set state variables. More... | |
std::vector< int32_t > | m_admin_last_notification |
Last notification times for admin set variables. More... | |
std::vector< SystemVariable::Spec > | m_auto_specified |
Automatically set state variables. More... | |
std::vector< int32_t > | m_auto_last_notification |
Last notification times for auto set variables. More... | |
std::vector< NotificationMessage > | m_notifications |
Pending notification messages. More... | |
int32_t | m_notification_interval |
Notification interval in seconds. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from Hypertable::MetaLog::Entity | |
void | encode_entry (uint8_t **bufp) |
Encodes entity header plus serialized state. More... | |
Protected Attributes inherited from Hypertable::MetaLog::Entity | |
std::mutex | m_mutex |
Mutex for serializing access to members More... | |
EntityHeader | header |
Entity header More... | |
Holds persistent global system state.
Definition at line 45 of file SystemState.h.
SystemState::SystemState | ( | ) |
Constructor.
This constructor intializes the m_admin_specified and m_auto_specified arrays with system variables and their default values. It also initializes m_admin_last_notification and m_auto_last_notification to the same size as the spec arrays, with all zeros. It also sets m_notification_interval to the value of the Hypertable.Master.NotificationInterval
property.
Definition at line 33 of file SystemState.cc.
SystemState::SystemState | ( | const MetaLog::EntityHeader & | header_ | ) |
Constructor from MetaLog entity.
header_ | MetaLog entity header |
Definition at line 48 of file SystemState.cc.
|
inlinevirtual |
Destructor.
Definition at line 64 of file SystemState.h.
bool SystemState::admin_set | ( | const std::vector< SystemVariable::Spec > & | specs | ) |
Set a vector of variables by administrator.
For each variable spec in specs
, this method updates the values in the m_admin_specified vector. If the variable state changes, or the variable is in the non-default state and the time since the last notification has exceeded m_notification_interval, it creates a notification and adds it to m_notifications.
specs | Vector of variable specifications |
Definition at line 54 of file SystemState.cc.
bool SystemState::admin_set | ( | int | code, |
bool | value | ||
) |
Set a variable by administrator.
This method updates the values in the m_admin_specified vector. If the variable state changes, or the variable is in the non-default state and the time since the last notification has exceeded m_notification_interval, it creates a notification and adds it to m_notifications.
code | Variable code to set |
value | Value of variable to set |
Definition at line 81 of file SystemState.cc.
bool SystemState::auto_set | ( | int | code, |
bool | value, | ||
const String & | reason | ||
) |
Set a variable by automated condition.
This method updates the values in the m_auto_specified vector. If the variable state changes, or the variable is in the non-default state and the time since the last notification has exceeded m_notification_interval, it creates a notification and adds it to m_notifications. The notification message body is constructed as:
value
reason
.code | Variable code to set |
value | Value of variable to set |
reason | String describing reason for state change |
Definition at line 105 of file SystemState.cc.
|
overridevirtual |
Decodes system state.
See encode_state() for format description.
bufp | Address of source buffer pointer (advanced by call) |
remainp | Amount of remaining buffer pointed to by *bufp (decremented by call). |
definition_version | Version of DefinitionMaster |
Reimplemented from Hypertable::MetaLog::Entity.
Definition at line 188 of file SystemState.cc.
|
overrideprivatevirtual |
Reads serialized representation of object from a buffer.
This function is to be overridden by derived classes and should decode the object per-se as encoded with encode_internal().
version | Encoding version |
bufp | Address of destination buffer pointer (advanced by call) |
remainp | Address of integer holding amount of serialized encoding remaining |
Implements Hypertable::Serializable.
Definition at line 227 of file SystemState.cc.
|
private |
Definition at line 263 of file SystemState.cc.
|
overridevirtual |
Return textual representation of entity state.
os | Output stream on which to write state string |
Reimplemented from Hypertable::MetaLog::Entity.
Definition at line 178 of file SystemState.cc.
|
overrideprivatevirtual |
Writes serialized representation of object to a buffer.
This function is to be overridden by derived classes and should encode the object per-se.
bufp | Address of destination buffer pointer (advanced by call) |
Implements Hypertable::Serializable.
Definition at line 213 of file SystemState.cc.
|
overrideprivatevirtual |
Returns internal serialized length.
This function is to be overridden by derived classes and should return the length of the the serialized object per-se.
Implements Hypertable::Serializable.
Definition at line 202 of file SystemState.cc.
|
overrideprivatevirtual |
Returns encoding version.
Implements Hypertable::Serializable.
Definition at line 198 of file SystemState.cc.
void SystemState::get | ( | std::vector< SystemVariable::Spec > & | specs, |
uint64_t * | generation | ||
) |
Get system variables and generation number.
This method returns a vector of system variables and their current values as well as the current system state generation number. Each variable's value is set to the default value if both the administratively and automatically set variables are set to the default value, otherwise the value is set to boolean NOT of the default value.
specs | Reference to vector of variable specifications |
generation | Address of variable to hold generation number |
Definition at line 129 of file SystemState.cc.
void SystemState::get_non_default | ( | std::vector< SystemVariable::Spec > & | specs, |
uint64_t * | generation = 0 |
||
) |
Get system state variables that are not set to their default value.
This method returns a vector of system variable specs for the variables that are not set to their default value.
specs | Reference to vector of variable specifications |
generation | Address of variable to hold generation number |
Definition at line 157 of file SystemState.cc.
bool SystemState::get_notifications | ( | std::vector< NotificationMessage > & | notifications | ) |
Get pending notifications.
This method copies m_notifications to notifications
and then clears m_notifications.
Definition at line 149 of file SystemState.cc.
|
inlineoverridevirtual |
Return name of entity.
Implements Hypertable::MetaLog::Entity.
Definition at line 138 of file SystemState.h.
|
private |
Last notification times for admin set variables.
Definition at line 175 of file SystemState.h.
|
private |
Administratively set state variables.
Definition at line 172 of file SystemState.h.
|
private |
Last notification times for auto set variables.
Definition at line 181 of file SystemState.h.
|
private |
Automatically set state variables.
Definition at line 178 of file SystemState.h.
|
private |
Generation number incremented with each state change.
Definition at line 169 of file SystemState.h.
|
private |
Notification interval in seconds.
Definition at line 187 of file SystemState.h.
|
private |
Pending notification messages.
Definition at line 184 of file SystemState.h.