blob: a572390ddaf1790fe9c550a0164524ac442c04fd [file] [log] [blame]
Tommy Carpenter53786ca2020-02-28 09:17:46 -05001.. This work is licensed under a Creative Commons Attribution 4.0 International License.
2.. SPDX-License-Identifier: CC-BY-4.0
3.. Copyright (C) 2020 AT&T Intellectual Property
4
5xapp-frame-py Overview
6======================
7
8This library is a framework for writing Xapps in python.
9There may or may not be many Xapps written in python; however rmr, sdl, and logging libraries all exist for python, and this framework brings them together.
10
Tommy Carpenter99a0b482020-03-03 10:21:24 -050011There are (at the time of writing) two "kinds" of Xapps one can instantiate with this framework that model "push" (RMR Xapps) and "pull" (General Xapps), as described below.
Tommy Carpenter53786ca2020-02-28 09:17:46 -050012
13RMR Xapps
14---------
15This class of Xapps are purely reactive to rmr; data is always "pushed" to it via rmr.
16That is, every time the Xapp receives an rmr message, they do something, then wait for the next message to arrive, end never need to execute functionality at another time (if they do, use the next class).
Tommy Carpenterf9cd5cc2020-03-09 13:46:37 -040017This is represented by a series of callbacks that get registered to receive rmr message types.
18Every time an rmr message arrives, the user callback for that message type is invoked, or if the user has not registered a callback for that type, their default callback (mandatory) is invoked.
Tommy Carpenter53786ca2020-02-28 09:17:46 -050019An analogy of this is AWS Lambda: "execute this code every time an event comes in" (the code to execute can depend on the type of event).
20
Tommy Carpenter99a0b482020-03-03 10:21:24 -050021General Xapps
22-------------
Tommy Carpenter53786ca2020-02-28 09:17:46 -050023In this class of Xapp the user simply provides a function that gets invoked, and typically that function has a `while (something)` in it.
24If the function returns, the Xapp will stop.
25In this type of Xapp, the Xapp must "pull" it's own data, typically from SDL, rmr (ie query another component for data), or other sources.
26The framework is "lighter" in this case then the former; it sets up an SDL connection, an rmr thread, and then calls the client provided function.
27This is to be used for Xapps that are not purely event driven.
28
29RMR Threading in the framework
30------------------------------
31NOTE: this is an implementation detail!
32We expose this for transparency but most users will not have to worry about this.
33
34In both types of Xapp, the framework launches a seperate thread whose only job is to read from rmr and deposit all messages (and their summaries) into a thread safe queue.
Tommy Carpenter99a0b482020-03-03 10:21:24 -050035When the client Xapp reads using the framework (this read is done by the framework itself in the RMR Xapp, but by the client in a general Xapp), the read is done from the queue.
Tommy Carpenter53786ca2020-02-28 09:17:46 -050036The framework is implemented this way so that a long running client function (e.g., consume) cannot block rmr reads.
37This is important because rmr is *not* a persistent message bus, if any rmr client does not read "fast enough", messages can be lost.
38So in this framework the client code is not in the same thread as the rmr reads, so that long running client code can never lead to lost messages.
39
Tommy Carpenter1c9ce6b2020-03-13 09:36:36 -040040In the case of RMR Xapps, there are currently 3 potential threads; the thread that reads from rmr directly, and the user can optionally have the rmr queue read run in a thread, returning execution back to the user thread.
41The default is only two threads however, where `.run` does not return back execution and the user code is "finished" at that point.
42
Tommy Carpenter09894e32020-04-02 19:45:19 -040043Healthchecks
44------------
45RMRXapps come with a default rmr healthcheck probe handler.
46When the RMRXapp is sent an rmr healthcheck, it will check to see if the rmr thread is healthy (well it can't even reply if it's not!), and that the SDL connection is healthy.
47The Xapp responds accordingly.
48The user can override this default handler by registering a new callback to the appropriate message type.
49
50General Xapps must handle healthchecks when they read their rmr mailbox, since there is no notion of handlers.
51
52There is no http service (Currently) in the framework therefore there are no http healthchecks.
Tommy Carpenterf9cd5cc2020-03-09 13:46:37 -040053
Tommy Carpenter53786ca2020-02-28 09:17:46 -050054Examples
55--------
Tommy Carpenter99a0b482020-03-03 10:21:24 -050056There are two examples in the `examples` directory; `ping` which is a general Xapp, and `pong` which is an RMR Xapp.
57Ping sends a message, pong receives the message and use rts to reply.
58Ping then reads it's own mailbox and demonstrates other functionality.
59The highlight to note is that `pong` is purely reactive, it only does anything when a message is received.
60Ping uses a general that also happens to read it's rmr mailbox inside.