Table Of Contents

Previous topic

_TopicTreeNode

Next topic

PublisherClass

This Page

phoenix_title _TopicTreeRoot

The root of the tree knows how to access other node of the tree and is the gateway of the tree user to the tree nodes. It can create topics, and and remove callbacks, etc.

For efficiency, it stores a dictionary of listener-topics, so that unsubscribing a listener just requires finding the topics associated to a listener, and finding the corresponding nodes of the tree. Without it, unsubscribing would require that we search the whole tree for all nodes that contain given listener. Since Publisher is a singleton, it will contain all topics in the system so it is likely to be a large tree. However, it is possible that in some runs, unsubscribe() is called very little by the user, in which case most unsubscriptions are automatic, ie caused by the listeners dying. In this case, a flag is set to indicate that the dictionary should be cleaned up at the next opportunity. This is not necessary, it is just an optimization.


class_hierarchy Inheritance Diagram

Inheritance diagram for class _TopicTreeRoot

Inheritance diagram of _TopicTreeRoot


super_classes Known Superclasses

lib.pubsub.pub._TopicTreeNode


method_summary Methods Summary

__init__  
addTopic Add topic to tree if doesnt exist, and add listener to topic node
getTopics Return the list of topics for given listener
isSubscribed Return true if listener is registered for topic specified.
numListeners Return a pair (live, dead) with count of live and dead listeners in tree
printCallbacks  
sendMessage Send a message for given topic to all registered listeners. If
unsubAll Unsubscribe all listeners registered for any topic in
unsubscribe Remove listener from given list of topics. If topicList

api Class API



class _TopicTreeRoot(_TopicTreeNode)

The root of the tree knows how to access other node of the tree and is the gateway of the tree user to the tree nodes. It can create topics, and and remove callbacks, etc.

For efficiency, it stores a dictionary of listener-topics, so that unsubscribing a listener just requires finding the topics associated to a listener, and finding the corresponding nodes of the tree. Without it, unsubscribing would require that we search the whole tree for all nodes that contain given listener. Since Publisher is a singleton, it will contain all topics in the system so it is likely to be a large tree. However, it is possible that in some runs, unsubscribe() is called very little by the user, in which case most unsubscriptions are automatic, ie caused by the listeners dying. In this case, a flag is set to indicate that the dictionary should be cleaned up at the next opportunity. This is not necessary, it is just an optimization.


Methods



__init__(self)


addTopic(self, topic, listener)

Add topic to tree if doesnt exist, and add listener to topic node



getTopics(self, listener)

Return the list of topics for given listener



isSubscribed(self, listener, topic=None)

Return true if listener is registered for topic specified. If no topic specified, return true if subscribed to something. Use topic=getStrAllTopics() to determine if a listener will receive messages for all topics.



numListeners(self)

Return a pair (live, dead) with count of live and dead listeners in tree



printCallbacks(self)


sendMessage(self, topic, message, onTopicNeverCreated)

Send a message for given topic to all registered listeners. If topic doesn’t exist, call onTopicNeverCreated(topic).



unsubAll(self, topicList, onNoSuchTopic)

Unsubscribe all listeners registered for any topic in topicList. If a topic in the list does not exist, and onNoSuchTopic is not None, a call to onNoSuchTopic(topic) is done for that topic.



unsubscribe(self, listener, topicList)

Remove listener from given list of topics. If topicList doesn’t have any topics for which listener has subscribed, nothing happens.