diff options
Diffstat (limited to 'java')
-rw-r--r-- | java/demo/IceStorm/clock/Publisher.java | 49 | ||||
-rw-r--r-- | java/demo/IceStorm/clock/README | 31 | ||||
-rw-r--r-- | java/demo/IceStorm/clock/Subscriber.java | 153 | ||||
-rw-r--r-- | java/demo/IceStorm/clock/config.pub | 2 | ||||
-rw-r--r-- | java/demo/IceStorm/clock/config.service | 5 | ||||
-rw-r--r-- | java/demo/IceStorm/clock/config.sub | 2 |
6 files changed, 162 insertions, 80 deletions
diff --git a/java/demo/IceStorm/clock/Publisher.java b/java/demo/IceStorm/clock/Publisher.java index 6516475cbbb..5078748baf2 100644 --- a/java/demo/IceStorm/clock/Publisher.java +++ b/java/demo/IceStorm/clock/Publisher.java @@ -20,35 +20,24 @@ public class Publisher extends Ice.Application public int run(String[] args) { - IceStorm.TopicManagerPrx manager = IceStorm.TopicManagerPrxHelper.checkedCast( - communicator().propertyToProxy("IceStorm.TopicManager.Proxy")); - if(manager == null) - { - System.err.println("invalid proxy"); - return 1; - } - + String option = "None"; String topicName = "time"; - boolean datagram = false; - boolean twoway = false; - boolean oneway = false; - int optsSet = 0; - for(int i = 0; i < args.length; ++i) + 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("--oneway")) { - oneway = true; - ++optsSet; + option = "Oneway"; } else if(args[i].startsWith("--")) { @@ -57,17 +46,31 @@ public class Publisher extends Ice.Application } else { - topicName = args[i]; + topicName = args[i++]; break; } + + if(!oldoption.equals(option) && !oldoption.equals("None")) + { + usage(); + return 1; + } } - if(optsSet > 1) + if(i != args.length) { usage(); return 1; } + IceStorm.TopicManagerPrx manager = IceStorm.TopicManagerPrxHelper.checkedCast( + communicator().propertyToProxy("TopicManager.Proxy")); + if(manager == null) + { + System.err.println("invalid proxy"); + return 1; + } + // // Retrieve the topic. // @@ -94,11 +97,11 @@ public class Publisher extends Ice.Application // the mode specified as an argument of this application. // Ice.ObjectPrx publisher = topic.getPublisher(); - if(datagram) + if(option.equals("Datagram")) { publisher = publisher.ice_datagram(); } - else if(twoway) + else if(option.equals("Twoway")) { // Do nothing. } diff --git a/java/demo/IceStorm/clock/README b/java/demo/IceStorm/clock/README index 9339189ee30..0146a70c9c3 100644 --- a/java/demo/IceStorm/clock/README +++ b/java/demo/IceStorm/clock/README @@ -21,44 +21,57 @@ displayed in the subscriber window. Both the subscriber and publisher take an optional topic name as a final argument. The default value for this topic is "time". -Through the use of command-line options, both the subscriber and +Through the use of command-line options both the subscriber and publisher can use different QoS for sending and receiving messages. For the subscriber: -java Subscriber --oneway +subscriber --oneway The subscriber receives events as oneway messages. This is the default. -java Subscriber --datagram +subscriber --datagram The subscriber receives events as datagrams. -java Subscriber --twoway +subscriber --twoway The subscriber receives events as twoway messages. -java Subscriber --ordered +subscriber --ordered The subscriber receives events as twoway messages with guaranteed ordering. -java Subscriber --batch +subscriber --batch This is an additional flag that forwards datagram and oneway events to the subscriber in batches. +subscriber --id <id> + + This is flag sets the unique for the given subscriber. If this + option is used it you should run the subscriber on a static port. + Use --Clock.Subscriber.Endpoints="tcp -p <x> -h <h>:udp -p <x> -h + <h>" + +subscriber --retryCount <count> + + This flag sets the retry count for a subscriber. This option should + be used in conjunction with the --id option. Setting retryCount + changes the default subscriber QoS to twoway. + For the publisher: -java Publisher --oneway +publisher --oneway The publisher sends events as oneway messages. This is the default. -java Publisher --datagram +publisher --datagram The publisher sends events as datagrams. -java Publisher --twoway +publisher --twoway The publisher sends events as twoway messages. diff --git a/java/demo/IceStorm/clock/Subscriber.java b/java/demo/IceStorm/clock/Subscriber.java index 047e0e16329..7fac97459ec 100644 --- a/java/demo/IceStorm/clock/Subscriber.java +++ b/java/demo/IceStorm/clock/Subscriber.java @@ -23,51 +23,64 @@ public class Subscriber extends Ice.Application public void usage() { - System.out.println("Usage: " + appName() + " [--batch] [--datagram|--twoway|--ordered|--oneway] [topic]"); + System.out.println("Usage: " + appName() + " [--batch] [--datagram|--twoway|--ordered|--oneway] " + + "[--retryCount count] [--id id] [topic]"); } public int run(String[] args) { - IceStorm.TopicManagerPrx manager = IceStorm.TopicManagerPrxHelper.checkedCast( - communicator().propertyToProxy("IceStorm.TopicManager.Proxy")); - if(manager == null) - { - System.err.println("invalid proxy"); - return 1; - } + args = communicator().getProperties().parseCommandLineOptions("Clock", args); String topicName = "time"; - boolean datagram = false; - boolean twoway = false; - boolean ordered = false; + String option = "None"; boolean 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(); @@ -75,22 +88,53 @@ public class Subscriber extends Ice.Application } else { - topicName = args[i]; + topicName = args[i++]; break; } + + if(!oldoption.equals(option) && !oldoption.equals("None")) + { + usage(); + return 1; + } + } + + 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 && (twoway || ordered)) + + if(batch && (option.equals("Twoway") || option.equals("Ordered"))) { System.err.println(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(); + System.err.println("invalid proxy"); return 1; } + // + // Retrieve the topic. + // IceStorm.TopicPrx topic; try { @@ -112,50 +156,77 @@ public class Subscriber extends Ice.Application 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. // + // 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); + java.util.Map<String, String> qos = new java.util.HashMap<String, String>(); - Ice.ObjectPrx subscriber = adapter.addWithUUID(new ClockI()); + if(retryCount != null) + { + qos.put("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.put("reliability", "ordered"); } - else // if(oneway) + else if(option.equals("Oneway") || option.equals("None")) { - subscriber = subscriber.ice_oneway(); - } - if(batch) - { - 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 e) { - e.printStackTrace(); - return 1; + // If we're manually setting the subscriber id ignore. + if(id == null) + { + e.printStackTrace(); + return 1; + } + else + { + System.out.println("reactivating persistent subscriber"); + } } catch(IceStorm.BadQoS e) { diff --git a/java/demo/IceStorm/clock/config.pub b/java/demo/IceStorm/clock/config.pub index c6de9cb84b1..e7d497f8f52 100644 --- a/java/demo/IceStorm/clock/config.pub +++ b/java/demo/IceStorm/clock/config.pub @@ -1,7 +1,7 @@ # # This property is used by the clients to connect to IceStorm. # -IceStorm.TopicManager.Proxy=DemoIceStorm/TopicManager:default -p 10000 +TopicManager.Proxy=DemoIceStorm/TopicManager:default -p 10000 # # Network Tracing diff --git a/java/demo/IceStorm/clock/config.service b/java/demo/IceStorm/clock/config.service index 818ad2f761b..1cabb0820d3 100644 --- a/java/demo/IceStorm/clock/config.service +++ b/java/demo/IceStorm/clock/config.service @@ -1,9 +1,4 @@ # -# This property is used by the administrative client to connect to IceStorm. -# -IceStorm.TopicManager.Proxy=DemoIceStorm/TopicManager:default -p 10000 - -# # This property defines the endpoints on which the IceStorm # TopicManager listens. # diff --git a/java/demo/IceStorm/clock/config.sub b/java/demo/IceStorm/clock/config.sub index ad2ac555de8..cefadaeb6e5 100644 --- a/java/demo/IceStorm/clock/config.sub +++ b/java/demo/IceStorm/clock/config.sub @@ -7,7 +7,7 @@ Clock.Subscriber.Endpoints=tcp:udp # # This property is used by the clients to connect to IceStorm. # -IceStorm.TopicManager.Proxy=DemoIceStorm/TopicManager:default -p 10000 +TopicManager.Proxy=DemoIceStorm/TopicManager:default -p 10000 # # Network Tracing |