Ejemplo n.º 1
0
class TopicInfo(object):

    def __init__(self, config, name, pub_nodes, sub_nodes):
        self.name, self._pub_nodes, self._sub_nodes = name, pub_nodes, sub_nodes
        n = config.ctx.nodes
        node_config = n._config
        NodeNS = n._nstype
        self.pub_nodes = NSResourceList('', node_config, pub_nodes, NodeNS)
        self.sub_nodes = NSResourceList('', node_config, sub_nodes, NodeNS)

    def _update(self, pub_nodes, sub_nodes):
        """
        In-place update of resource lists
        """
        self._pub_nodes, _sub_nodes = pub_nodes, sub_nodes        
        self.pub_nodes._set_resources(pub_nodes)
        self.sub_nodes._set_resources(sub_nodes)

    def __repr__(self):
        return self.__str__()
        
    def __str__(self):
        buff ="Topic [%s]\n"%(self.name)
        if self._pub_nodes:
            buff += "\nPublishers:\n"
            buff += '\n'.join([" * %s"%(l) for l in self._pub_nodes]) + '\n' 
        if self._sub_nodes:
            buff += "\nSubscribers:\n"
            buff += '\n'.join([" * %s"%(l) for l in self._sub_nodes]) + '\n'                
        return buff
Ejemplo n.º 2
0
class NodeInfo(object):
    
    def __init__(self, config, name, pubs, subs, srvs):
        self.name, self._pubs, self._subs, self._srvs = name, pubs, subs, srvs

        # we need to use the config from the relevant concept so that
        # we are allocating off of pre-existing instances. We also
        # need to fetch the relevant Namespace class for instantiating
        # resources.
        t = config.ctx.topics
        s = config.ctx.services
        topic_config = t._config
        service_config = s._config
        TopicNS = t._nstype
        ServiceNS = s._nstype

        self.pubs = NSResourceList('', topic_config, pubs, TopicNS)
        self.subs = NSResourceList('', topic_config, subs, TopicNS)
        self.srvs = NSResourceList('', service_config, srvs, ServiceNS)
        
    def _update(self, pubs, subs, srvs):
        """
        In-place update of resource lists
        """
        self._pubs, self._subs, self._srvs = pubs, subs, srvs
        self.pubs._set_resources(pubs)
        self.subs._set_resources(subs)
        self.srvs._set_resources(srvs)
        
    def __repr__(self):
        return self.__str__()
        
    def __str__(self):
        pubs, subs, srvs = self._pubs, self._subs, self._srvs
        buff = 'Node [%s]\n'%(self.name)
        if pubs:
            buff += "\nPublications: \n"
            buff += '\n'.join([" * %s"%(l) for l in pubs]) + '\n'
        else:
            buff += "\nPublications: None\n"
        if subs:
            buff += "\nSubscriptions: \n"
            buff += '\n'.join([" * %s"%(l) for l in subs]) + '\n'
        else:
            buff += "\nSubscriptions: None\n"        
        if srvs:
            buff += "\nServices: \n"
            buff += '\n'.join([" * %s"%l for l in srvs]) + '\n'
        else:
            buff += "\nServices: None\n"

        return buff