Commit Graph

11 Commits

Author SHA1 Message Date
Gleb Natapov
59f4b9af46 messaging: bind rpc client to listen-address 2015-05-21 15:17:42 +03:00
Gleb Natapov
8d9fb8a96c message: consolidate send_message() and send_message_oneway()
send_message() and send_message_oneway() are almost identical, implement
the later in terms of the former. The patch also fixes send_message() to
work properly with MsgIn = void.

Reviewed-by: Asias He <asias@cloudius-systems.com>
2015-05-13 13:41:24 +03:00
Asias He
cce98e19e4 message: Remove more leftover
class handler_base and handler are not used anymore.
2015-05-10 12:03:27 +03:00
Asias He
f12e955b4e message: Drop register_handler_oneway 2015-05-07 13:16:18 +03:00
Gleb Natapov
1a8c4b75f5 message: do not erase client's rpc call type
Currently we cast rpc call lambda to std::function (to put all lambdas
in one container) which removes its template properties and gives it
strictly typed interface. This is inconvenient since interface may either
receive an object by value (which requires copy during invocation),
or by reference (which require lifetime management), but not both. This
patch changes the implementation to no store lambda in one central
place, but create it with rpc::make_client() call when used. This way
template properties are preserved and send_message() arguments are
forwarded to rpc call with original types.

Reviewed-by: Asias He <asias@cloudius-systems.com>
2015-05-07 13:16:16 +03:00
Gleb Natapov
78d36eabc2 Merge remote-tracking branch 'origin/master' into tmpmerge
message_service: create object using placement new()

Object reference may point to a unit member that was not properly
created, so assign will not work on it. Use placement new() instead.
2015-05-05 10:39:51 +03:00
Asias He
3d36debcf8 message: Do not call remove_rpc_client() under exception
We can not remove the rpc client while the client might still "active".
2015-04-23 14:55:26 +08:00
Asias He
5a54ae3214 gossip: Fix string serializer in messaging_service 2015-04-23 14:55:26 +08:00
Asias He
8ea0d94ece message: Listen on single port 2015-04-20 16:11:01 +08:00
Asias He
7fd4c0a402 message: Allow listen on a specific IP address 2015-04-16 14:58:52 +08:00
Asias He
2f56a360e7 message: Introduce messaging_service
It is built on top of seastar rpc infrastructure. I've sorted out all
the message VERBs which Origin use. All of them can be implemented using
this messaging_service.

Each Verb contains a handler. There are two types of handlers, one
will return a message back to sender, the other will not. The former
can be registered using ms.register_handler(), the latter can be
registered using ms.register_handler_oneway().

Usage example:
To use messaging_service to send a message. All you need is:

messaging_service& ms = get_local_messaging_service();

1) To register a message hander:
   ms.register_handler(messaging_verb::ECHO, [] (int x, long y) {
       print("Server got echo msg = (%d, %ld) \n", x, y);
       std::tuple<int, long> ret(x*x, y*y);
       return make_ready_future<decltype(ret)>(std::move(ret));
   });

   ms.register_handler_oneway(messaging_verb::GOSSIP_SHUTDOWN, [] (empty_msg msg) {
       print("Server got shutdown msg = %s\n", msg);
       return messaging_service::no_wait();
   });

2) To send a message:
    using RetMsg = std::tuple<int, long>;
    return ms.send_message<RetMsg>(messaging_verb::ECHO, id, msg1, msg2).then([] (RetMsg msg) {
        print("Client sent echo got reply = (%d , %ld)\n", std::get<0>(msg), std::get<1>(msg));
        return sleep(100ms).then([]{
            return make_ready_future<>();
        });
    });

    return ms.send_message_oneway<void>(messaging_verb::GOSSIP_SHUTDOWN, std::move(id), std::move(msg)).then([] () {
        print("Client sent gossip_shutdown got reply = void\n");
        return make_ready_future<>();
    });

Tests:
   send to cpu 0
   $ ./message --server 127.0.0.1  --cpuid 0  --smp 2
   send to cpu 1
   $ ./message --server 127.0.0.1  --cpuid 1  --smp 2
2015-04-09 10:54:17 +08:00