summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2007-12-13 14:49:32 -0330
committerDwayne Boone <dwayne@zeroc.com>2007-12-13 14:49:32 -0330
commit095ce5674bfa3c48b0cabbc2e37a10c0433a46aa (patch)
tree8c66092204389e83f3e678ff0f12dae45ab567a4 /java
parent- Fixes to makemsi.py to support new directory structure. (diff)
downloadice-095ce5674bfa3c48b0cabbc2e37a10c0433a46aa.tar.bz2
ice-095ce5674bfa3c48b0cabbc2e37a10c0433a46aa.tar.xz
ice-095ce5674bfa3c48b0cabbc2e37a10c0433a46aa.zip
Added multicast demo
Diffstat (limited to 'java')
-rwxr-xr-xjava/allDemos.py1
-rw-r--r--java/demo/Ice/README4
-rw-r--r--java/demo/Ice/build.xml2
-rw-r--r--java/demo/Ice/multicast/Client.java119
-rw-r--r--java/demo/Ice/multicast/Hello.ice24
-rw-r--r--java/demo/Ice/multicast/HelloI.java26
-rw-r--r--java/demo/Ice/multicast/README12
-rw-r--r--java/demo/Ice/multicast/Server.java37
-rw-r--r--java/demo/Ice/multicast/build.xml50
-rw-r--r--java/demo/Ice/multicast/config.client28
-rw-r--r--java/demo/Ice/multicast/config.server29
-rwxr-xr-xjava/demo/Ice/multicast/expect.py38
12 files changed, 370 insertions, 0 deletions
diff --git a/java/allDemos.py b/java/allDemos.py
index ded2a85ca94..675b5cfb356 100755
--- a/java/allDemos.py
+++ b/java/allDemos.py
@@ -65,6 +65,7 @@ demos = [
"Ice/invoke",
"Ice/latency",
"Ice/minimal",
+ "Ice/multicast",
"Ice/nested",
"Ice/session",
"Ice/throughput",
diff --git a/java/demo/Ice/README b/java/demo/Ice/README
index 6dbee2c5a4c..ed7506e7146 100644
--- a/java/demo/Ice/README
+++ b/java/demo/Ice/README
@@ -38,6 +38,10 @@ Demos in this directory:
This demo illustrates a minimal Ice application.
+- multicast
+
+ This demo illustrates the use of UDP multicast.
+
- nested
A demo to illustrate how nested callbacks work, and how the size of
diff --git a/java/demo/Ice/build.xml b/java/demo/Ice/build.xml
index b238c7e452d..809e521aa5f 100644
--- a/java/demo/Ice/build.xml
+++ b/java/demo/Ice/build.xml
@@ -23,6 +23,7 @@
<ant dir="value"/>
<ant dir="session"/>
<ant dir="async"/>
+ <ant dir="multicast"/>
</target>
<target name="clean">
@@ -37,6 +38,7 @@
<ant dir="value" target="clean"/>
<ant dir="session" target="clean"/>
<ant dir="async" target="clean"/>
+ <ant dir="multicast" target="clean"/>
</target>
</project>
diff --git a/java/demo/Ice/multicast/Client.java b/java/demo/Ice/multicast/Client.java
new file mode 100644
index 00000000000..b5ea6c11d42
--- /dev/null
+++ b/java/demo/Ice/multicast/Client.java
@@ -0,0 +1,119 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+import Demo.*;
+
+public class Client extends Ice.Application
+{
+ class ShutdownHook extends Thread
+ {
+ public void
+ run()
+ {
+ try
+ {
+ communicator().destroy();
+ }
+ catch(Ice.LocalException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ private static void
+ menu()
+ {
+ System.out.println(
+ "usage:\n" +
+ "t: send multicast message\n" +
+ "s: shutdown server\n" +
+ "x: exit\n" +
+ "?: help\n");
+ }
+
+ public int
+ run(String[] args)
+ {
+ if(args.length > 0)
+ {
+ System.err.println(appName() + ": too many arguments");
+ return 1;
+ }
+
+ //
+ // Since this is an interactive demo we want to clear the
+ // Application installed interrupt callback and install our
+ // own shutdown hook.
+ //
+ setInterruptHook(new ShutdownHook());
+
+ HelloPrx proxy = HelloPrxHelper.uncheckedCast(communicator().propertyToProxy("Hello.Proxy").ice_datagram());
+
+ menu();
+
+ java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
+
+ String line = null;
+ do
+ {
+ try
+ {
+ System.out.print("==> ");
+ System.out.flush();
+ line = in.readLine();
+ if(line == null)
+ {
+ break;
+ }
+ if(line.equals("t"))
+ {
+ proxy.sayHello();
+ }
+ else if(line.equals("s"))
+ {
+ proxy.shutdown();
+ }
+ else if(line.equals("x"))
+ {
+ // Nothing to do
+ }
+ else if(line.equals("?"))
+ {
+ menu();
+ }
+ else
+ {
+ System.out.println("unknown command `" + line + "'");
+ menu();
+ }
+ }
+ catch(java.io.IOException ex)
+ {
+ ex.printStackTrace();
+ }
+ catch(Ice.LocalException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ while(!line.equals("x"));
+
+ return 0;
+ }
+
+ public static void
+ main(String[] args)
+ {
+ Client app = new Client();
+ int status = app.main("Client", args, "config.client");
+ System.exit(status);
+ }
+}
+
diff --git a/java/demo/Ice/multicast/Hello.ice b/java/demo/Ice/multicast/Hello.ice
new file mode 100644
index 00000000000..86714e069ba
--- /dev/null
+++ b/java/demo/Ice/multicast/Hello.ice
@@ -0,0 +1,24 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+#ifndef HELLO_ICE
+#define HELLO_ICE
+
+module Demo
+{
+
+interface Hello
+{
+ ["cpp:const"] idempotent void sayHello();
+ void shutdown();
+};
+
+};
+
+#endif
diff --git a/java/demo/Ice/multicast/HelloI.java b/java/demo/Ice/multicast/HelloI.java
new file mode 100644
index 00000000000..7a779f2d9da
--- /dev/null
+++ b/java/demo/Ice/multicast/HelloI.java
@@ -0,0 +1,26 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+import Demo.*;
+
+public class HelloI extends _HelloDisp
+{
+ public void
+ sayHello(Ice.Current current)
+ {
+ System.out.println("Hello World!");
+ }
+
+ public void
+ shutdown(Ice.Current current)
+ {
+ System.out.println("Shutting down...");
+ current.adapter.getCommunicator().shutdown();
+ }
+}
diff --git a/java/demo/Ice/multicast/README b/java/demo/Ice/multicast/README
new file mode 100644
index 00000000000..5053bcabad9
--- /dev/null
+++ b/java/demo/Ice/multicast/README
@@ -0,0 +1,12 @@
+This demo illustrates how to use UDP multicast to send messages.
+
+To run the demo, first start multiple instances of the server:
+
+$ java Server
+
+In a separate window, start a client:
+
+$ java Client
+
+When you send a message you will notice that it is received by all
+running servers.
diff --git a/java/demo/Ice/multicast/Server.java b/java/demo/Ice/multicast/Server.java
new file mode 100644
index 00000000000..06f6576471c
--- /dev/null
+++ b/java/demo/Ice/multicast/Server.java
@@ -0,0 +1,37 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+import Demo.*;
+
+public class Server extends Ice.Application
+{
+ public int
+ run(String[] args)
+ {
+ if(args.length > 0)
+ {
+ System.err.println(appName() + ": too many arguments");
+ return 1;
+ }
+
+ Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Hello");
+ adapter.add(new HelloI(), communicator().stringToIdentity("hello"));
+ adapter.activate();
+ communicator().waitForShutdown();
+ return 0;
+ }
+
+ public static void
+ main(String[] args)
+ {
+ Server app = new Server();
+ int status = app.main("Server", args, "config.server");
+ System.exit(status);
+ }
+}
diff --git a/java/demo/Ice/multicast/build.xml b/java/demo/Ice/multicast/build.xml
new file mode 100644
index 00000000000..ccec3def1b6
--- /dev/null
+++ b/java/demo/Ice/multicast/build.xml
@@ -0,0 +1,50 @@
+<!--
+ **********************************************************************
+
+ Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.
+
+ This copy of Ice is licensed to you under the terms described in the
+ ICE_LICENSE file included in this distribution.
+
+ **********************************************************************
+-->
+
+<project name="demo_Ice_multicast" default="all" basedir=".">
+
+ <!-- set global properties for this build -->
+ <property name="top.dir" value="../../.."/>
+
+ <!-- import common definitions -->
+ <import file="${top.dir}/config/common.xml"/>
+
+ <target name="generate" depends="init">
+ <!-- Create the output directory for generated code -->
+ <mkdir dir="${generated.dir}"/>
+ <slice2java outputdir="${generated.dir}">
+ <meta value="${java2metadata}"/>
+ <fileset dir="." includes="Hello.ice"/>
+ </slice2java>
+ </target>
+
+ <target name="compile" depends="generate">
+ <mkdir dir="${class.dir}"/>
+ <javac srcdir="${generated.dir}" destdir="${class.dir}"
+ source="${jdk.version}" debug="${debug}">
+ <classpath refid="ice.classpath"/>
+ <compilerarg value="${javac.lint}" compiler="${javac.lint.compiler}"/>
+ </javac>
+ <javac srcdir="." destdir="${class.dir}" source="${jdk.version}"
+ excludes="generated/**" debug="${debug}">
+ <classpath refid="ice.classpath"/>
+ <compilerarg value="${javac.lint}" compiler="${javac.lint.compiler}"/>
+ </javac>
+ </target>
+
+ <target name="all" depends="compile"/>
+
+ <target name="clean">
+ <delete dir="${generated.dir}"/>
+ <delete dir="${class.dir}"/>
+ </target>
+
+</project>
diff --git a/java/demo/Ice/multicast/config.client b/java/demo/Ice/multicast/config.client
new file mode 100644
index 00000000000..8dd66d37f92
--- /dev/null
+++ b/java/demo/Ice/multicast/config.client
@@ -0,0 +1,28 @@
+#
+# The client reads this property to create the reference to the
+# "hello" object in the server.
+#
+Hello.Proxy=hello:udp -h 224.0.0.5 -p 10000
+
+#
+# Warn about connection exceptions
+#
+#Ice.Warn.Connections=1
+
+#
+# Network Tracing
+#
+# 0 = no network tracing
+# 1 = trace connection establishment and closure
+# 2 = like 1, but more detailed
+# 3 = like 2, but also trace data transfer
+#
+#Ice.Trace.Network=1
+
+#
+# Protocol Tracing
+#
+# 0 = no protocol tracing
+# 1 = trace protocol messages
+#
+#Ice.Trace.Protocol=1
diff --git a/java/demo/Ice/multicast/config.server b/java/demo/Ice/multicast/config.server
new file mode 100644
index 00000000000..1bb94c4644a
--- /dev/null
+++ b/java/demo/Ice/multicast/config.server
@@ -0,0 +1,29 @@
+#
+# The server creates one single object adapter with the name
+# "Hello". The following line sets the endpoints for this
+# adapter.
+#
+Hello.Endpoints=udp -h 224.0.0.5 -p 10000
+
+#
+# Warn about connection exceptions
+#
+#Ice.Warn.Connections=1
+
+#
+# Network Tracing
+#
+# 0 = no network tracing
+# 1 = trace connection establishment and closure
+# 2 = like 1, but more detailed
+# 3 = like 2, but also trace data transfer
+#
+#Ice.Trace.Network=1
+
+#
+# Protocol Tracing
+#
+# 0 = no protocol tracing
+# 1 = trace protocol messages
+#
+#Ice.Trace.Protocol=1
diff --git a/java/demo/Ice/multicast/expect.py b/java/demo/Ice/multicast/expect.py
new file mode 100755
index 00000000000..d27d7d37fd3
--- /dev/null
+++ b/java/demo/Ice/multicast/expect.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+# **********************************************************************
+#
+# Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.
+#
+# This copy of Ice is licensed to you under the terms described in the
+# ICE_LICENSE file included in this distribution.
+#
+# **********************************************************************
+
+import sys, os
+
+try:
+ import demoscript
+except ImportError:
+ for toplevel in [".", "..", "../..", "../../..", "../../../.."]:
+ toplevel = os.path.normpath(toplevel)
+ if os.path.exists(os.path.join(toplevel, "demoscript")):
+ break
+ else:
+ raise "can't find toplevel directory!"
+ sys.path.append(os.path.join(toplevel))
+ import demoscript
+
+import demoscript.Util
+import demoscript.Ice.multicast
+demoscript.Util.defaultLanguage = "Java"
+
+server1 = demoscript.Util.spawn('java Server --Ice.PrintAdapterReady')
+server1.expect('.* ready')
+server2 = demoscript.Util.spawn('java Server --Ice.PrintAdapterReady')
+server2.expect('.* ready')
+server3 = demoscript.Util.spawn('java Server --Ice.PrintAdapterReady')
+server3.expect('.* ready')
+client = demoscript.Util.spawn('java Client')
+client.expect('.*==>')
+
+demoscript.Ice.multicast.run(client, server1, server2, server3)