diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2006-11-15 16:28:03 +0000 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2006-11-15 16:28:03 +0000 |
commit | 99f0ba2f16954defa94554d25d341ece0f8d3a79 (patch) | |
tree | f43e12f4b1c28056b3520e3269d0f82475ad600e /py/demo/IceStorm/clock/Subscriber.py | |
parent | Fixed Windows Errors (diff) | |
download | ice-99f0ba2f16954defa94554d25d341ece0f8d3a79.tar.bz2 ice-99f0ba2f16954defa94554d25d341ece0f8d3a79.tar.xz ice-99f0ba2f16954defa94554d25d341ece0f8d3a79.zip |
Bug 1547
Diffstat (limited to 'py/demo/IceStorm/clock/Subscriber.py')
-rw-r--r-- | py/demo/IceStorm/clock/Subscriber.py | 80 |
1 files changed, 31 insertions, 49 deletions
diff --git a/py/demo/IceStorm/clock/Subscriber.py b/py/demo/IceStorm/clock/Subscriber.py index 3060e4a00ee..d997a4554f3 100644 --- a/py/demo/IceStorm/clock/Subscriber.py +++ b/py/demo/IceStorm/clock/Subscriber.py @@ -14,8 +14,8 @@ Ice.loadSlice('Clock.ice') import Demo class ClockI(Demo.Clock): - def tick(self, current=None): - print "tick" + def tick(self, date, current=None): + print date class Subscriber(Ice.Application): def run(self, args): @@ -28,68 +28,50 @@ class Subscriber(Ice.Application): return False base = self.communicator().stringToProxy(proxy) - manager = IceStorm.TopicManagerPrx.checkedCast(base) + manager = IceStorm.TopicManagerPrx.checkedCast(self.communicator().stringToProxy(proxy)) if not manager: print args[0] + ": invalid proxy" return False - # - # Gather the set of topics to which to subscribe. It is either - # the set provided on the command line, or the topic "time". - # - topics = [] - if len(args) > 1: - for i in range(1, len(args)): - topics.append(args[i]) - else: - topics.append("time") - - # - # Set the requested quality of service "reliability" = - # "batch". This tells IceStorm to send events to the subscriber - # in batches at regular intervals. - # - qos = {} - qos["reliability"] = "batch" + topicName = "time" + if len(args) != 1: + topicName = args[1] + + # + # Retrieve the topic. + # + try: + topic = manager.retrieve(topicName) + except IceStorm.NoSuchTopic, e: + try: + topic = manager.create(topicName) + except IceStorm.TopicExists, ex: + print self.appName() + ": temporay error. try again" + return False - # - # Create the servant to receive the events. - # adapter = self.communicator().createObjectAdapter("Clock.Subscriber") - clock = ClockI() - # - # List of all subscribers. + # Add a Servant for the Ice Object. # - subscribers = {} + subscriber = adapter.addWithUUID(ClockI()); # - # Add the servant to the adapter for each topic. A ServantLocator - # could have been used for the same purpose. + # This demo requires no quality of service, so it will use + # the defaults. # - for i in range(0, len(topics)): - object = adapter.addWithUUID(clock) - try: - topic = manager.retrieve(topics[i]) - topic.subscribe(qos, object) - except IceStorm.NoSuchTopic, e: - print self.appName() + ": no such topic name: " + e.name - break + qos = {} - subscribers[topics[i]] = object + topic.subscribe(qos, subscriber) + adapter.activate() - if len(subscribers) == len(topics): - adapter.activate() - self.shutdownOnInterrupt() - self.communicator().waitForShutdown() + self.shutdownOnInterrupt() + self.communicator().waitForShutdown() - for name in subscribers.keys(): - try: - topic = manager.retrieve(name) - topic.unsubscribe(subscribers[name]) - except IceStorm.NoSuchTopic, e: - print self.appName() + ": no such topic name: " + e.name + # + # Unsubscribe all subscribed objects. + # + topic.unsubscribe(subscriber) return True |