Skip to content

HTTP Request Processing

Alessandro Pagiaro edited this page Jan 18, 2019 · 1 revision

In order to synchronize the internal simulation clock to the user script, the tool manages the HTTP request by using a queue.

Every request from the user script is managed by the web server (Flask with flask_restful).

In order to explain the design used to queue the request, an example is performed. Let suppose a client have to add a device. Looking at the file __main__.py it is possible to see that the class Devices is invoked (see flask_restful's docs for more details). Then, the class Devices simply reads all the arguments comes from the HTTP request and then create a task in the queue. The task is modelled as a tuple composed in this way:

(("className", "functionName"), *args, **kwargs)

Added the tuple in the queue, the task waits for the result. As soon as the result arrives, it returns to the user.

The task is executed by the Simulation Core Thread. It executes, if present, one task at every simulation run. In order to execute a task, the Simulation Core Thread invokes the Queue.execute_next_task() that pop a task and then, using Python reflection, it gets the module called className from the API_executor and executes the corresponding function, according to the task description, passing it all the arguments present in the tuple.

Clone this wiki locally