Skip to content

Enable the device server push events manually #140

@kmadisa

Description

@kmadisa

Problem Description

At the moment the generated device server requires that polling be set for attribute(s) so that the client(s) can be able to subscribe to the attribute events. Depending on how many attributes the device might have, this might also degrade the performance of the server.
One proposed solution to this would be to have the device server push events to clients, which is more efficient than polling.

Two possible solutions (there can be more) are proposed:

Solution 1. Specify the flag(s) as part of the attribute configuration

In this scenario we add a property/properties in each attribute configuration to flag whether we want the device server to push either change/archive event for each individual attribute. The nice thing about this approach is that we can set it up for a specific attribute.
The proper place for this would be to use the SimDD.json configuration file to add this extra properties. This means we might also have to update the parser, but it shouldn't be difficult, and then when initialising the device, we would get these properties from the model and configure it accordingly.

Code snippet: tango_sim_generator.py

def initialize_dynamic_attributes(self):
    model_sim_quants = self.model.sim_quantities
    attribute_list = set([attr for attr in model_sim_quants.keys()])
    for attribute_name in attribute_list:
        meta_data = model_sim_quants[attribute_name].meta
        # Dynamically add all attributes except those with DevEnum data type,
        # and SPECTRUM data format since they are added statically to the device
        # class prior to start-up. Also exclude attributes with a data format
        # 'IMAGE' as we currently do not handle them.
        if not self._is_attribute_addable_dynamically(meta_data):
            if model_sim_quantities[attribute_name].meta['push_change_event']:
                self.set_change_event(attribute_name, True, True)

            if model_sim_quantities[attribute_name].meta['push_archive_event']:
                self.set_change_event(attribute_name, True, True)

             continue
        ....

        self._add_dynamic_attribute(attr, rw_type)
        MODULE_LOGGER.debug("Added dynamic {} attribute".format(attribute_name))

        if model_sim_quantities[attribute_name].meta['push_change_event']:
            self.set_change_event(attribute_name, True, True)

        if model_sim_quantities[attribute_name].meta['push_archive_event']:
            self.set_change_event(attribute_name, True, True)

Solution 2. Pass the flags as command line arguments

In this scenario, we pass a flag(s) in the terminal to signal whether to manually push events or not. With this approach, there won't be an easier way to specify as to for which attribute we want the event to be pushed for. We will have to just push for all attributes.

Code snippet: bash

$ tango-simlib-generator --sim-data-file <xmi/fgo/json>\
                         --dserver-name <server-name>\
                         --directory <output filepath>\
                         --push-change-events <True/False>\
                         --push-archive-events <True/False>

Code snippet: tango_sim_generator.py

....

def generate_device_server(
    server_name,
    sim_data_files,
    directory="",
    push_change_events=False,
    push_archive_events=False
):
....
    lines = [
        ....
        "    TangoDeviceServers = get_tango_device_server("
        "        models,"
        "        sim_data_files,"
        "        push_change_events={},".format(push_change_events)
        "        push_archive_events={}".format(push_archive_events)
        "     )"
....

def get_tango_device_server(
    models,
    sim_data_files,
    push_change_events=False,
    push_archive_events=False
):
....

def initialize_dynamic_attributes(self):
    model_sim_quants = self.model.sim_quantities
    attribute_list = set([attr for attr in model_sim_quants.keys()])
    for attribute_name in attribute_list:
        meta_data = model_sim_quants[attribute_name].meta
        # Dynamically add all attributes except those with DevEnum data type,
        # and SPECTRUM data format since they are added statically to the device
        # class prior to start-up. Also exclude attributes with a data format
        # 'IMAGE' as we currently do not handle them.
        if not self._is_attribute_addable_dynamically(meta_data):
            if push_archive_events:
                self.set_archive_event(attribute_name, True, True)

            if push_change_events:
                self.set_change_event(attribute_name, True, True)

             continue
        ....

        self._add_dynamic_attribute(attr, rw_type)
        MODULE_LOGGER.debug("Added dynamic {} attribute".format(attribute_name))

        if push_archive_events:
            self.set_archive_event(attribute_name, True, True)

        if push_change_event:
            self.set_change_event(attribute_name, True, True)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions