/* */ #ifndef SECONDO_TES_MESSAGEBROKER_H #define SECONDO_TES_MESSAGEBROKER_H #include #include #include #include "MessageServer.h" #include "MessageClient.h" //#include "QueueSupplier.h" #include "LoopbackProxy.h" #include "../Helpers/RemoteEndpoint.h" #include "../typedefs.h" #include namespace distributed3 { class MessageBroker { public: MessageBroker(); ~MessageBroker(); static MessageBroker& get(); /* Tuple From Server Begin */ Tuple* getTuple(const int eid, const int slot); void addServer(const int eid, const int slot, MessageServer* server); void wakeup(const int eid, const int slot); /* Tuple From Server End */ //Tuple* getTuple(const int eid, const int slot); //void pushTuple(const int eid, const int slot, char* tuple); void pushTuple(const int eid, const int slot, Tuple* tuple); void incrementFinished(const int eid); void sendTuple(const int eid, const int slot, const int workerNumber, Tuple* tuple); void broadcastFinishMessage(const int eid); void setNumberOfSlots(const int eid, const int slots); // 5 int getNumberOfSlots(const int eid); // 5 bool startTcpListener(const int port); // in StartTESServer bool startClient(const int slot, const RemoteEndpoint host); bool startLoopbackProxy(const int slot); bool tcpListenerRunning(); // in StartTESServer /* void pauseServers(); void startServers(); */ void stopServers(); void stopClients(); void reset(); private: static MessageBroker broker; std::shared_ptr tcpListener = nullptr; std::shared_ptr globalSocket = nullptr; std::list > servers = std::list< std::shared_ptr >(); //std::shared_ptr loopbackProxy; using mt = std::map >; mt workerToClient = mt(); bool allfinished(const int eid); std::map* > > loopInboxes; //std::map* > > inboxes; template void clear(std::map*>>& inbox); std::map> inboxmutex; //std::map> inboxcond; //std::map> readymtx; //std::map> ready; std::map finished; std::map finishedMutex; std::map> servers2mtx; std::map>> servers2; std::map::iterator>> serversIterator; std::map> readycond; // uses // bool allfinished(const int eid); std::map slotCountMap; // 5 inline void initializeInboxes(const int eid, const int slots); void removeMessageServer(const int eid, const int slot); void acceptConnections(int port); }; } #endif //SECONDO_MESSAGEBROKER_H