#include "ResourceValueUpdate.h" #include "common/validator/MessageValidator.h" #include "Dispatcher.h" #include "fd/NetworkFailureDetector.h" namespace ubeeme { namespace moversight { /** * @brief Constructor * @param peerResources - resource value of the peer * @param peerID - Id of the peer which will tell his new resource value */ ResourceValueUpdate::ResourceValueUpdate(const PeerResources & peerResources, PeerID aPeerID) : MulticastMessage("RVU", RVU), resources(peerResources), peerID(aPeerID) { } /** * @brief Deconstructor */ ResourceValueUpdate::~ResourceValueUpdate() { //dtor } /** * @brief Copy constructor * @param other Object to copy from */ ResourceValueUpdate::ResourceValueUpdate(const ResourceValueUpdate& other) : MulticastMessage(other) { operator=(other); //copy ctor } /** * @brief Assignment operator * @param other Object to assign from * @return A reference to this */ ResourceValueUpdate & ResourceValueUpdate::operator=(const ResourceValueUpdate& rhs) { if (this == &rhs) return *this; // handle self assignment resources = rhs.resources; peerID = rhs.peerID; //assignment operator return *this; } /** * @brief method duplicate this messages * @return ResourceValueUpdate */ ResourceValueUpdate * ResourceValueUpdate::dup() const { return new ResourceValueUpdate(*this); } /** * @brief Handles this message. To handle a message, it has first successfully validated. * @param dis A reference to the dispatcher, used to forward this message to the handling modules. */ void ResourceValueUpdate::handleReceive(Dispatcher& dis) { if (dis.getMessageValidator()->isValid(*this)) { //notify the NFD about ongoing traffic dis.getNetworkFailureDetector().handleMessage(this); //handle the message dis.getMessageTransfer().handleMessage(this); } } /** * @brief Handles the message delivering. To deliver a message, the message to each module which is interested in this message. * @param dis A reference to the dispatcher, used to forward this message to the handling modules. * @param missedPeers A list of peers, which have missed this message, as they are pending. */ void ResourceValueUpdate::handleDeliver(Dispatcher& dis, const PeerIDList& missedPeers) { MemberRegister & memberReg = dis.getMembershipService().getCurrentMemberRegister(); if (memberReg.contains(peerID)) { Peer & peer = memberReg.getPeer(peerID); peer.setPeerResources(resources); memberReg.printMemberRegister(); } } } }