Files
spark/src/lib/mercury/executor/Executor.cpp
T
Pedro Pinto 7ab6fd273e Added buffering to mercury queues.
We were dropping events on Dan's system when the queue filled up.
2018-10-16 15:32:54 +00:00

49 lines
1.1 KiB
C++

#include "lib/mercury/executor/Executor.h"
#include "lib/mercury/broker/Broker.h"
#include "lib/mercury/broker/BrokerProxy.h"
#include "lib/mercury/actors/Actor.h"
#include "lib/mercury/actors/IPollableActor.h"
namespace bts {
namespace mercury {
Executor::Executor() :
_broker(),
_incoming_proxies(),
_my_proxy(make_proxy()),
_actor_broker(_my_proxy),
_actors() {}
Executor::~Executor() {
for (auto &a : _actors)
a->deactivate();
}
void Executor::init_neighbours(std::vector<Executor*> const&neighbours)
{
for (auto e : neighbours)
if (e != this)
_outgoing_proxies.push_back(&e->make_proxy());
for (auto n : _outgoing_proxies)
_broker.add_neighbour(*n);
}
void Executor::activate(Actor *actor)
{
_actors.push_back(std::unique_ptr<Actor> (actor));
auto pollable = dynamic_cast<IPollableActor*> (actor);
if (pollable)
_pollable_actors.push_back(pollable);
actor->activate(_actor_broker);}
BrokerProxy& Executor::make_proxy()
{
_incoming_proxies.push_back(std::make_unique<BrokerProxy>(_broker));
return *_incoming_proxies.back();
}
} // namespace mercury
} // namespace bts