273 lines
8.5 KiB
C++
273 lines
8.5 KiB
C++
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
// along with this program. If not, see http://www.gnu.org/licenses/.
|
|
//
|
|
/*
|
|
* File: Dispatcher.h
|
|
* Author: jgaebler
|
|
*
|
|
* Created on September 20, 2010, 1:30 PM
|
|
*/
|
|
#pragma once
|
|
|
|
#ifndef DISPATCHER_H
|
|
#define DISPATCHER_H
|
|
|
|
#include "ct/CausalTransfer.h"
|
|
#include "common/UbeemeConnector.h"
|
|
#include "common/transport/TransportAddress.h"
|
|
#include "common/transport/MoversightMessageQueue.h"
|
|
#include "common/validator/MessageValidatorType.h"
|
|
#include "event/EventService.h"
|
|
#include "event/ObjectListener.h"
|
|
#include "merge/MergeService.h"
|
|
#include "mob/MobilitySupport.h"
|
|
#include "mrs/MaintanceRoleService.h"
|
|
#include "mrs/metric/MaintanceMomentMetricTypes.h"
|
|
#include "mrs/sync/NextViewBuffer.h"
|
|
#include "ms/placingstrategy/PeerPlacingStrategyType.h"
|
|
#include "ms/MembershipService.h"
|
|
#include "ms/Invitation.h"
|
|
#include "mt/MessageTransfer.h"
|
|
#include "fd/FailureDetector.h"
|
|
#include "rvd/ResourceValueDistributor.h"
|
|
#include "simutils/logger/MemberRegisterLogger.h"
|
|
#include "split/SplitService.h"
|
|
#include "st/StreamTransfer.h"
|
|
#include "ts/TimeService.h"
|
|
#include "ut/UnicastTransfer.h"
|
|
|
|
#if UBEEME
|
|
#include "core/event/event_container.h"
|
|
#include "core/event/event_sender.h"
|
|
|
|
class GroupMessage;
|
|
#endif
|
|
|
|
|
|
namespace ubeeme {
|
|
namespace moversight {
|
|
|
|
class MessageValidator;
|
|
class Moversight;
|
|
class Application;
|
|
class Peer;
|
|
class PeerResources;
|
|
class Roster;
|
|
class NetworkFailureDetector;
|
|
|
|
/**
|
|
* @brief Implements the dispatcher of the Moversight protocol.
|
|
* @class Dispatcher
|
|
* @ingroup Moversight
|
|
* @author Jan Gäbler, Robert Noack
|
|
*/
|
|
#if OMNETPP
|
|
class Dispatcher : public ObjectListener {
|
|
#else
|
|
|
|
class Dispatcher : public EventSender {
|
|
#endif
|
|
public:
|
|
|
|
Dispatcher(Moversight & aModule, Application & app);
|
|
virtual ~Dispatcher();
|
|
|
|
virtual void initialise();
|
|
virtual void handleMessage(MoversightMessage *msg);
|
|
void handleSavedMessages();
|
|
|
|
// ----------------------------------------------------------------
|
|
// API Methods
|
|
// ----------------------------------------------------------------
|
|
void sendMessage(MulticastMessage& msg); // @NOTE used by several services.
|
|
void sendMessage(StreamMessage& msg);
|
|
|
|
void invitePeer(TransportAddress & ta, PeerDescription & pDesc);
|
|
void cancelInvitation(TransportAddress & ta, std::string reason);
|
|
|
|
void acceptInvitation(const Invitation & inv, const std::string & comment, const PeerDescription & pDesc, const PeerResources & resource);
|
|
void rejectInvitation(const Invitation & inv, const std::string & reason);
|
|
|
|
void leaveGroup();
|
|
|
|
void splitGroup(unsigned char options, PeerIDList splitPeers);
|
|
void mergeGroup(TransportAddress & destTa);
|
|
void acceptGroupMerge();
|
|
void rejectGroupMerge(std::string & reason);
|
|
|
|
Peer & getLocalPeer();
|
|
TransportAddress getLocalAddressFromPeer(PeerID pId);
|
|
const State & getLocalState() const;
|
|
const SubState & getLocalSubState() const;
|
|
const StateOperation & getLocalStateOperation() const;
|
|
|
|
void setLocalPeerResources(const PeerResources & pres);
|
|
const PeerResources & getLocalPeerResources() const;
|
|
|
|
ViewID getViewID() const;
|
|
|
|
// ----------------------------------------------------------------
|
|
// Object Delivery System
|
|
// ----------------------------------------------------------------
|
|
template<typename ObjType>
|
|
void subscribe(ObjectListener * ol);
|
|
template<typename ObjType>
|
|
void unsubscribe(ObjectListener * ol);
|
|
void unsubscribeAll(ObjectListener * ol);
|
|
|
|
void signal(DeliverableObject* e, ObjectListener* recipient = NULL);
|
|
|
|
// Event Handling
|
|
void handleEvent(const GroupClosedEvent & e);
|
|
void handleEvent(const FlushDoneEvent & e);
|
|
|
|
//-----------------------------------------------------------------
|
|
// Event signals from other Ubeeme components
|
|
//-----------------------------------------------------------------
|
|
void signalConnectionLost();
|
|
void signalConnectionReEstablished();
|
|
// ----------------------------------------------------------------
|
|
|
|
Application & getMoversightCallback();
|
|
const Application & getMoversightCallback() const;
|
|
|
|
Moversight & getMoversight();
|
|
const Moversight & getMoversight() const;
|
|
|
|
MembershipService & getMembershipService();
|
|
const MembershipService & getMembershipService() const;
|
|
|
|
EventService & getEventService();
|
|
const EventService & getEventService() const;
|
|
|
|
FailureDetector & getFailureDetector();
|
|
const FailureDetector & getFailureDetector() const;
|
|
|
|
NetworkFailureDetector & getNetworkFailureDetector();
|
|
const NetworkFailureDetector & getNetworkFailureDetector() const;
|
|
|
|
MobilitySupport & getMobilitySupport();
|
|
const MobilitySupport & getMobilitySupport() const;
|
|
|
|
TimeService & getTimeService();
|
|
const TimeService & getTimeService() const;
|
|
|
|
MergeService & getMergeService();
|
|
const MergeService & getMergeService() const;
|
|
|
|
SplitService & getSplitService();
|
|
const SplitService & getSplitService() const;
|
|
|
|
CausalTransfer & getCausalTransfer();
|
|
const CausalTransfer & getCausalTransfer() const;
|
|
|
|
StreamTransfer & getStreamTransfer();
|
|
const StreamTransfer & getStreamTransfer() const;
|
|
|
|
UnicastTransfer & getUnicastTransfer();
|
|
const UnicastTransfer & getUnicastTransfer() const;
|
|
|
|
MessageTransfer & getMessageTransfer();
|
|
const MessageTransfer & getMessageTransfer() const;
|
|
|
|
MaintenanceRoleService & getMaintenanceRoleService();
|
|
const MaintenanceRoleService & getMaintenanceRoleService() const;
|
|
|
|
ResourceValueDistributor & getResourceValueDistributor();
|
|
const ResourceValueDistributor & getResourceValueDistributor() const;
|
|
|
|
NextViewBuffer & getNextViewBuffer();
|
|
const NextViewBuffer & getNextViewBuffer() const;
|
|
|
|
size_t getGroupSize() const;
|
|
const PeerPlacingStrategyType & getPeerPlacingStrategyType() const;
|
|
|
|
const PeerPlacingStrategyMetricType & getPeerPlacingStrategyMetricType() const;
|
|
|
|
const MaintanceMomentMetricType & getMaintanceMomentMetricType() const;
|
|
|
|
void setStandardMessageValidator();
|
|
void setMessageValidator(MessageValidatorType type);
|
|
const MessageValidator * getMessageValidator() const;
|
|
|
|
void setupGroupFromRoster(Roster & roster, PeerID localPeerID);
|
|
|
|
Dispatcher & operator = (Dispatcher const & other);
|
|
|
|
private:
|
|
|
|
virtual void finalise();
|
|
|
|
Application & app;
|
|
|
|
Moversight & module;
|
|
|
|
MembershipService ms;
|
|
EventService es;
|
|
CausalTransfer ct;
|
|
StreamTransfer st;
|
|
UnicastTransfer ut;
|
|
MessageTransfer mt;
|
|
FailureDetector fd;
|
|
MobilitySupport mob;
|
|
MergeService merge;
|
|
SplitService split;
|
|
TimeService ts;
|
|
MaintenanceRoleService mrs;
|
|
ResourceValueDistributor rvd;
|
|
NextViewBuffer nvb;
|
|
|
|
UbeemeConnector uc;
|
|
|
|
MessageValidator * messageValidator;
|
|
// MoversightMessageQueue tempMessageQueue;
|
|
MemberRegisterLogger logMemberRegister;
|
|
};
|
|
|
|
/**
|
|
* @brief Subscribe for a certain type of object.
|
|
*
|
|
* This will add <ObjType> as a key value to <subscriptions>, if not
|
|
* already present. <ms> will be inserted in the object's subscriber list.
|
|
* To subscribe to multiple objects, you have to call <subscribe()>
|
|
* subsequently.
|
|
*
|
|
* @tparam ObjType Type of object to subscribe to.
|
|
* @param ms The Moversight service which is subscribing to the object.
|
|
*/
|
|
template<typename ObjType>
|
|
void
|
|
Dispatcher::subscribe(ObjectListener * ol) {
|
|
es.subscribe(ol, typeid(ObjType*).name());
|
|
}
|
|
|
|
/**
|
|
* @brief Unsubscribe from a certain type of object.
|
|
*
|
|
* The service will be removed from the object's list of subscribers.
|
|
* To unsubscribe from multiple objects you have to use subsequent calls
|
|
* to <unsubscribe()>.
|
|
*
|
|
* @tparam ObjType Type of object to unsubscribe from.
|
|
* @param ms The Moversight service to unsubscribe.
|
|
*/
|
|
template<typename ObjType>
|
|
void
|
|
Dispatcher::unsubscribe(ObjectListener * ol) {
|
|
es.unsubscribe(ol, typeid(ObjType*).name());
|
|
}
|
|
}
|
|
}
|
|
#endif /* DISPATCHER_H */
|