clojang.rpc

The clojang.rpc namespace has no analong in the JInterface package. This namepsace intends to provide a similar interface as that provided by the clojang.conn namespace: a set of functions for sending and receiving messages to and from remote processes. In this case, however, there is a very specfic client we expect to be receiving requests from and replying to: an RPC client, and one that expects this namespace to provide functions compatible with the RPC capabilities of an Erlang/OTP gen_server.

!

->map

(->map otp-msg)

Convert the JInterface OtpMsg to a Clojure map, parsing any RPC data that may be included in the message.

deliver

(deliver this msg-or-exception)

Deliver messages or communication exceptions to the recipient.

exit

(exit dest-pid reason)

An alias for jiface.otp.connection/exit that automatically converts the reason argument to an appropriate Erlang type.

get-msg-count

(get-msg-count this)

Return the number of messages currently waiting in the receive queue for this connection.

get-peer

(get-peer this)

Get information about the node at the peer end of this connection.

get-self

(get-self this)

Get information about the node at the local end of this connection.

msg->rpc-data

(msg->rpc-data msg-data)

Convert RPC message data to a Clojure map, if the message contains RPC data. If not, set the :rpc-data value to nil.

parse-rpc

(parse-rpc [gen-call-type [calling-pid calling-ref] [call-type module function arguments group-leader]])

Parse the message data in an RPC message.

receive

(receive & args)

This function is called by the RPC server in anticipation of a message from an Erlang RPC client. As such, it parses the OtpMsg for RPC content, identifies the function to call on behalf of the client, makes this call (using eval), and then sends the result to the calling OtpPid (being that of the client).

Note that in order for an Erlang RPC client to accept a message from an RPC server, the message sent by the server has to conform to a very specific format, a format that is not speficied anywhere except the OTP gen_server code. As such, this Clojure function sends a reply to the client using this format. Since the format is only specificed in OTP source code, it may change in the future, in which case this function will need to be updated.

The request sent by the RPC client boils down to the following chain of calls (some have been elided): * rpc:do_call/3 * gen_server:call/3 * gen:do_call/4

The response that the RPC client is expected is created/formated in the following functions, and these are what govern how this particular Clojure function sends its results back to the RPC client, especially the reply/2 function: * gen_server:handle_msg/* * gen_server:reply/2

In particular, this sending code is what we used: To ! {Tag, Reply} (which, in LFE, would be (! pid `#(,tag ,reply))).

receive-buf

(receive-buf this)(receive-buf this timeout)

Receive a raw (still encoded) message from a remote process.

receive-msg

(receive-msg connx)(receive-msg connx timeout)

An alias for jiface.otp.connection/receive-msg that returns the received data as Clojure data types.

recv

rpc?

(rpc? msg-data)

send

(send connx dest msg)

An alias for jiface.otp.connection/send that also allows for mailbox and node name arguments to be symbols, keywords, or strings.

send-buf

(send-buf this desg msg)

Send a pre-encoded message to a process on a remote node.

snd