Request-Reply Communication

Overview

The Request/Reply communication pattern consists of two roles:

Server (or LocalServer), local server participant

This class is instantiated in the service-providing RSB process. Provided methods are registered by name and signature.

RemoteServer, remote server participant

This class is instantiated in the service-using RSB process. Each RemoteServer instance has one or more corresponding Server instances, potentially in different processes, that provide the service in question. Client code calls methods on the RemoteServer instance which cause methods of a Service instance to be called and perform the requested task.

For example:

digraph rpc_example {
fontname=Arial
fontsize=11
node [fontsize=11,fontname=Arial]
edge [fontsize=11,fontname=Arial]

subgraph cluster_process1 {
  label="process 1";
  "remoteserver" [shape=rectangle];
}
subgraph cluster_process2 {
  label="process 2";
  "server" [shape=rectangle];
}

"remoteserver" -> "server" [label="request: call method foo"];
"server" -> "remoteserver" [label="reply: for foo call"];
}

Important

If a single service is provided by more than one server, requests will be processed in all servers, but the client will only receive one, arbitrarily selected, reply.

Conversely, if service is not provided by any server, the request part of method calls is performed, but a reply is never received. This situation is indistinguishable from a server which takes an infinitely long time to process request and can therefore not be detected by the caller. However, timeouts can be used handle absent and slow servers uniformly.

Server

Conceptually, the Server instance is the root of the following object tree:

  • Server
    • Scope: SERVER-SCOPE
    • Method
      • Name: METHOD-NAME
      • Scope SERVER-SCOPE/METHOD-NAME/
      • Request listener
        • Scope: SERVER-SCOPE/METHOD-NAME/
        • Handler: passes received events to client code for processing
      • Reply informer
        • Scope: SERVER-SCOPE/METHOD-NAME/
    • more methods

RemoteServer

Conceptually, the RemoteServer instance is the root of the following object tree:

  • RemoteServer
    • Scope: SERVER-SCOPE
    • Method
      • Name: METHOD-NAME
      • Scope SERVER-SCOPE/METHOD-NAME/
      • Request informer
        • Scope: SERVER-SCOPE/METHOD-NAME/
      • Reply listener
        • Scope: SERVER-SCOPE/METHOD-NAME/
        • Handler: processes received replies to ultimately return a result to the client code which initiated the call
      • A collection of in-progress method calls
    • more methods

Protocol

  1. Client code calls a method on a RemoteServer instance
  2. The request informer of the method publishes a request event containing
  3. A record containing the event id of the request event is created for the method call
  4. The call blocks until a reply event is received (see below)
  5. The request listener of the method in a corresponding Server instance receives the event
  6. The request event is dispatched to a handler for processing
  7. After processing, the reply informer of the method in the Server sends a reply event containing
    • The result of the processing as payload, if the processing succeeded without errors
    • The textual description of the error as payload, if an error occurred
    • A user-info item with key rsb:error? and an arbitrary value, if an error occurred
    • The value "REPLY" in its method field
    • The event id of the request event in its causal vector
  8. The reply listener of the method in the RemoteServer receives the reply event
  9. The call record is located using the event id stored in the causal vector of the reply event
  10. The blocking call is notified and
    • returns the payload of the reply event, if a user-item with key rsb:error? is not present in the event
    • signals an error, if a user-item with key rsb:error? is present in the event

Examples

TODO: include examples or link to tutorial?

Implementations

Language File(s)
C++ “0.14” branch of https://code.cor-lab.org/git/rsb.git.cpp at src/rsb/patterns/
Java “0.14” branch of https://code.cor-lab.org/git/rsb.git.java at src/rsb/patterns/
Python “0.14” branch of https://code.cor-lab.org/git/rsb.git.python at rsb/patterns/
Common Lisp “0.14” branch of https://code.cor-lab.org/git/rsb.git.cl at src/patterns/request-reply