• fastdds之domain


    Domain可以认为是一个虚拟的网络用于运行所有在同一个domain中和隔离不同domain的APP。
    每个domain有一个唯一的uint32的domainId。当一个app需要加入domain时就需要使用这个domainId创建一个DomainParticipant,DomainParticipant的创建使用DomainParticipantFactory这个单例。
    在这里插入图片描述
    使用DomainParticipant的GuidPrefix_t来区分是否在同一主机运行。同一主机中两个participants的GuidPrefix_t的前四个字节是相同的。可以通过API:is_on_same_host_as() 来检查这一条件。

    DomainParticipant

    每个DomainParticipant只归属于一个Domain,包含所有和domain相关的实体。同时它也是Publisher,Subscriber和Topic的生产工厂。

    创建

    DomainParticipantFactory* factory = DomainParticipantFactory::get_instance();
    participant_ = factory->create_participant(0, pqos); // 第一个参数domainid和第二个参数qos必选,listener和statusmask可选
    if(nullptr == participant_with_default_attributes) {
        // Error
        return;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    基于Profile创建, domainId和profile name是必须的,listener和StatusMask是可选的:

    // First load the XML with the profiles
    DomainParticipantFactory::get_instance()->load_XML_profiles_file("profiles.xml");
    
    // Create a DomainParticipant using a profile and no Listener
    DomainParticipant* participant_with_profile =
            DomainParticipantFactory::get_instance()->create_participant_with_profile(0, "participant_profile");
    if (nullptr == participant_with_profile) {
        return;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    删除:只有当所有属于这个participant的entities(Publisher,Subscriber,Topic)都被删除时可以删除DomainParticipant,否则报错。可以通过 delete_contained_entities()函数删除所有entities。

    if (participant->delete_contained_entities() != ReturnCode_t::RETCODE_OK) {
        // DomainParticipant failed to delete the entities it created.
        return;
    }
    
    // Delete the DomainParticipant
    if (DomainParticipantFactory::get_instance()->delete_participant(participant) != ReturnCode_t::RETCODE_OK) {
        // Error
        return;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    DomainParticipantFactory

    单例类,通过get_instance()获取对象实例,唯一的目的是用于创建和销毁DomainParticipant对象实例;通过DomainParticipantFactoryQos配置Qos,Qos只能通过Domain Participant Factory::set_qos()来设置

    DomainParticipantQos

    DomainParticipant的行为可以通过DomainParticipantQos的Qos值来修改,Qos值可以在创建时设置,也可以后续使用DomainParticipant::set_qos()函数来设置。默认值为PARTICIPANT_QOS_DEFAULT。也可以使用 set_default_participant_qos() 函数设置qos。

    DomainParticipant的Qos有以下内容:
    UserDataQosPolicy user_data()
    EntityFactoryQosPolicy entity_factory()
    ParticipantResourceLimitsQos allocation()
    PropertyPolicyQos properties()
    WireProtocolConfigQos wire_protocol()
    TransportConfigQos transport() and setup_transports()
    FlowControllersQos flow_controllers()
    ThreadSettings builtin_controllers_sender_thread()
    ThreadSettings timed_events_thread()
    ThreadSettings discovery_server_thread()
    ThreadSettings security_log_thread()

    DomainParticipantListener

    DomainPariticipant有一个DomainParticipantListener的抽象类,用户可以继承这个抽象类实现响应函数用于通知DomainParticipant实例状态的改变。DomainParticipantListener继承自TopicListener,PublisherListener和SubscriberListener,因此它可以监听任何实体的事件通知。
    当有事件发生时,总是先通知处理该事件的具体的监听器,因此DomainParticipantListener从其他监听器继承的回调函数只有在没有其他实体能够处理该事件的情况下会被调用(该实体没有附加监听器u后者StatusMask禁用了回调)

    有以下回调函数:

    • on_participant_discovery():服务发现发现participant
    • on_subscriber_discovery():服务发现过程中发现新的Subscriber
    • on_publisher_discovery():服务发现过程中发现新的Publisher
    • on_type_discovery()
    • on_type_dependencies_reply()
    • on_type_information_received()

    Partitions

    todo

  • 相关阅读:
    基础算法之背包
    【ES6知识】Generator 函数 与 yield 关键字
    git提交时会将target也提交
    麦肯锡:中国生成式AI市场现状和未来发展趋势
    Apollo自动驾驶系统概述(文末参与活动赠送百度周边)
    【学习笔记】RabbitMQ-5 消息的可靠性投递 以及示例代码
    Redis应用问题解决(缓存穿透、击穿、雪崩、分布式锁)
    可观测|时序数据降采样在Prometheus实践复盘
    js获取Element元素的常用方法
    Go语言操作grpc详细使用
  • 原文地址:https://blog.csdn.net/u010378559/article/details/132812709