pymasep.application.sub_app =========================== .. py:module:: pymasep.application.sub_app Classes ------- .. autoapisummary:: pymasep.application.sub_app.SubApp Module Contents --------------- .. py:class:: SubApp(app, received_q_id, cfg) Bases: :py:obj:`threading.Thread` Part of the application as a Thread. Usually a sub application is the engine or the interface. :param App app: main application :param received_q_id: id of the queue used by the sub app to receive messages. :param cfg: configuration of the sub application .. py:attribute:: id :type: str id of the sub application .. py:attribute:: config configuration of the sub application .. py:attribute:: app main application pointer .. py:attribute:: messages_received_q_id id of the queue used to receive messages .. py:attribute:: messages_received :type: queue.Queue queue used to receive messages .. py:attribute:: connected_sub_app dict of sub applications information connected to this sub application .. py:attribute:: current_event :type: Optional[pymasep.communication.message.Message] :value: None Last message received by the sub application .. py:attribute:: app_states possible states of the sub application .. py:attribute:: current_app_states :type: List[pymasep.application.sub_app_state.SubAppState] :value: [] Stack of the current state of the sub application .. py:attribute:: logger :type: logging.Logger logger for the sub application .. py:attribute:: environment :type: Optional[pymasep.common.environment.Environment] :value: None environment used to run the sub application .. py:attribute:: remote_communication :type: Optional[pymasep.communication.base_threaded_communication.BaseThreadedCommunication] :value: None the remote communication of the sub application as a BaseThreadedCommunication (Client or Server) .. py:method:: __del__() Delete the instance. Close the logger .. py:method:: register_connected_sub_app(sub_app_id, role, sent_q = None) Register a sub application connected to self with a rale, and optionally a queue (if it's the same process). :param sub_app_id: Connected sub app id :param role: role of the connected sub app. See ConnectedSubAppInfo. :param sent_q: Queue of the connected sub app used to send messages (for sub apps in the same process) .. py:method:: get_connected_id_from_agent_fname(agent_fname) get the connected sub app that handles an agent :param agent_fname: the agent full name (ex. state.agent_name) :return: the id of the sub app associated to the agent .. py:method:: send_message(message, subapp_id) Send messages to a sub app from its id. Send by queue or by socket according to the connection between the tow sub app :param message: Message to send :param subapp_id: destination sub app id .. py:method:: send_message_to_queue(message, q) :staticmethod: Send a message to a queue. The message is put in the queue as byte :param message the message to send :param q the queue .. py:method:: wait_message(wanted_messages, block = True, most_recent = False, keep_all = None) Wait for a message of certain types. The wait can be blocked or not. The received message is put in self.current_event :param wanted_messages: List of wanted messages types. :param block: True if the method blocks until a message arrives :param most_recent: True makes the function to get the most recent message in the queue and empty the queue :param keep_all: List of message types that will not be skipped when most_recent is True. All messages after the message with type in keep_all, are kept in the queue. :return: The received message .. py:method:: get_current_app_state() Get the current sub app state :return: The current sub app state as SubAppState .. py:method:: push_state(sbapp_state) Push a new state in the head state. Pause the current state and init the new one. :param sbapp_state: New state to push .. py:method:: set_state(sbapp_state) Set a new state. Remove the ald current and push the new one. :param sbapp_state: New state to set .. py:method:: pop_state() Clean and remove the current state