diff options
Diffstat (limited to 'java/demo')
-rw-r--r-- | java/demo/IceStorm/clock/Publisher.java | 63 | ||||
-rw-r--r-- | java/demo/IceStorm/clock/README | 44 | ||||
-rw-r--r-- | java/demo/IceStorm/clock/Subscriber.java | 131 | ||||
-rw-r--r-- | java/demo/IceStorm/clock/config.service | 2 | ||||
-rw-r--r-- | java/demo/IceStorm/clock/config.sub | 2 |
5 files changed, 213 insertions, 29 deletions
diff --git a/java/demo/IceStorm/clock/Publisher.java b/java/demo/IceStorm/clock/Publisher.java index 5ff723bb8c1..9a06a52fd88 100644 --- a/java/demo/IceStorm/clock/Publisher.java +++ b/java/demo/IceStorm/clock/Publisher.java @@ -11,6 +11,12 @@ import Demo.*; public class Publisher extends Ice.Application { + public void + usage() + { + System.out.println("Usage: " + appName() + " [--datagram|--twoway|--oneway] [topic]"); + } + public int run(String[] args) { @@ -22,14 +28,42 @@ public class Publisher extends Ice.Application return 1; } - String topicName = "time"; - if(args.length != 0) + String topicName = "time"; + boolean datagram = false; + boolean twoway = false; + boolean oneway = false; + int optsSet = 0; + for(int i = 0; i < args.length; ++i) { - topicName = args[0]; + if(args[i].equals("--datagram")) + { + datagram = true; + ++optsSet; + } + else if(args[i].equals("--twoway")) + { + twoway = true; + ++optsSet; + } + else if(args[i].equals("--oneway")) + { + oneway = true; + ++optsSet; + } + else if(args[i].startsWith("--")) + { + usage(); + return 1; + } + else + { + topicName = args[i]; + break; + } } // - // Retrieve the topic named "time". + // Retrieve the topic. // IceStorm.TopicPrx topic; try @@ -44,16 +78,29 @@ public class Publisher extends Ice.Application } catch(IceStorm.TopicExists ex) { - System.err.println("temporary failure, try again."); + System.err.println(appName() + ": temporary failure, try again."); return 1; } } // - // Get the topic's publisher object, the Clock type, and create a - // oneway Clock proxy (for efficiency reasons). + // Get the topic's publisher object, and create a Clock proxy with + // the mode specified as an argument of this application. // - ClockPrx clock = ClockPrxHelper.uncheckedCast(topic.getPublisher().ice_oneway()); + Ice.ObjectPrx publisher = topic.getPublisher(); + if(datagram) + { + publisher = publisher.ice_datagram(); + } + else if(twoway) + { + // Do nothing. + } + else // if(oneway) + { + publisher = publisher.ice_oneway(); + } + ClockPrx clock = ClockPrxHelper.uncheckedCast(publisher); System.out.println("publishing tick events. Press ^C to terminate the application."); try diff --git a/java/demo/IceStorm/clock/README b/java/demo/IceStorm/clock/README index b55ead1bcaa..acc1506736d 100644 --- a/java/demo/IceStorm/clock/README +++ b/java/demo/IceStorm/clock/README @@ -17,3 +17,47 @@ $ java Publisher While the publisher continues to run "tick" messages should be 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 +publisher can use different QoS for sending and receiving messages. + +For the subscriber: + +java Subscriber --oneway + + The subscriber receives events as oneway messages. This is the default. + +java Subscriber --datagram + + The subscriber receives events as datagrams. + +java Subscriber --twoway + + The subscriber receives events as twoway messages. + +java Subscriber --ordered + + The subscriber receives events as twoway messages with guaranteed + ordering. + +java Subscriber --batch + + This is an additional flag that forwards datagram and oneway events + to the subscriber in batches. + +For the publisher: + +java Publisher --oneway + + The publisher sends events as oneway messages. This is the default. + +java Publisher --datagram + + The publisher sends events as datagrams. + +java 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 ef9e37317e5..01f4887d72c 100644 --- a/java/demo/IceStorm/clock/Subscriber.java +++ b/java/demo/IceStorm/clock/Subscriber.java @@ -19,6 +19,12 @@ public class Subscriber extends Ice.Application System.out.println(date); } } + + public void + usage() + { + System.out.println("Usage: " + appName() + " [--batch] [--datagram|--twoway|--ordered|--oneway] [topic]"); + } public int run(String[] args) @@ -32,14 +38,65 @@ public class Subscriber extends Ice.Application } String topicName = "time"; - if(args.length != 0) - { - topicName = args[0]; - } + boolean datagram = false; + boolean twoway = false; + boolean ordered = false; + boolean oneway = false; + boolean batch = false; + int optsSet = 0; + for(int i = 0; i < args.length; ++i) + { + if(args[i].equals("--datagram")) + { + datagram = true; + ++optsSet; + } + else if(args[i].equals("--twoway")) + { + twoway = true; + ++optsSet; + } + else if(args[i].equals("--ordered")) + { + ordered = true; + ++optsSet; + } + else if(args[i].equals("--oneway")) + { + oneway = true; + ++optsSet; + } + else if(args[i].equals("--batch")) + { + batch = true; + } + else if(args[i].startsWith("--")) + { + usage(); + return 1; + } + else + { + topicName = args[i]; + break; + } + } + + if(batch) + { + if(twoway || ordered) + { + System.err.println(appName() + ": batch can only be set with oneway or datagram"); + return 1; + } + } + + if(optsSet != 1) + { + usage(); + return 1; + } - // - // Retrieve the topic named "time". - // IceStorm.TopicPrx topic; try { @@ -53,7 +110,7 @@ public class Subscriber extends Ice.Application } catch(IceStorm.TopicExists ex) { - System.err.println("temporary failure, try again."); + System.err.println(appName() + ": temporary failure, try again."); return 1; } } @@ -63,23 +120,59 @@ public class Subscriber extends Ice.Application // // Add a Servant for the Ice Object. // - Ice.ObjectPrx subscriber = adapter.addWithUUID(new ClockI()); - - // - // This demo requires no quality of service, so it will use - // the defaults. - // java.util.Map qos = new java.util.HashMap(); - - topic.subscribe(qos, subscriber); + Ice.ObjectPrx subscriber = adapter.addWithUUID(new ClockI()); + // + // Set up the proxy. + // + if(datagram) + { + subscriber = subscriber.ice_datagram(); + } + else if(twoway) + { + // Do nothing to the subscriber proxy. Its already twoway. + } + else if(ordered) + { + // Do nothing to the subscriber proxy. Its already twoway. + qos.put("reliability", "ordered"); + } + else // if(oneway) + { + subscriber = subscriber.ice_oneway(); + } + if(batch) + { + if(datagram) + { + subscriber = subscriber.ice_batchDatagram(); + } + else + { + subscriber = subscriber.ice_batchOneway(); + } + } + + try + { + topic.subscribeAndGetPublisher(qos, subscriber); + } + catch(IceStorm.AlreadySubscribed e) + { + e.printStackTrace(); + return 1; + } + catch(IceStorm.BadQoS e) + { + e.printStackTrace(); + return 1; + } adapter.activate(); shutdownOnInterrupt(); communicator().waitForShutdown(); - // - // Unsubscribe all subscribed objects. - // topic.unsubscribe(subscriber); return 0; diff --git a/java/demo/IceStorm/clock/config.service b/java/demo/IceStorm/clock/config.service index 4f1edc9ad3f..d88d9be996a 100644 --- a/java/demo/IceStorm/clock/config.service +++ b/java/demo/IceStorm/clock/config.service @@ -20,7 +20,7 @@ IceStorm.InstanceName=DemoIceStorm # IceStorm instances this must run on a fixed port (or use # IceGrid). # -Ice.OA.IceStorm.Publish.Endpoints=default -p 10001 +Ice.OA.IceStorm.Publish.Endpoints=default -p 10001:udp -p 10001 # # TopicManager Tracing diff --git a/java/demo/IceStorm/clock/config.sub b/java/demo/IceStorm/clock/config.sub index cb6b50d94f0..4f60a8ca7c1 100644 --- a/java/demo/IceStorm/clock/config.sub +++ b/java/demo/IceStorm/clock/config.sub @@ -2,7 +2,7 @@ # This property is used to configure the endpoints of the clock # subscriber adapter. # -Ice.OA.Clock.Subscriber.Endpoints=tcp +Ice.OA.Clock.Subscriber.Endpoints=tcp:udp # # This property is used by the clients to connect to IceStorm. |