Exemplo n.º 1
0
 def create_subscriber(self):
     """Create a subscriber using specified addresses and message types."""
     if self.subscriber is None:
         if self.topics:
             LOGGER.info("Subscribing to %s with topics %s",
                         str(self.address), str(self.topics))
             self.subscriber = Subscriber(self.address, self.topics)
             LOGGER.debug("Subscriber %s", str(self.subscriber))
Exemplo n.º 2
0
 def create_subscriber(self):
     '''Create a subscriber instance using specified addresses and
     message types.
     '''
     if self.subscriber is None:
         if len(self.address_list) > 0:
             if len(self.msg_type_list) > 0:
                 self.subscriber = Subscriber(self.address_list,
                                              *self.msg_type_list)
Exemplo n.º 3
0
    def __init__(self, holder, configfile):
        Thread.__init__(self)

        self.scanlines = holder

        cfg = ConfigParser()
        cfg.read(configfile)
        host = cfg.get("local_reception", "mirror")
        hostname = cfg.get(host, "hostname")
        port = cfg.get(host, "pubport")
        rport = cfg.get(host, "reqport")
        address = "tcp://" + hostname + ":" + port
        self._sub = Subscriber([address], "hrpt 0")
        self._reqaddr = "tcp://" + hostname + ":" + rport
Exemplo n.º 4
0
def create_subscriber(cfgfile):
    """Create a new subscriber for all the remote hosts in cfgfile.
    """

    cfg = ConfigParser()
    cfg.read(cfgfile)
    addrs = []
    for host in cfg.get("local_reception", "remotehosts").split():
        addrs.append("tcp://" + cfg.get(host, "hostname") + ":" +
                     cfg.get(host, "pubport"))
    localhost = cfg.get("local_reception", "localhost")
    addrs.append("tcp://" + cfg.get(localhost, "hostname") + ":" +
                 cfg.get(localhost, "pubport"))
    logger.debug("Subscribing to " + str(addrs))
    return Subscriber(addrs, "hrpt 0", translate=True)
Exemplo n.º 5
0
    def test_pub_suber(self):
        """Test publisher and subscriber.
        """

        pub_address = "tcp://" + str(get_own_ip()) + ":0"
        pub = Publisher(pub_address)
        addr = pub_address[:-1] + str(pub.port_number)
        sub = Subscriber([addr], '/counter')
        tested = False
        for counter in range(5):
            message = Message("/counter", "info", str(counter))
            pub.send(str(message))
            time.sleep(1)

            msg = sub.recv(2).next()
            if msg is not None:
                self.assertEquals(str(msg), str(message))
                tested = True
        self.assertTrue(tested)
        pub.stop()
 def create_subscriber(self):
     '''
     '''
     if len(self.address_list) > 0:
         self.subscriber = Subscriber(self.address_list, self.type_list)