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.
__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 |
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.
Add topic to tree if doesnt exist, and add listener to topic node
Return the list of topics for given listener
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.
Return a pair (live, dead) with count of live and dead listeners in tree
Send a message for given topic to all registered listeners. If topic doesn’t exist, call onTopicNeverCreated(topic).
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.
Remove listener from given list of topics. If topicList doesn’t have any topics for which listener has subscribed, nothing happens.