def __init__(self, aml_topic: AmlTopic, aml_participant: AmlParticipant, publisher_qos=fastdds.PublisherQos(), datawriter_qos=None): """ Create an AmlWriter entity. It creates a DDS Publisher and inside a DDS DataWriter. """ logger.construct( f'Creating AmlWriter {aml_topic.name()}, {aml_topic.type_name()}.') if datawriter_qos is None: datawriter_qos = AmlWriter.default_datawriter_qos() # Topic self.aml_topic_ = aml_topic # Create Publisher self.publisher_ = aml_participant.get_dds_participant( ).create_publisher(publisher_qos) # Create DataWriter self.writer_ = self.publisher_.create_datawriter( aml_topic.dds_topic(), datawriter_qos, None) # Wait for a minimum time so the entity is created and discovered sleep(0.2)
def __del__(self): """TODO comment.""" logger.construct(f'Destroying ComputingNode {self.name_}.') self.stop() if self.store_in_file_: self._save_jobs_in_file()
def __del__(self): """ Destroy Entity. So far, every entity is destroyed by itself. """ logger.construct(f'Destroying AmlDdsNode {self.name_}.') self._publish_status_data(alive=False)
def __del__(self): """Destroy Participant entities and destroy participant in factory.""" logger.construct(f'Destroying AmlParticipant {self.name_}.') # Destroy alive entities self.participant_.delete_contained_entities() # Destroy participant fastdds.DomainParticipantFactory.get_instance().delete_participant( self.participant_)
def __init__(self, name, inference_process_callback=None, domain=0): """Construct MainNodeParticipant object.""" super().__init__(name, domain) logger.construct(f'Constructing AmlDdsMainNode {name}') # Internal values self.inference_server_ = None self.job_client_ = None self.inference_process_callback_ = inference_process_callback # Async threads self.async_job_requests_ = {}
def __init__(self, node_id: AmlNodeId, service_name: str, aml_participant: AmlParticipant, aml_writer_request_availability_topic: AmlTopic, aml_reader_reply_available_topic: AmlTopic, aml_writer_task_target_topic: AmlTopic, aml_writer_task_topic: AmlTopic, aml_reader_solution_topic: AmlTopic): """ Create a AmlMultiserviceClient entity. Create a Client entity with every DDS subentity required. """ logger.construct(f'Creating AmlMultiserviceClient {service_name}.') # Internal elements self.node_id_ = node_id self.name_ = service_name self.request_number_ = 0 self.stop_ = False self.task_id_ = 0 # This list collects all task that servers has set as available to self.request_already_available_ = {} self.solution_already_available_ = {} # Mutex to avoid simultaneous threads accessing the readers at the same time self.reader_reply_available_mutex_ = threading.Lock() self.reader_solution_mutex_ = threading.Lock() # Create request availability Writer self.aml_writer_request_availability_ = AmlWriter( aml_topic=aml_writer_request_availability_topic, aml_participant=aml_participant) # Create reply available Reader self.aml_reader_reply_available_ = AmlReader( aml_topic=aml_reader_reply_available_topic, aml_participant=aml_participant) # Create task target Writer self.aml_writer_task_target_ = AmlWriter( aml_topic=aml_writer_task_target_topic, aml_participant=aml_participant) # Create task Writer self.aml_writer_task_ = AmlWriter(aml_topic=aml_writer_task_topic, aml_participant=aml_participant) # Create solution Reader self.aml_reader_solution_ = AmlReader( aml_topic=aml_reader_solution_topic, aml_participant=aml_participant)
def __init__(self, node_id: AmlNodeId, service_name: str, aml_participant: AmlParticipant, aml_reader_request_availability_topic: AmlTopic, aml_writer_reply_available_topic: AmlTopic, aml_reader_task_target_topic: AmlTopic, aml_reader_task_topic: AmlTopic, aml_writer_solution_topic: AmlTopic, callback=None): """ Create a AmlMultiserviceServer entity. :param callback: routine that will be called when processing a request. If callback is None, it will require to specify the callback when calling process request. """ logger.construct(f'Creating AmlMultiserviceServer {service_name}.') # Internal elements self.node_id_ = node_id self.name_ = service_name self.callback_ = callback # This list collects all task that clients has already set as chosen # so this server does not try to use them self.tasks_already_taken_ = [] # Create request availability Reader self.aml_reader_request_availability_ = AmlReader( aml_topic=aml_reader_request_availability_topic, aml_participant=aml_participant) # Create reply available Writer self.aml_writer_reply_available_ = AmlWriter( aml_topic=aml_writer_reply_available_topic, aml_participant=aml_participant) # Create request task target Reader self.aml_reader_task_target_ = AmlReader( aml_topic=aml_reader_task_target_topic, aml_participant=aml_participant) # Create request task Reader self.aml_reader_task_ = AmlReader(aml_topic=aml_reader_task_topic, aml_participant=aml_participant) # Create reply solution Writer self.aml_writer_solution_ = AmlWriter( aml_topic=aml_writer_solution_topic, aml_participant=aml_participant)
def __init__( self, topic_name, alm_participant: AmlParticipant, aml_topic_data_type: AmlTopicDataType, topic_qos=fastdds.TopicQos()): """Create new AmlTopic by a Participant and a TopicDataType.""" logger.construct(f'Creating AmlTopic {topic_name}.') self.topic_name_ = topic_name self.aml_topic_data_type_ = aml_topic_data_type # Create Topic self.dds_topic_ = alm_participant.get_dds_participant().create_topic( self.name(), self.aml_topic_data_type_.name(), topic_qos)
def stop(self): """ Stop this node. Stop its internal DDS entities. Set variable stop as true. Awake threads waiting for stop. """ logger.construct(f'Stopping ComputingNode {self.name_}.') # Stop DDS module self.dds_computing_node_.stop() # Set entity as stopped self.cv_stop_.acquire() self.stop_ = True self.cv_stop_.notify_all() self.cv_stop_.release()
def __init__(self, name, domain=0, participant_qos=fastdds.DomainParticipantQos()): """ Create a AmlParticipant entity. Create every internal variable for class I_AmlNodeParticipant. """ logger.construct(f'Creating AmlParticipant {name}.') # Participant internal values self.name_ = name # Get Participant QoS factory = fastdds.DomainParticipantFactory.get_instance() participant_qos.name = name # TODO Check it is working # Construct participant self.participant_ = factory.create_participant(domain, participant_qos)
def __init__(self, name, domain=0, store_in_file=True): """Create a default ComputingNode.""" logger.construct(f'Creating ComputingNode {name}.') # Internal variables self.name_ = name self.time_range_ms_ = (2000, 7000) self.store_in_file_ = store_in_file self.jobs_processed_ = [] # DDS variables self.dds_computing_node_ = AmlDdsComputingNode( name=name, job_process_callback=self._job_process_callback_dds_type, domain=domain) self.dds_computing_node_.init() # Stop variables self.stop_ = False self.cv_stop_ = Condition()
def __init__( self, name, domain=0): """Construct AmlNode and instantiate every internal variable.""" logger.construct(f'Constructing AmlDdsNode {name}') # Participant Id self.id_ = AmlNodeId() # Internal variables self.name_ = name self.domain_ = domain self.enabled_ = False # DDS variables self.participant_ = None self.topic_handler_ = TopicHandler() self.status_writer_ = None logger.debug(f'Created AmlDdsNode {name} with id {self.id_}.')
def __init__( self, aml_topic: AmlTopic, aml_participant: AmlParticipant, subscriber_qos=fastdds.SubscriberQos(), datareader_qos=None): """ Create an AmlReader entity. It creates a DDS Subscriber and inside a DDS DataReader. """ super().__init__() if datareader_qos is None: datareader_qos = AmlReader.default_datareader_qos() logger.construct(f'Creating AmlReader {aml_topic.name()}, {aml_topic.type_name()}.') # Topic self.aml_topic_ = aml_topic # Listener self.msgs_to_read_ = [] # Wait Condition self.cv_wait_data_ = Condition() self.stop_ = False # Create Subscriber self.subscriber_ = aml_participant.get_dds_participant().create_subscriber( subscriber_qos) # Create DataReader self.reader_ = self.subscriber_.create_datareader( aml_topic.dds_topic(), datareader_qos, self) # Wait for a minimum time so the entity is created and discovered sleep(0.2)
def __init__(self, aml_participant: AmlParticipant, topic_data_type_name, topic_data_type_pubsub_constructor, topic_data_type_constructor): """ Create new AmlTopicDataType. Registers the new DatType into the Participant. :param topic_data_type_pubsub_constructor: constructor function of the class PubSubType of this data type. :param topic_data_type_constructor: constructor function of the class of this data type. """ logger.construct(f'Creating AmlTopicDataType {topic_data_type_name}.') self.name_ = topic_data_type_name # self.topic_data_type_pubsub_constructor_ = topic_data_type_pubsub_constructor self.topic_data_type_constructor_ = topic_data_type_constructor # Register data topic_data_type_pubsub_object = topic_data_type_pubsub_constructor() topic_data_type_pubsub_object.setName(self.name()) type_support = fastdds.TypeSupport(topic_data_type_pubsub_object) aml_participant.get_dds_participant().register_type(type_support)
def __del__(self): """Stop entity and destroy it.""" logger.construct(f'Deleting AmlMultiserviceClient {self.name_}.') self.stop()