summaryrefslogtreecommitdiff
path: root/java/demo/IceStorm/clock/Publisher.java
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2006-11-15 15:15:48 +0000
committerDwayne Boone <dwayne@zeroc.com>2006-11-15 15:15:48 +0000
commit2f55717289d3c6820317434ef61669aba5763913 (patch)
treea02f62b4df6ec4f88ddadfe82ac391b001492f88 /java/demo/IceStorm/clock/Publisher.java
parentBug 1547 (diff)
downloadice-2f55717289d3c6820317434ef61669aba5763913.tar.bz2
ice-2f55717289d3c6820317434ef61669aba5763913.tar.xz
ice-2f55717289d3c6820317434ef61669aba5763913.zip
Bug 1547
Diffstat (limited to 'java/demo/IceStorm/clock/Publisher.java')
-rw-r--r--java/demo/IceStorm/clock/Publisher.java64
1 files changed, 44 insertions, 20 deletions
diff --git a/java/demo/IceStorm/clock/Publisher.java b/java/demo/IceStorm/clock/Publisher.java
index f1917cc93b2..5c52bebe8e0 100644
--- a/java/demo/IceStorm/clock/Publisher.java
+++ b/java/demo/IceStorm/clock/Publisher.java
@@ -15,6 +15,7 @@ public class Publisher extends Ice.Application
run(String[] args)
{
Ice.Properties properties = communicator().getProperties();
+
final String proxyProperty = "IceStorm.TopicManager.Proxy";
String proxy = properties.getProperty(proxyProperty);
if(proxy.length() == 0)
@@ -23,46 +24,69 @@ public class Publisher extends Ice.Application
return 1;
}
- Ice.ObjectPrx base = communicator().stringToProxy(proxy);
- IceStorm.TopicManagerPrx manager = IceStorm.TopicManagerPrxHelper.checkedCast(base);
+ IceStorm.TopicManagerPrx manager = IceStorm.TopicManagerPrxHelper.checkedCast(
+ communicator().stringToProxy(proxy));
if(manager == null)
{
System.err.println("invalid proxy");
return 1;
}
+ String topicName = "time";
+ if(args.length != 0)
+ {
+ topicName = args[0];
+ }
+
//
// Retrieve the topic named "time".
//
IceStorm.TopicPrx topic;
try
{
- topic = manager.retrieve("time");
+ topic = manager.retrieve(topicName);
}
catch(IceStorm.NoSuchTopic e)
{
- System.err.println(e + "name: " + e.name);
- return 1;
+ try
+ {
+ topic = manager.create(topicName);
+ }
+ catch(IceStorm.TopicExists ex)
+ {
+ System.err.println("temporary failure, try again.");
+ return 1;
+ }
}
- assert(topic != null);
//
- // Get the topic's publisher object, verify that it supports
- // the Clock type, and create a oneway Clock proxy (for efficiency
- // reasons).
+ // Get the topic's publisher object, the Clock type, and create a
+ // oneway Clock proxy (for efficiency reasons).
//
- Ice.ObjectPrx obj = topic.getPublisher();
- if(!obj.ice_isDatagram())
- {
- obj = obj.ice_oneway();
- }
- ClockPrx clock = ClockPrxHelper.uncheckedCast(obj);
+ ClockPrx clock = ClockPrxHelper.uncheckedCast(topic.getPublisher().ice_oneway());
- System.out.println("publishing 10 tick events");
- for(int i = 0; i < 10; ++i)
- {
- clock.tick();
- }
+ System.out.println("publishing tick events. Press ^C to terminate the application.");
+ try
+ {
+ java.text.SimpleDateFormat date = new java.text.SimpleDateFormat("MM/dd/yy HH:mm:ss:SSS");
+ while(true)
+ {
+
+ clock.tick(date.format(new java.util.Date()));
+
+ try
+ {
+ Thread.currentThread().sleep(1000);
+ }
+ catch(java.lang.InterruptedException e)
+ {
+ }
+ }
+ }
+ catch(Ice.CommunicatorDestroyedException ex)
+ {
+ // Ignore
+ }
return 0;
}