Replace SendHelper with Send call

Reviewers: zuza

Reviewed By: zuza

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D649
This commit is contained in:
Sasa Stanko 2017-08-08 17:36:07 +02:00
parent 045e14e139
commit d88380c602
5 changed files with 11 additions and 17 deletions

View File

@ -176,9 +176,7 @@ class Master : public Reactor {
auto connector = Open(txn_channel_name);
auto stream = connector.first;
auto create_node_txn =
std::make_unique<CreateNodeTxn>("master", "main", xid);
channels_[worker_id]->SendHelper(typeid(nullptr), std::move(create_node_txn));
channels_[worker_id]->Send<CreateNodeTxn>("master", "main", xid);
auto m = stream->AwaitEvent();
if (CommitRequest *req = dynamic_cast<CommitRequest *>(m.get())) {
req->GetChannelToSender(system_)->Send<CommitDirective>();
@ -306,8 +304,7 @@ class Worker : public Reactor {
auto stream = connector.first;
auto masterChannel = txn->GetChannelToSender(system_);
// TODO: Do the actual commit.
masterChannel->SendHelper(typeid(nullptr),
std::make_unique<CommitRequest>("master", "main", worker_id_));
masterChannel->Send<CommitRequest>("master", "main", worker_id_);
auto m = stream->AwaitEvent();
if (dynamic_cast<CommitDirective *>(m.get())) {
// TODO: storage_.CreateNode();
@ -328,11 +325,10 @@ class Worker : public Reactor {
// TODO: Fix this hack -- use the storage.
int num = 123;
masterChannel->SendHelper(typeid(nullptr),
std::make_unique<CommitRequest>("master", "main", worker_id_));
masterChannel->Send<CommitRequest>("master", "main", worker_id_);
auto m = stream->AwaitEvent();
if (dynamic_cast<CommitDirective *>(m.get())) {
masterChannel->SendHelper(typeid(nullptr), std::make_unique<CountNodesTxnResult>(num));
masterChannel->Send<CountNodesTxnResult>(num);
} else if (dynamic_cast<AbortDirective *>(m.get())) {
// send nothing
} else {
@ -370,9 +366,9 @@ void ClientMain(System *system) {
std::getline(std::cin, s);
if (s == "quit") {
active = false;
channel->SendHelper(typeid(nullptr), std::make_unique<Quit>());
channel->Send<Quit>();
} else {
channel->SendHelper(typeid(nullptr), std::make_unique<Query>(s));
channel->Send<Query>(s);
}
}
}

View File

@ -508,7 +508,7 @@ class Network {
virtual std::string Name() { return channel_; }
virtual void SendHelper(const std::type_index &tidx, std::unique_ptr<Message> message) {
virtual void SendHelper(const std::type_index& tidx, std::unique_ptr<Message> message) {
network_->mutex_.lock();
network_->queue_.push(NetworkMessage(address_, port_, reactor_, channel_,
std::move(message)));

View File

@ -64,7 +64,7 @@ void Session::Execute() {
return;
}
channel->SendHelper(typeid(nullptr), std::move(message));
channel->Send(std::move(message));
SendSuccess(true);
}

View File

@ -54,8 +54,7 @@ class ChatServer : public Reactor {
<< std::endl;
auto channel = msg->GetChannelToSender(system_);
if (channel != nullptr) {
channel->SendHelper(typeid(nullptr),
std::make_unique<ChatACK>("server", "chat", msg->Message()));
channel->Send<ChatACK>("server", "chat", msg->Message());
}
} else {
std::cerr << "Unknown message received!\n";
@ -81,7 +80,7 @@ class ChatClient : public Reactor {
auto channel =
system_->network().Resolve(address, port, "server", "chat");
if (channel != nullptr) {
channel->SendHelper(typeid(nullptr), std::make_unique<ChatMessage>("server", "chat", message));
channel->Send<ChatMessage>("server", "chat", message);
} else {
std::cerr << "Couldn't resolve that server!" << std::endl;
}

View File

@ -7,8 +7,7 @@ int main(int argc, char *argv[]) {
auto channel = system.network().Resolve("127.0.0.1", 10000, "master", "main");
std::cout << channel << std::endl;
if (channel != nullptr) {
auto message = std::make_unique<SenderMessage>("master", "main");
channel->SendHelper(typeid(SenderMessage), std::move(message));
channel->Send<SenderMessage>("master", "main");
}
system.network().StopClient();
return 0;