Exemplo n.º 1
0
    def _registration_builder(self, topic, description, publisher=True):
        """Creates a xMsgRegistration object

        Args:
            topic (xMsgTopic): the name of the requester/sender. Required
                according to the xMsg zmq message structure definition
                (topic, sender, data)
            description (String): subscriber description string
            publisher (bool): Is publisher flag, if it is set to True the
                registration object generated corresponds to a publisher,
                otherwise corresponds to a subscriber.
        """
        r_data = xMsgRegistration()
        r_data.name = self.myname
        if description:
            r_data.description = description
        r_data.host = topic.domain()
        r_data.port = xMsgConstants.DEFAULT_PORT
        r_data.domain = topic.domain()
        r_data.subject = topic.subject()
        r_data.type = topic.type()

        if publisher:
            r_data.ownerType = xMsgRegistration.PUBLISHER
        else:
            r_data.ownerType = xMsgRegistration.SUBSCRIBER

        return r_data
Exemplo n.º 2
0
    def build_registration(name, description, domain, subject, xtype,
                           is_publisher):
        """xMsgRegistration builder util

        Args:
            name (String): registration name
            description (String): registration description
            domain (String): registration domain
            subject (String): registration subject
            xtype (String): registration type
            is_publisher (bool): True if registration is for a publisher
                actor otherwise means is a subscriber

        Returns:
            xMsgRegistration: xMsg registration object
        """
        r_data = xMsgRegistration_pb2.xMsgRegistration()
        r_data.name = name
        r_data.description = description
        r_data.host = xMsgUtil.get_local_ip()
        r_data.port = xMsgConstants.DEFAULT_PORT
        r_data.domain = domain
        r_data.subject = subject
        r_data.type = xtype

        if is_publisher:
            r_data.ownerType = xMsgRegistration_pb2.xMsgRegistration.PUBLISHER
        else:
            r_data.ownerType = xMsgRegistration_pb2.xMsgRegistration.SUBSCRIBER

        return r_data
Exemplo n.º 3
0
 def register_data(self, n):
     r_data = xMsgRegistration_pb2.xMsgRegistration()
     r_data.name = "name%s" % n
     r_data.description = "description"
     r_data.host = xMsgUtil.host_to_ip("localhost")
     r_data.port = 8888
     r_data.domain = "domain%s" % n
     r_data.subject = "subject%s" % n
     r_data.type = "xtype%s" % n
     return r_data
def new_registration(topic, name, host):
    reg_info = xMsgRegistration_pb2.xMsgRegistration()
    reg_info.domain = topic.domain()
    reg_info.subject = topic.subject()
    reg_info.type = topic.type()
    reg_info.name = name
    reg_info.description = "some test description..."
    reg_info.host = host
    reg_info.port = 8000
    return reg_info
    def setUp(self):
        self.reg_info = xMsgRegistration()
        self.reg_info.host = "localhost"
        self.reg_info.name = "xMsgR"
        self.reg_info.subject = "test_subject"
        self.reg_info.domain = "domain"
        self.reg_info.type = "type_p"
        self.reg_info.port = 8888
        self.msg = ["topic", "sender", self.reg_info]
        self.serialized_msg = [
            "topic", "sender",
            self.reg_info.SerializeToString()
        ]

        self.req = xMsgRegRequest.create_from_multipart(self.msg)
Exemplo n.º 6
0
    def remove_by_host(self, host):
        """Removes all stored registrations for specific hostname

        Method that removes all values of the registration database that
        have a specified host set, i.e.  removes registration information
        of all xMsg actors that are running on a specified host.

        Args:
            host (String): host name of the xMsg
        """
        for key in self.all():
            for r_data in self.db[key].copy():
                registration = xMsgRegistration_pb2.xMsgRegistration()
                registration.ParseFromString(r_data)
                if registration.host == host:
                    self.db.get(key).remove(r_data)
                    if len(self.db[key]) == 0:
                        del self.db[key]
Exemplo n.º 7
0
 def get_data(self):
     ds_msg = xMsgRegistration_pb2.xMsgRegistration()
     ds_msg.ParseFromString(self.data)
     return ds_msg