0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Hypertable::SystemState Class Reference

Holds persistent global system state. More...

#include <SystemState.h>

Inheritance diagram for Hypertable::SystemState:
Inheritance graph
[legend]
Collaboration diagram for Hypertable::SystemState:
Collaboration graph
[legend]

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 > &notifications)
 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::Specm_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::Specm_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< NotificationMessagem_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...
 

Detailed Description

Holds persistent global system state.

Definition at line 45 of file SystemState.h.

Constructor & Destructor Documentation

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.

Parameters
header_MetaLog entity header

Definition at line 48 of file SystemState.cc.

virtual Hypertable::SystemState::~SystemState ( )
inlinevirtual

Destructor.

Definition at line 64 of file SystemState.h.

Member Function Documentation

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.

Parameters
specsVector of variable specifications
Returns
true if variable state changed and generation number incremented, false otherwise.

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.

Parameters
codeVariable code to set
valueValue of variable to set
Returns
true if variable state changed and generation number incremented, false otherwise.

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:

  • System state VARIABLE=value reason.
Parameters
codeVariable code to set
valueValue of variable to set
reasonString describing reason for state change
Returns
true if variable state changed and generation number incremented, false otherwise.

Definition at line 105 of file SystemState.cc.

void SystemState::decode ( const uint8_t **  bufp,
size_t *  remainp,
uint16_t  definition_version 
)
overridevirtual

Decodes system state.

See encode_state() for format description.

Parameters
bufpAddress of source buffer pointer (advanced by call)
remainpAmount of remaining buffer pointed to by *bufp (decremented by call).
definition_versionVersion of DefinitionMaster

Reimplemented from Hypertable::MetaLog::Entity.

Definition at line 188 of file SystemState.cc.

void SystemState::decode_internal ( uint8_t  version,
const uint8_t **  bufp,
size_t *  remainp 
)
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().

Parameters
versionEncoding version
bufpAddress of destination buffer pointer (advanced by call)
remainpAddress of integer holding amount of serialized encoding remaining
See also
encode_internal() for encoding format

Implements Hypertable::Serializable.

Definition at line 227 of file SystemState.cc.

void SystemState::decode_old ( const uint8_t **  bufp,
size_t *  remainp 
)
private

Definition at line 263 of file SystemState.cc.

void SystemState::display ( std::ostream &  os)
overridevirtual

Return textual representation of entity state.

Parameters
osOutput stream on which to write state string

Reimplemented from Hypertable::MetaLog::Entity.

Definition at line 178 of file SystemState.cc.

void SystemState::encode_internal ( uint8_t **  bufp) const
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.

Parameters
bufpAddress of destination buffer pointer (advanced by call)

Implements Hypertable::Serializable.

Definition at line 213 of file SystemState.cc.

size_t SystemState::encoded_length_internal ( ) const
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.

Returns
Internal serialized length
See also
encode_internal() for encoding format

Implements Hypertable::Serializable.

Definition at line 202 of file SystemState.cc.

uint8_t SystemState::encoding_version ( ) const
overrideprivatevirtual

Returns encoding version.

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.

Parameters
specsReference to vector of variable specifications
generationAddress 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.

Parameters
specsReference to vector of variable specifications
generationAddress 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.

Returns
true if no pending notifications, false otherwise.

Definition at line 149 of file SystemState.cc.

const String Hypertable::SystemState::name ( )
inlineoverridevirtual

Return name of entity.

Returns
Name of entity.

Implements Hypertable::MetaLog::Entity.

Definition at line 138 of file SystemState.h.

Member Data Documentation

std::vector<int32_t> Hypertable::SystemState::m_admin_last_notification
private

Last notification times for admin set variables.

Definition at line 175 of file SystemState.h.

std::vector<SystemVariable::Spec> Hypertable::SystemState::m_admin_specified
private

Administratively set state variables.

Definition at line 172 of file SystemState.h.

std::vector<int32_t> Hypertable::SystemState::m_auto_last_notification
private

Last notification times for auto set variables.

Definition at line 181 of file SystemState.h.

std::vector<SystemVariable::Spec> Hypertable::SystemState::m_auto_specified
private

Automatically set state variables.

Definition at line 178 of file SystemState.h.

uint64_t Hypertable::SystemState::m_generation
private

Generation number incremented with each state change.

Definition at line 169 of file SystemState.h.

int32_t Hypertable::SystemState::m_notification_interval
private

Notification interval in seconds.

Definition at line 187 of file SystemState.h.

std::vector<NotificationMessage> Hypertable::SystemState::m_notifications
private

Pending notification messages.

Definition at line 184 of file SystemState.h.


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