Cleaning up mercury.

This commit is contained in:
Pedro Pinto committed 2018-10-02 16:24:00 +00:00
1 parent fa2a2e2107
commit ef3b39361a
7 files changed
+37 -39

No files matched your search

+2 -6
View File
@@ -9,7 +9,7 @@ namespace mercury {
class ActorBroker {
public:
ActorBroker (ILocalBroker &real_broker) : _proxy(real_broker),_proxy_id(_proxy.id()),_current_suid(0) {}
ActorBroker (BrokerProxy &proxy) : _proxy(proxy),_proxy_id(_proxy.id()),_current_suid(0) {}
BrokerID id() {return _proxy_id;}
@@ -55,16 +55,12 @@ public:
_proxy.send_notify(_proxy_id, stream.sid, SubID(0), *msg);
}
void do_work() {
_proxy.do_work();
}
void schedule_action (std::function<void()> const&action) {
_proxy.schedule_action(action);
}
private:
BrokerProxy _proxy;
BrokerProxy &_proxy;
BrokerID _proxy_id;
LocalSubID _current_suid;
};
+1 -1
View File
@@ -82,7 +82,7 @@ void BrokerProxy::local_subscribe(LocalSubID lsid, TopicFilter const &tf,
void BrokerProxy::local_unsubscribe(LocalSubID lsid) {
auto m = _action_pool.construct();
m->msg_type = BrokerMsgType::LOCAL_SUBSCRIBE;
m->msg_type = BrokerMsgType::LOCAL_UNSUBSCRIBE;
m->local_sub_id = lsid;
send(*m);
}
+7 -10
View File
@@ -12,7 +12,7 @@ namespace bts {
namespace mercury {
class BrokerProxy : public ILocalBroker {
protected:
protected:
friend class ActorBroker;
enum class BrokerMsgType {
ADD_NEIGHBOUR,
@@ -61,19 +61,16 @@ protected:
void schedule_action(std::function<void()> const &action);
// these are just for performance, we want to avoid to allow for
// these are just for performance, we want to allow for
// notifications to be initialized in place but this class does not
// know how to do that, so we need to expose the notification
// member to the outside.
void alloc_notify(BrokerMsg **msg, Notification **n)
{
void alloc_notify(BrokerMsg **msg, Notification **n) {
auto m = _action_pool.construct();
*msg = m;
*n = &m->notification;
}
void send_notify(BrokerID bid, StreamID sid, SubID suid, BrokerMsg &m)
{
void send_notify(BrokerID bid, StreamID sid, SubID suid, BrokerMsg &m) {
m.msg_type = BrokerMsgType::NOTIFY;
m.broker_id = bid;
m.stream_id = sid;
@@ -82,7 +79,7 @@ protected:
}
void do_work() {
_outgoing.consume_all([this](BrokerMsg *m) {
_outgoing.consume_all([this](BrokerMsg *m) {
switch (m->msg_type) {
case BrokerMsgType::ADD_NEIGHBOUR:
_real_broker.add_neighbour(*m->neighbour);
@@ -104,11 +101,11 @@ protected:
break;
case BrokerMsgType::NOTIFY:
_real_broker.notify(m->broker_id, m->stream_id, m->sub_id,
m->notification);
m->notification);
break;
case BrokerMsgType::LOCAL_SUBSCRIBE:
_real_broker.local_subscribe(m->local_sub_id, m->filter,
m->local_handler);
m->local_handler);
break;
case BrokerMsgType::LOCAL_UNSUBSCRIBE:
_real_broker.local_unsubscribe(m->local_sub_id);
+7 -3
View File
@@ -7,7 +7,11 @@
namespace bts {
namespace mercury {
Executor::Executor() : _broker(), _actor_broker(_broker),_actors() {}
Executor::Executor() :
_broker(),
_proxies(),
_actor_broker(make_proxy()),
_actors() {}
Executor::~Executor() {
for (auto &a : _actors)
@@ -36,8 +40,8 @@ void Executor::activate(Actor *actor)
BrokerProxy& Executor::make_proxy()
{
_neighbour_proxies.push_back(std::make_unique<BrokerProxy>(_broker));
return *_neighbour_proxies.back();
_proxies.push_back(std::make_unique<BrokerProxy>(_broker));
return *_proxies.back();
}
} // namespace mercury
+2 -3
View File
@@ -23,10 +23,9 @@ class Executor {
}
void do_work() {
_actor_broker.do_work();
for (auto p : _pollable_actors)
p->on_poll();
for (auto &bp : _neighbour_proxies)
for (auto &bp : _proxies)
bp->do_work();
}
@@ -35,9 +34,9 @@ class Executor {
private:
Broker _broker;
std::vector<std::unique_ptr<BrokerProxy>> _proxies;
ActorBroker _actor_broker;
std::vector<IPollableActor *> _pollable_actors;
std::vector<std::unique_ptr<BrokerProxy>> _neighbour_proxies;
std::vector<std::unique_ptr<Actor>> _actors;
};
} // namespace mercury
+5 -5
View File
@@ -137,7 +137,7 @@ ServiceBridge::create_order(api::orderman::Create const &c) {
std::promise<api::orderman::Response> p;
auto f = p.get_future();
schedule_action([this, &c, &p]() {
me->service_call_marshaller.schedule_action([this, &c, &p]() {
api::orderman::Response r;
if (is_ready()) {
@@ -163,7 +163,7 @@ ServiceBridge::update_order(api::orderman::Update const &c) {
std::promise<api::orderman::Response> p;
auto f = p.get_future();
schedule_action([this, &c, &p]() {
me->service_call_marshaller.schedule_action([this, &c, &p]() {
api::orderman::Response r;
if (is_ready()) {
@@ -190,7 +190,7 @@ ServiceBridge::cancel_order(api::orderman::Cancel const &c) {
std::promise<api::orderman::Response> p;
auto f = p.get_future();
schedule_action([this, &c, &p]() {
me->service_call_marshaller.schedule_action([this, &c, &p]() {
api::orderman::Response r;
if (is_ready()) {
@@ -213,7 +213,7 @@ ServiceBridge::crack_order(api::orderman::Crack const &c) {
std::promise<api::orderman::Response> p;
auto f = p.get_future();
schedule_action([this, &c, &p]() {
me->service_call_marshaller.schedule_action([this, &c, &p]() {
api::orderman::Response r;
if (is_ready()) {
@@ -233,7 +233,7 @@ ServiceBridge::crack_order(api::orderman::Crack const &c) {
void ServiceBridge::update_admin_data(
std::shared_ptr<const api::admin::AdminData> const &admin) {
schedule_action([this, admin]() {
me->service_call_marshaller.schedule_action([this, admin]() {
me->admin_data_updates.push_back(admin);
publish(me->new_admin_data_pub, *admin);
});
+13 -11
View File
@@ -125,17 +125,6 @@ OrderServiceServer::OrderServiceServer(
me->publish_orders = make_orders_publisher();
me->publish_fills = make_fills_publisher();
me->service_bridge = new ServiceBridge(
[this]() { me->service_ready = true; },
[this, &ctx](auto const &orders) {
ctx.post([this, orders] { this->on_orders(orders); });
},
[this, &ctx](auto const &fill) {
ctx.post([this, fill] { this->on_fills(fill); });
});
std::vector<mercury::Executor*> all_executors;
for (auto const &thread_cfg : config::get<config::OrdermanCfg>().thread()) {
auto at = std::make_unique<ActorThread>(thread_cfg,stats);
@@ -201,6 +190,19 @@ OrderServiceServer::OrderServiceServer(
thread = find_thread_for_actor("ServiceBridge", me->actor_threads);
bts_assert_msg(thread, "Could not find a configured thread for ServiceBridge. See "
"the OrdermanCfg key");
me->service_bridge = new ServiceBridge(
[this]() { me->service_ready = true; },
[this, &ctx](auto const &orders) {
ctx.post([this, orders] { this->on_orders(orders); });
},
[this, &ctx](auto const &fill) {
ctx.post([this, fill] { this->on_fills(fill); });
},
thread->executor.make_proxy()
);
thread->executor.activate(me->service_bridge);
// spin up threads