FREEDM DGI
Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
freedm::broker::sc::SCAgent Class Reference

#include <StateCollection.hpp>

Inheritance diagram for freedm::broker::sc::SCAgent:
freedm::broker::IDGIModule

Public Member Functions

 SCAgent ()
 Constructor. More...
 

Protected Member Functions

CPeerNode GetMe ()
 Gets a CPeerNode representing this process. More...
 
std::string GetUUID () const
 Gets the UUID of this process. More...
 

Private Types

typedef std::pair< std::string, int > StateVersion
 

Private Member Functions

CPeerNode AddPeer (CPeerNode peer)
 Add a peer to peer set from a pointer to a peer node object. More...
 
CPeerNode GetPeer (std::string uuid)
 Get a pointer to a peer from UUID. More...
 
void HandleAccept (CPeerNode peer)
 Handle receiving messages. More...
 
void HandleIncomingMessage (boost::shared_ptr< const ModuleMessage > msg, CPeerNode peer)
 Handles received messages. More...
 
void HandleMarker (const MarkerMessage &msg, CPeerNode peer)
 
void HandlePeerList (const gm::PeerListMessage &msg, CPeerNode peer)
 
void HandleRequest (const RequestMessage &msg, CPeerNode peer)
 
void HandleState (const StateMessage &msg, CPeerNode peer)
 
void Initiate ()
 Initiator starts state collection. More...
 
void SaveForward (StateVersion latest, const MarkerMessage &msg)
 Peer save local state and forward maker. More...
 
void SendStateBack ()
 Peer sends collected states back to the initiator. More...
 
void StateResponse ()
 Initiator sends collected states back to the request module. More...
 
void TakeSnapshot (const std::vector< std::string > &devicelist)
 Save local state. More...
 

Static Private Member Functions

static ModuleMessage PrepareForSending (const StateCollectionMessage &message, std::string recipient="sc")
 Wraps a StateCollectionMessage in a ModuleMessage. More...
 

Private Attributes

std::multimap< StateVersion, StateMessage > collectstate
 collect states container and its iterator More...
 
std::multimap< StateVersion, StateMessage >::iterator it
 
PeerSet m_AllPeers
 all known peers More...
 
unsigned int m_countdone
 count number of "Done" messages More...
 
unsigned int m_countmarker
 count number of marker More...
 
unsigned int m_countstate
 count number of states More...
 
StateMessage m_curstate
 current state More...
 
StateVersion m_curversion
 current version of marker More...
 
std::vector< std::string > m_device
 
std::string m_module
 module that request state collection More...
 
bool m_NotifyToSave
 flag to indicate save channel message More...
 
std::string m_scleader
 save leader More...
 

Detailed Description

Description:
Declaration of Chandy-Lamport Algorithm Each node that wants to initiate the state collection records its local state and sends a marker message to all other peer nodes. Upon receiving a marker for the first time, peer nodes record their local states and start recording any message from incoming channel until receive marker from other nodes (these messages belong to the channel between the nodes).

Member Typedef Documentation

typedef std::pair< std::string, int > freedm::broker::sc::SCAgent::StateVersion
private

Constructor & Destructor Documentation

freedm::broker::sc::SCAgent::SCAgent ( )

SCAgent

Description:
: Constructor for the state collection module.
Precondition:
PoxisMain prepares parameters and invokes module.
Postcondition:
Object initialized and ready to enter run state.
Limitations:
: None

Member Function Documentation

CPeerNode freedm::broker::sc::SCAgent::AddPeer ( CPeerNode  peer)
private

AddPeer

Description:
Add a peer to peer set from a pointer to a peer node object m_AllPeers is a specific peer set for SC module.
Precondition:
m_AllPeers
Postcondition:
Add a peer to m_AllPeers
Parameters
peer
Returns
a pointer to a peer node
CPeerNode IDGIModule::GetMe ( )
protectedinherited

GetMe

Description:
Gets a CPeerNode that refers to this process.
Returns
A CPeerNode referring to this process.
CPeerNode freedm::broker::sc::SCAgent::GetPeer ( std::string  uuid)
private

GetPeer

Description:
Get a pointer to a peer from UUID. m_AllPeers is a specific peer set for SC module.
Precondition:
m_AllPeers
Postcondition:
Add a peer to m_AllPeers
Parameters
uuidstring
Returns
a pointer to the peer
std::string IDGIModule::GetUUID ( ) const
protectedinherited

GetUUID

Description:
Gets this process's UUID.
Returns
This process's UUID
void freedm::broker::sc::SCAgent::HandleAccept ( CPeerNode  peer)
private

This function will be called to handle Accept messages from LoadBalancing. Normally, state collection can safely ignore these messages, but if they arrive during state collection's own phase, then there is a problem and they need to be added to the collected state.

Parameters
peerthe DGI that sent the message
void freedm::broker::sc::SCAgent::HandleIncomingMessage ( boost::shared_ptr< const ModuleMessage >  msg,
CPeerNode  peer 
)
privatevirtual

"Downcasts" incoming messages into a specific message type, and passes the message to an appropriate handler.

Parameters
msgthe incoming message
peerthe node that sent this message (could be this DGI)

