Technical components

Version 4 (Paul Carensac, 04/20/2016 10:45 am)

1 1 Paul Carensac
h1. Technical components
2 2 Paul Carensac
3 4 Paul Carensac
Explanations on the technical components of the project : the ones we have created (internal), and the imported ones (external).
4 2 Paul Carensac
5 2 Paul Carensac
---
6 2 Paul Carensac
7 2 Paul Carensac
h2. %{margin-left:0px; font-weight:bold; font-size:25px;  display:block; color:red;}Internal components%
8 2 Paul Carensac
9 2 Paul Carensac
h3. Agent
10 1 Paul Carensac
11 4 Paul Carensac
The Agent class is in the common.agent.py file.
12 4 Paul Carensac
13 4 Paul Carensac
 * *I - Purpose*
14 4 Paul Carensac
15 4 Paul Carensac
    * Generically handles and creates the asynchronous modules
16 4 Paul Carensac
    * Uses the threading library (see below in External components) to make all modules independent
17 4 Paul Carensac
    * Provides an abstract class to be inherited
18 4 Paul Carensac
19 4 Paul Carensac
 * *II - Features*
20 4 Paul Carensac
21 4 Paul Carensac
    * Uses a config file (pyros_agent_config.ini) to set the network communication interface of all agents
22 4 Paul Carensac
    * Provides a 'work' method to override : this is the entry method of the newly created thread (see 'How to use it' section below)
23 4 Paul Carensac
    * Provides the 'receive' and 'analyze_message' methods to generically receive messages from network and analyze them 
24 4 Paul Carensac
25 4 Paul Carensac
 * *III - How to use it ?*
26 4 Paul Carensac
27 4 Paul Carensac
    Each of these points are +NECESSARY+
28 4 Paul Carensac
29 4 Paul Carensac
    * Create a new class that inherits from Agent
30 4 Paul Carensac
    * In the __init__ method, first call the __init__ method of Agent, passing the name of the agent as second parameter (they are defined in the Agent class, eg: Agent.SCHEDULER)
31 4 Paul Carensac
    * Inside the class, define the messages your agent can receive (eg: MSG_OBS_FINISHED = "Observation finished")
32 4 Paul Carensac
    * Create a method to be called for every message you created
33 4 Paul Carensac
    * In the __init__, after calling the Agent's __init__, associate each message to its associated function in the 'self.actions_by_message' dictionary (eg: self.actions_by_message[self.MSG_OBS_FINISHED] = self.observation_finished)
34 4 Paul Carensac
    * Override the method work : this will be the entry function of the new thread, so do whatever you need. This MUST NOT be an infinite loop, because Agent's receive method will be called after this one
35 4 Paul Carensac
    * If ever needed, override the 'shutdown' method, it will be called when your agent receive the Agent.SHUTDOWN message (eg: if you created another thread in the 'work' method, you need to close it)
36 4 Paul Carensac
37 4 Paul Carensac
    The main points to understand are that you can do whatever you want (but non-blocking) in work method (like creating new threads or variables' initialization), then the only entry points are the message-associated methods 
38 4 Paul Carensac
39 2 Paul Carensac
h3. Sender
40 1 Paul Carensac
41 4 Paul Carensac
The Sender class is in the common.sender.py file
42 4 Paul Carensac
43 4 Paul Carensac
 * *I - Purpose*
44 4 Paul Carensac
45 4 Paul Carensac
    * Send a given message to an agent
46 4 Paul Carensac
47 4 Paul Carensac
 * *II - Features*
48 4 Paul Carensac
49 4 Paul Carensac
    * Uses the 'pyros_agent_config.ini' file to get the agents' network interface configuration (ip and port)
50 4 Paul Carensac
    * Provide a 'send_to' static method to send the messages
51 4 Paul Carensac
52 4 Paul Carensac
 * *III - How to use it ?*
53 4 Paul Carensac
54 4 Paul Carensac
    * The targeted agent must be described in 'pyros_agent_config.ini'
55 4 Paul Carensac
    * Use Sender.send_to method, giving as first parameter the name of the targeted agent (eg: Agent.SCHEDULER), and as second parameter the message (eg: Agent.SHUTDOWN)
56 4 Paul Carensac
    * /!\ send_to is a static method, you don't need to instantiate a Sender (just do Sender.send_to(...))
57 2 Paul Carensac
---
58 2 Paul Carensac
59 2 Paul Carensac
h2. %{margin-left:0px; font-weight:bold; font-size:25px;  display:block; color:red;}External components%
60 2 Paul Carensac
61 2 Paul Carensac
h3. Threading library
62 2 Paul Carensac
63 2 Paul Carensac
h3. Socket library
64 2 Paul Carensac
65 2 Paul Carensac
---