diff options
author | Matthew Newhook <matthew@zeroc.com> | 2008-02-29 15:51:11 +0800 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2008-02-29 16:39:54 +0800 |
commit | fb4132881dde7c9b135d713a06a3b64db1f706db (patch) | |
tree | 8a037e9d4cae7ed15360ab0878d14b32ac3150a4 /cs/demo/IceStorm/clock/Subscriber.cs | |
parent | fixing mode on php/config/Make.rules.mak (diff) | |
download | ice-fb4132881dde7c9b135d713a06a3b64db1f706db.tar.bz2 ice-fb4132881dde7c9b135d713a06a3b64db1f706db.tar.xz ice-fb4132881dde7c9b135d713a06a3b64db1f706db.zip |
Merge HA IceStorm branch.
- http://bugzilla/bugzilla/show_bug.cgi?id=2706
- http://bugzilla/bugzilla/show_bug.cgi?id=2705
Diffstat (limited to 'cs/demo/IceStorm/clock/Subscriber.cs')
-rw-r--r-- | cs/demo/IceStorm/clock/Subscriber.cs | 156 |
1 files changed, 111 insertions, 45 deletions
diff --git a/cs/demo/IceStorm/clock/Subscriber.cs b/cs/demo/IceStorm/clock/Subscriber.cs index b403db93d2f..776dc6506d3 100644 --- a/cs/demo/IceStorm/clock/Subscriber.cs +++ b/cs/demo/IceStorm/clock/Subscriber.cs @@ -32,45 +32,57 @@ public class Subscriber public override int run(string[] args) { - IceStorm.TopicManagerPrx manager = IceStorm.TopicManagerPrxHelper.checkedCast( - communicator().propertyToProxy("IceStorm.TopicManager.Proxy")); - if(manager == null) - { - Console.WriteLine("invalid proxy"); - return 1; - } + args = communicator().getProperties().parseCommandLineOptions("Clock", args); string topicName = "time"; - bool datagram = false; - bool twoway = false; - bool ordered = false; + string option = "None"; bool batch = false; - int optsSet = 0; - for(int i = 0; i < args.Length; ++i) + string id = null; + string retryCount = null; + int i; + for(i = 0; i < args.Length; ++i) { + String oldoption = option; if(args[i].Equals("--datagram")) { - datagram = true; - ++optsSet; + option = "Datagram"; } else if(args[i].Equals("--twoway")) { - twoway = true; - ++optsSet; + option = "Twoway"; } else if(args[i].Equals("--ordered")) { - ordered = true; - ++optsSet; + option = "Ordered"; } else if(args[i].Equals("--oneway")) { - ++optsSet; + option = "Oneway"; } else if(args[i].Equals("--batch")) { batch = true; } + else if(args[i].Equals("--id")) + { + ++i; + if(i >= args.Length) + { + usage(); + return 1; + } + id = args[i]; + } + else if(args[i].Equals("--retryCount")) + { + ++i; + if(i >= args.Length) + { + usage(); + return 1; + } + retryCount = args[i]; + } else if(args[i].StartsWith("--")) { usage(); @@ -78,20 +90,47 @@ public class Subscriber } else { - topicName = args[i]; + topicName = args[i++]; break; } + + if(!oldoption.Equals(option) && !oldoption.Equals("None")) + { + usage(); + return 1; + } } - if(batch && (twoway || ordered)) + if(i != args.Length) + { + usage(); + return 1; + } + + if(retryCount != null) + { + if(option.Equals("None")) + { + option = "Twoway"; + } + else if(!option.Equals("Twoway") && !option.Equals("Ordered")) + { + usage(); + return 1; + } + } + + if(batch && (option.Equals("Twoway") || option.Equals("Ordered"))) { Console.WriteLine(appName() + ": batch can only be set with oneway or datagram"); return 1; } - if(optsSet > 1) + IceStorm.TopicManagerPrx manager = IceStorm.TopicManagerPrxHelper.checkedCast( + communicator().propertyToProxy("TopicManager.Proxy")); + if(manager == null) { - usage(); + Console.WriteLine("invalid proxy"); return 1; } @@ -117,55 +156,81 @@ public class Subscriber } Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Clock.Subscriber"); - // - // Add a Servant for the Ice Object. + // Add a servant for the Ice object. If --id is used the + // identity comes from the command line, otherwise a UUID is + // used. // - Ice.ObjectPrx subscriber = adapter.addWithUUID(new ClockI()); - + // id is not directly altered since it is used below to + // detect whether subscribeAndGetPublisher can raise + // AlreadySubscribed. + // + Ice.Identity subId = new Ice.Identity(id, ""); + if(subId.name == null) + { + subId.name = Ice.Util.generateUUID(); + } + Ice.ObjectPrx subscriber = adapter.add(new ClockI(), subId); + Dictionary<string, string> qos = new Dictionary<string, string>(); - + if(retryCount != null) + { + qos["retryCount"] = retryCount; + } // // Set up the proxy. // - if(datagram) + if(option.Equals("Datagram")) { - subscriber = subscriber.ice_datagram(); + if(batch) + { + subscriber = subscriber.ice_batchDatagram(); + } + else + { + subscriber = subscriber.ice_datagram(); + } } - else if(twoway) + else if(option.Equals("Twoway")) { // Do nothing to the subscriber proxy. Its already twoway. } - else if(ordered) + else if(option.Equals("Ordered")) { // Do nothing to the subscriber proxy. Its already twoway. qos["reliability"] = "ordered"; } - else // if(oneway) - { - subscriber = subscriber.ice_oneway(); - } - if(batch) + else if(option.Equals("Oneway") || option.Equals("None")) { - if(datagram) + if(batch) { - subscriber = subscriber.ice_batchDatagram(); + subscriber = subscriber.ice_batchOneway(); } else { - subscriber = subscriber.ice_batchOneway(); + subscriber = subscriber.ice_oneway(); } } + + try + { + topic.subscribeAndGetPublisher(qos, subscriber); + } + catch(IceStorm.AlreadySubscribed) + { + // If we're manually setting the subscriber id ignore. + if(id == null) + { + throw; + } + System.Console.Out.WriteLine("reactivating persistent subscriber"); + } - topic.subscribeAndGetPublisher(qos, subscriber); adapter.activate(); shutdownOnInterrupt(); communicator().waitForShutdown(); - // - // Unsubscribe all subscribed objects. - // topic.unsubscribe(subscriber); return 0; @@ -174,7 +239,8 @@ public class Subscriber public void usage() { - Console.WriteLine("Usage: " + appName() + " [--batch] [--datagram|--twoway|--ordered|--oneway] [topic]"); + Console.WriteLine("Usage: " + appName() + " [--batch] [--datagram|--twoway|--ordered|--oneway] " + + "[--retryCount count] [--id id] [topic]"); } } |