summaryrefslogtreecommitdiff
path: root/py/demo/IceStorm/clock/Subscriber.py
diff options
context:
space:
mode:
authorMatthew Newhook <matthew@zeroc.com>2007-02-02 06:35:15 +0000
committerMatthew Newhook <matthew@zeroc.com>2007-02-02 06:35:15 +0000
commit4313ec716660c138ad219042e6e1ca790028be0f (patch)
tree1cc5832fa18fc4e20c5fd3015a4a510a67f69eed /py/demo/IceStorm/clock/Subscriber.py
parenthttp://bugzilla.zeroc.com/bugzilla/show_bug.cgi?id=1711 (diff)
downloadice-4313ec716660c138ad219042e6e1ca790028be0f.tar.bz2
ice-4313ec716660c138ad219042e6e1ca790028be0f.tar.xz
ice-4313ec716660c138ad219042e6e1ca790028be0f.zip
http://bugzilla.zeroc.com/bugzilla/show_bug.cgi?id=1711
Diffstat (limited to 'py/demo/IceStorm/clock/Subscriber.py')
-rw-r--r--py/demo/IceStorm/clock/Subscriber.py71
1 files changed, 60 insertions, 11 deletions
diff --git a/py/demo/IceStorm/clock/Subscriber.py b/py/demo/IceStorm/clock/Subscriber.py
index 17fb94ad222..cdf9ae706de 100644
--- a/py/demo/IceStorm/clock/Subscriber.py
+++ b/py/demo/IceStorm/clock/Subscriber.py
@@ -8,7 +8,7 @@
#
# **********************************************************************
-import sys, traceback, Ice, IceStorm
+import sys, traceback, Ice, IceStorm, getopt
Ice.loadSlice('Clock.ice')
import Demo
@@ -18,8 +18,47 @@ class ClockI(Demo.Clock):
print date
class Subscriber(Ice.Application):
+ def usage(self):
+ print "Usage: " + self.appName() + " [--batch] [--datagram|--twoway|--ordered|--oneway] [topic]"
+
def run(self, args):
- properties = self.communicator().getProperties()
+ try:
+ opts, args = getopt.getopt(args, '', ['datagram', 'twoway', 'oneway'])
+ except getopt.GetoptError:
+ self.usage()
+ return False
+
+ topicName = "time"
+ datagram = False
+ twoway = False
+ ordered = False
+ batch = False
+ optsSet = 0;
+ for o, a in opts:
+ if o == "--datagram":
+ datagram = True
+ optsSet = optsSet + 1
+ elif o =="--twoway":
+ twoway = True
+ optsSet = optsSet + 1
+ elif o =="--ordered":
+ ordered = True
+ optsSet = optsSet + 1
+ elif o =="--oneway":
+ optsSet = optsSet + 1
+ elif o =="--batch":
+ batch = True
+
+ if batch and (twoway or ordered):
+ print self.appName() + ": batch can only be set with oneway or datagram"
+ return False
+
+ if optsSet > 1:
+ self.usage()
+ sys.exit(1)
+
+ if len(args) > 1:
+ topicName = args[1]
manager = IceStorm.TopicManagerPrx.checkedCast(\
self.communicator().propertyToProxy('IceStorm.TopicManager.Proxy'))
@@ -27,10 +66,6 @@ class Subscriber(Ice.Application):
print args[0] + ": invalid proxy"
return False
- topicName = "time"
- if len(args) != 1:
- topicName = args[1]
-
#
# Retrieve the topic.
#
@@ -40,7 +75,7 @@ class Subscriber(Ice.Application):
try:
topic = manager.create(topicName)
except IceStorm.TopicExists, ex:
- print self.appName() + ": temporay error. try again"
+ print self.appName() + ": temporary error. try again"
return False
adapter = self.communicator().createObjectAdapter("Clock.Subscriber")
@@ -48,15 +83,29 @@ class Subscriber(Ice.Application):
#
# Add a Servant for the Ice Object.
#
+ qos = {}
subscriber = adapter.addWithUUID(ClockI());
#
- # This demo requires no quality of service, so it will use
- # the defaults.
+ # Set up the proxy.
#
- qos = {}
+ if datagram:
+ subscriber = subscriber.ice_datagram();
+ elif twoway:
+ pass
+ # Do nothing to the subscriber proxy. Its already twoway.
+ elif ordered:
+ # Do nothing to the subscriber proxy. Its already twoway.
+ qos["reliability"] = "ordered"
+ else: # if(oneway)
+ subscriber = subscriber.ice_oneway();
+ if batch:
+ if datagram:
+ subscriber = subscriber.ice_batchDatagram();
+ else:
+ subscriber = subscriber.ice_batchOneway();
- topic.subscribe(qos, subscriber)
+ topic.subscribeAndGetPublisher(qos, subscriber)
adapter.activate()
self.shutdownOnInterrupt()