interface.rst 3.8 KB

  1. Interface description
  2. =====================
  3. All Modelverse components communicate with each other through the use of sockets.
  4. On these sockets, XML/HTTP Requests are used for communication.
  5. In this brief section, we describe the form of these requests.
  6. MvS server
  7. ----------
  8. The MvS server listens to a fixed set of commands.
  9. All commands have a fully defined signature and result.
  10. Note that commands are encoded: a decoding table is presented below.
  11. ==== ======================
  12. Code Description
  13. ==== ======================
  14. CN create_node
  15. CE create_edge
  16. CNV create_nodevalue
  17. CD create_dict
  18. RV read_value
  19. RO read_outgoing
  20. RI read_incoming
  21. RE read_edge
  22. RD read_dict
  23. RDN read_dict_node
  24. RDNE read_dict_node_edge
  25. RDE read_dict_edge
  26. RRD read_reverse_dict
  27. RR read_root
  28. RDK read_dict_keys
  29. DE delete_edge
  30. DN delete_node
  31. ==== ======================
  32. Requests are sent as POST requests (*i.e.*, in the data of a HTTP request).
  33. They have the following form::
  34. op=CODE&params=PARAMS
  35. In this case, *CODE* is one of the codes mentioned above, and the value of *PARAMS* is a JSON encoded list of Modelverse identifiers.
  36. The choice of what is a Modelverse identifier is left to the MvS itself.
  37. The result will be a JSON serialized list containing as first element the response to the request, and as second element the statuscode.
  38. If the statuscode is 200, the first element will be correct.
  39. Otherwise, the statuscode indicates the error, and the first element is set to *null*.
  40. MvK server
  41. ----------
  42. The communication with the MvK is a lot easier, as there is only a very minimal interface: the actual interface needs to be explicitly modelled in action language.
  43. Requests have the following form::
  44. op=OPERATION&taskname=TASKNAME&value=VALUE
  45. Here, *OPERATION* defines the operation to execute, of which only two exist:
  46. 1. *set_input*, which adds the sent value to the input queue of the user;
  47. 2. *get_output*, which blocks until there is a value in the output queue of the user.
  48. Obviously, *TASKNAME* specifies the name of the task for which the operation needs to happen.
  49. The *VALUE* is just a JSON encoded value which will be added to the input queue of the Modelverse.
  50. This is ignored when the *get_output* operation is used.
  51. Note that there are some minor differences between our encoding and JSON encoding.
  52. The supported types are shown below.
  53. ======= ===================
  54. Type Example
  55. ======= ===================
  56. Integer 1
  57. Float 1.0
  58. Boolean true
  59. String "abc"
  60. Action if
  61. ======= ===================
  62. While this list mostly resembles JSON, there are some important differences:
  63. * Lists and objects are not supported;
  64. * Null object is not supported;
  65. * Action type is new, and contains a string representation (without quotes!) of the action language construct to add
  66. As response, the *set_input* will always receive the same reply if the message was correctly deserialized.
  67. Receiving a reply does *NOT* mean that a message was consumed by the task, it only means that the message was correctly added to the input queue of that task.
  68. A *get_output* request blocks until a value is available in the tasks output queue.
  69. The reply to this message will then contain a JSON serialized (with identical remarks as for *set_input*) containing the value that was output.
  70. Note that now the *null* message is possible, in case the node that is being outputted does not contain a value (or is an edge).
  71. Performance notes
  72. ^^^^^^^^^^^^^^^^^
  73. For performance reasons, sending a huge amount of data to the Modelverse (*e.g.*, a compiled program), should not happen with individual requests for each line.
  74. To allow for packed messages, tasks can ignore the *value* parameter, and use the *data* parameter instead.
  75. The content of this parameter should be a JSON encoded list of all individual values to be inserted.