Base class for MetaLog entities. More...
#include <MetaLogEntity.h>
Public Member Functions | |
Entity (int32_t type) | |
Constructor from entity type. More... | |
Entity (const EntityHeader &header_) | |
Constructor from entity header. More... | |
virtual | ~Entity () |
Destructor. More... | |
virtual void | decode (const uint8_t **bufp, size_t *remainp, uint16_t definition_version) |
Decodes serialized entity state. 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... | |
virtual const std::string | name ()=0 |
Returns the name of the entity. More... | |
int64_t | id () const |
Returns the entity ID. More... | |
virtual void | display (std::ostream &os) |
Prints a textual representation of the entity state to an ostream. 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... | |
Protected Member Functions | |
void | encode_entry (uint8_t **bufp) |
Encodes entity header plus serialized state. More... | |
Protected Member Functions inherited from Hypertable::Serializable | |
virtual uint8_t | encoding_version () const =0 |
Returns encoding version. More... | |
virtual size_t | encoded_length_internal () const =0 |
Returns internal serialized length. More... | |
virtual void | encode_internal (uint8_t **bufp) const =0 |
Writes serialized representation of object to a buffer. More... | |
virtual void | decode_internal (uint8_t version, const uint8_t **bufp, size_t *remainp)=0 |
Reads serialized representation of object from a buffer. More... | |
Protected Attributes | |
std::mutex | m_mutex |
Mutex for serializing access to members More... | |
EntityHeader | header |
Entity header More... | |
Friends | |
class | Reader |
class | Writer |
std::ostream & | operator<< (std::ostream &os, Entity &entity) |
ostream shift function for Entity objects. More... | |
Base class for MetaLog entities.
A MetaLog entitiy is associated with each application object that is to be persisted in the MetaLog. Entity objects are what get passed into and out of the read and write methods of the MetaLog API. Application objects can include a member that is derived from this class for the purpose of persisting its state. The application object class can also be derived from Entity allowing the application object itself to be passed directly into the Metalog APIs.
Definition at line 62 of file MetaLogEntity.h.
Entity::Entity | ( | int32_t | type | ) |
Constructor from entity type.
This method constructs a new entity, initializing the header member with type
.
type | Numeric entity type |
Definition at line 40 of file MetaLogEntity.cc.
Entity::Entity | ( | const EntityHeader & | header_ | ) |
Constructor from entity header.
This method constructs an entity from an entity header (typically read and deserialized from a MetaLog). The header member is initialized with header_
.
header_ | Entity header |
Definition at line 42 of file MetaLogEntity.cc.
|
inlinevirtual |
Destructor.
Definition at line 81 of file MetaLogEntity.h.
|
inlinevirtual |
Decodes serialized entity state.
bufp | Address of destination buffer pointer (advanced by call) |
remainp | Address of integer holding amount of remaining buffer |
definition_version | Version of MetaLog::Definition that was used to generate the log. |
Reimplemented in Hypertable::Operation, Hypertable::BalancePlanAuthority, Hypertable::MetaLog::EntityRecover, Hypertable::MetaLogEntityRange, Hypertable::SystemState, Hypertable::MetaLogEntityRemoveOkLogs, Hypertable::RecoveredServers, Hypertable::RangeServerConnection, and Hypertable::MetaLog::EntityTaskAcknowledgeRelinquish.
Definition at line 91 of file MetaLogEntity.h.
|
inlinevirtual |
Prints a textual representation of the entity state to an ostream.
os | ostream on which to print entity state |
Reimplemented in Hypertable::Operation, Hypertable::BalancePlanAuthority, Hypertable::MetaLogEntityRange, Hypertable::SystemState, Hypertable::MetaLogEntityRemoveOkLogs, Hypertable::RecoveredServers, Hypertable::RangeServerConnection, and Hypertable::MetaLog::EntityTaskAcknowledgeRelinquish.
Definition at line 142 of file MetaLogEntity.h.
|
protected |
Encodes entity header plus serialized state.
This method first encodes the serialized state at *bufp
plus EntityHeader::LENGTH bytes. It then computes the checksum of the serialized state with a call to fletcher32() and stores the result in header.checksum
. It then encodes header at the beginning of the buffer. *bufp
is left pointing to the end of the serialized state when the method returns.
bufp | Address of destination buffer pointer (advanced by call) |
Definition at line 45 of file MetaLogEntity.cc.
|
inline |
|
inline |
Locks the entity's mutex.
Definition at line 97 of file MetaLogEntity.h.
|
inline |
Marks entity for removal.
To remove an entity from a MetaLog, the entity header gets written to the log with the EntityHeader::FLAG_REMOVE bit set in the flags field of the header. This method sets the EntityHeader::FLAG_REMOVE bit in the header and sets the header length and header checksum fields to zero. After a call to this method, the next time the entity is persisted to the log, it will be logically removed.
Definition at line 110 of file MetaLogEntity.h.
|
inline |
Checks if entity is marked for removal.
This method returns true if the EntityHeader::FLAG_REMOVE bit is set in the flags member of its header which means the next time it gets persisted, it will be logically removed removed.
Definition at line 123 of file MetaLogEntity.h.
|
pure virtual |
Returns the name of the entity.
This method returns the name of the entity which is used by tools that convert a MetaLog into a human readable representation
Implemented in Hypertable::BalancePlanAuthority, Hypertable::MetaLog::EntityRecover, Hypertable::MetaLogEntityRange, Hypertable::Operation, Hypertable::SystemState, Hypertable::MetaLogEntityRemoveOkLogs, Hypertable::RecoveredServers, Hypertable::OperationRegisterServerBlocker, Hypertable::OperationCreateTable, Hypertable::OperationSetState, Hypertable::OperationDropTable, Hypertable::OperationRecreateIndexTables, Hypertable::RangeServerConnection, Hypertable::OperationToggleTableMaintenance, Hypertable::OperationCompact, Hypertable::OperationRecover, Hypertable::OperationAlterTable, Hypertable::OperationGatherStatistics, Hypertable::MetaLog::EntityTaskAcknowledgeRelinquish, Hypertable::OperationRecoverRanges, Hypertable::OperationMoveRange, Hypertable::OperationSystemStatus, Hypertable::OperationBalance, Hypertable::OperationRelinquishAcknowledge, Hypertable::OperationRenameTable, Hypertable::OperationStatus, Hypertable::OperationCreateNamespace, Hypertable::OperationDropNamespace, Hypertable::OperationRegisterServer, Hypertable::OperationSystemUpgrade, Hypertable::MetaLog::EntityTask, Hypertable::OperationStop, Hypertable::OperationTimedBarrier, Hypertable::OperationInitialize, Hypertable::OperationCollectGarbage, Hypertable::OperationRecoveryBlocker, and Hypertable::OperationWaitForServers.
|
inline |
Unlocks the entity's mutex.
Definition at line 100 of file MetaLogEntity.h.
|
friend |
ostream shift function for Entity objects.
This method writes a human readable representation of an Entity to a given ostream. It prints the header followed by the entity state.
os | ostream on which to print entity |
entity | Entity object to print |
os
Definition at line 179 of file MetaLogEntity.h.
|
friend |
Definition at line 145 of file MetaLogEntity.h.
|
friend |
Definition at line 146 of file MetaLogEntity.h.
|
protected |
Entity header
Definition at line 165 of file MetaLogEntity.h.
|
mutableprotected |
Mutex for serializing access to members
Definition at line 162 of file MetaLogEntity.h.