Implements freedm::broker::IDGIModule.

void freedm::broker::sc::SCAgent::HandleMarker ( const MarkerMessage &  msg,
CPeerNode  peer 
)
private

SCAgent::HandleMarker

Description:
This function will be called to handle marker message.
Key:
sc.marker
Precondition:
Messages are obtained.
Postcondition:
parsing marker messages based on different conditions.
Interaction Peers:
Invoked by dispatcher, other SC
Parameters
msgthe received message
peerthe node
void freedm::broker::sc::SCAgent::HandlePeerList ( const gm::PeerListMessage &  msg,
CPeerNode  peer 
)
private

SCAgent::HandlePeerList

Description:
This function will be called to handle PeerList message.
Key:
any.PeerList
Precondition:
Messages are obtained.
Postcondition:
parsing messages, reset to default state if receiving PeerList from different leader.
Interaction Peers:
Invoked by dispatcher, other SC
Parameters
msgthe received message
peerthe node
void freedm::broker::sc::SCAgent::HandleRequest ( const RequestMessage &  msg,
CPeerNode  peer 
)
private

SCAgent::HandleRequest

Description:
This function will be called to handle state collect request message.
Key:
sc.request
Precondition:
Messages are obtained.
Postcondition:
start state collection by calling Initiate().
Parameters
msg,peer
void freedm::broker::sc::SCAgent::HandleState ( const StateMessage &  msg,
CPeerNode  peer 
)
private

SCAgent::HandleState

Description:
This function will be called to handle state message.
Key:
sc.state
Precondition:
Messages are obtained.
Postcondition:
parsing messages based on state or in-transit channel message.
Interaction Peers:
Invoked by dispatcher, other SC
Parameters
msgthe received message
peerthe node
void freedm::broker::sc::SCAgent::Initiate ( )
private

Initiate

Description:
Initiator redcords its local state and broadcasts marker.
Precondition:
Receiving state collection request from other module.
Postcondition:
The node (initiator) starts collecting state by saving its own states and broadcasting a marker out.
Device I/O:
TakeSnapshot()
Returns
Send a marker out to all known peers
Citation:
Distributed Snapshots: Determining Global States of Distributed Systems, ACM Transactions on Computer Systems, Vol. 3, No. 1, 1985, pp. 63-75
ModuleMessage freedm::broker::sc::SCAgent::PrepareForSending ( const StateCollectionMessage &  message,
std::string  recipient = "sc" 
)
staticprivate

Wraps a StateCollectionMessage in a ModuleMessage.

Parameters
messagethe message to prepare. If any required field is unset, the DGI will abort.
recipientthe module (sc/lb/gm/clk etc.) the message should be delivered to
Returns
a ModuleMessage containing a copy of the StateCollectionMessage
void freedm::broker::sc::SCAgent::SaveForward ( StateVersion  latest,
const MarkerMessage &  msg 
)
private

SaveForward

Description:
SaveForward is used by the node to save its local state and send marker out.
Precondition:
Marker message is received.
Postcondition:
The node saves its local state and sends marker out.
Parameters
latestthe current marker's version
msgthe message tp semd
void freedm::broker::sc::SCAgent::SendStateBack ( )
private

SendStateBack

Description:
SendStateBack is used by the peer to send collect states back to initiator.
Precondition:
Peer has completed its collecting states in local side.
Postcondition:
Peer sends its states back to the initiator.
Limitation:
Currently, only sending back gateway value and channel transit messages.
void freedm::broker::sc::SCAgent::StateResponse ( )
private

StateResponse

Description:
This function deals with the collectstate and prepare states sending back.
Precondition:
The initiator has collected all states.
Postcondition:
Collected states are sent back to the request module.
Interaction Peers:
other SC processes
Returns
Send message which contains gateway values and channel transit messages
Limitation:
Currently, only gateway values and channel transit messages are collected and sent back.
void freedm::broker::sc::SCAgent::TakeSnapshot ( const std::vector< std::string > &  devicelist)
private

TakeSnapshot

Description:
TakeSnapshot is used to collect local states.
Precondition:
The initiator starts state collection or the peer receives marker at first time.
Postcondition:
Save local state in container m_curstate
Limitation:
Currently, it is used to collect only the gateway values for LB module

Member Data Documentation

std::multimap<StateVersion, StateMessage> freedm::broker::sc::SCAgent::collectstate
private
std::multimap<StateVersion, StateMessage>::iterator freedm::broker::sc::SCAgent::it
private
PeerSet freedm::broker::sc::SCAgent::m_AllPeers
private
unsigned int freedm::broker::sc::SCAgent::m_countdone
private
unsigned int freedm::broker::sc::SCAgent::m_countmarker
private
unsigned int freedm::broker::sc::SCAgent::m_countstate
private
StateMessage freedm::broker::sc::SCAgent::m_curstate
private
StateVersion freedm::broker::sc::SCAgent::m_curversion
private
std::vector<std::string> freedm::broker::sc::SCAgent::m_device
private
std::string freedm::broker::sc::SCAgent::m_module
private
bool freedm::broker::sc::SCAgent::m_NotifyToSave
private
std::string freedm::broker::sc::SCAgent::m_scleader
private

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