summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2005-09-22 12:53:39 +0000
committerBenoit Foucher <benoit@zeroc.com>2005-09-22 12:53:39 +0000
commitbfdd9834dafd44a84753591220657ca1cc6a3098 (patch)
treebc982ee6aa3611d9143c6056156b2b007093d946 /java
parentAdded include of <sys/loadavg.h> for Sun (diff)
downloadice-bfdd9834dafd44a84753591220657ca1cc6a3098.tar.bz2
ice-bfdd9834dafd44a84753591220657ca1cc6a3098.tar.xz
ice-bfdd9834dafd44a84753591220657ca1cc6a3098.zip
Added IceGrid demo.
Diffstat (limited to 'java')
-rw-r--r--java/demo/IceGrid/build.xml22
-rw-r--r--java/demo/IceGrid/simple/Client.java99
-rw-r--r--java/demo/IceGrid/simple/Hello.ice24
-rw-r--r--java/demo/IceGrid/simple/HelloI.java26
-rw-r--r--java/demo/IceGrid/simple/README33
-rw-r--r--java/demo/IceGrid/simple/Server.java31
-rw-r--r--java/demo/IceGrid/simple/application.xml29
-rw-r--r--java/demo/IceGrid/simple/application_with_replication.xml39
-rw-r--r--java/demo/IceGrid/simple/application_with_template.xml34
-rw-r--r--java/demo/IceGrid/simple/build.xml59
-rw-r--r--java/demo/IceGrid/simple/config31
-rw-r--r--java/demo/IceGrid/simple/db/.dummy0
-rw-r--r--java/demo/build.xml1
13 files changed, 428 insertions, 0 deletions
diff --git a/java/demo/IceGrid/build.xml b/java/demo/IceGrid/build.xml
new file mode 100644
index 00000000000..2b9953bd953
--- /dev/null
+++ b/java/demo/IceGrid/build.xml
@@ -0,0 +1,22 @@
+<!--
+ **********************************************************************
+
+ Copyright (c) 2003-2005 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_IceGrid" default="all" basedir=".">
+
+ <target name="all">
+ <ant dir="simple"/>
+ </target>
+
+ <target name="clean">
+ <ant dir="simple" target="clean"/>
+ </target>
+
+</project>
diff --git a/java/demo/IceGrid/simple/Client.java b/java/demo/IceGrid/simple/Client.java
new file mode 100644
index 00000000000..1637604185b
--- /dev/null
+++ b/java/demo/IceGrid/simple/Client.java
@@ -0,0 +1,99 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 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
+{
+ private void
+ menu()
+ {
+ System.out.println(
+ "usage:\n" +
+ "t: send greeting as twoway\n" +
+ "s: shutdown server\n" +
+ "x: exit\n" +
+ "?: help\n");
+ }
+
+ public int
+ run(String[] args)
+ {
+ Ice.Properties properties = communicator().getProperties();
+
+ properties.parseCommandLineOptions("", args);
+
+ Ice.ObjectPrx base = communicator().stringToProxy(properties.getPropertyWithDefault("Identity", "hello"));
+ HelloPrx twoway = HelloPrxHelper.checkedCast(base);
+ if(twoway == null)
+ {
+ System.err.println("invalid proxy");
+ return 1;
+ }
+
+ 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"))
+ {
+ twoway.sayHello();
+ }
+ else if(line.equals("s"))
+ {
+ twoway.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");
+ System.exit(status);
+ }
+}
diff --git a/java/demo/IceGrid/simple/Hello.ice b/java/demo/IceGrid/simple/Hello.ice
new file mode 100644
index 00000000000..176763722ce
--- /dev/null
+++ b/java/demo/IceGrid/simple/Hello.ice
@@ -0,0 +1,24 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 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
+{
+ nonmutating void sayHello();
+ idempotent void shutdown();
+};
+
+};
+
+#endif
diff --git a/java/demo/IceGrid/simple/HelloI.java b/java/demo/IceGrid/simple/HelloI.java
new file mode 100644
index 00000000000..e4dea49e024
--- /dev/null
+++ b/java/demo/IceGrid/simple/HelloI.java
@@ -0,0 +1,26 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 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/IceGrid/simple/README b/java/demo/IceGrid/simple/README
new file mode 100644
index 00000000000..d2808f4e9cd
--- /dev/null
+++ b/java/demo/IceGrid/simple/README
@@ -0,0 +1,33 @@
+To run the demo, first start the IceGrid service:
+
+$ icegridnode --Ice.Config=config --warn
+
+In a separate window:
+
+$ icegridadmin --Ice.Config=config -e "application add 'application.xml'"
+$ java Client
+
+This will deploy the servers described in the file "application.xml"
+and start the client.
+
+Messages will be displayed in the IceGrid service window.
+
+To remove the application:
+
+$ icegridadmin --Ice.Config=config -e "application remove Simple"
+
+You can also use the following descriptors to deploy the application:
+
+- application_with_templates.xml: This descriptor demonstrates the use
+ of templates for the server definition. Templates make it easy to
+ deploy multiple instances of the same server. To deploy a new server
+ based on the template, use the following command:
+
+ $ icegridadmin --Ice.Config=config -e "server template instantiate \
+ Simple localhost SimpleServer index=2"
+
+ This will deploy a new server based on the `SimpleServer' template.
+
+- application_with_replication.xml: This descriptor demonstrates the
+ use of replication to balance the load of the application over
+ several servers.
diff --git a/java/demo/IceGrid/simple/Server.java b/java/demo/IceGrid/simple/Server.java
new file mode 100644
index 00000000000..0c161a5c180
--- /dev/null
+++ b/java/demo/IceGrid/simple/Server.java
@@ -0,0 +1,31 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 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.
+//
+// **********************************************************************
+
+public class Server extends Ice.Application
+{
+ public int
+ run(String[] args)
+ {
+ Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Hello");
+ String id = communicator().getProperties().getProperty("Identity");
+
+ adapter.add(new HelloI(), Ice.Util.stringToIdentity(id));
+ adapter.activate();
+ communicator().waitForShutdown();
+ return 0;
+ }
+
+ static public void
+ main(String[] args)
+ {
+ Server app = new Server();
+ int status = app.main("Server", args);
+ System.exit(status);
+ }
+}
diff --git a/java/demo/IceGrid/simple/application.xml b/java/demo/IceGrid/simple/application.xml
new file mode 100644
index 00000000000..8a8fddbb754
--- /dev/null
+++ b/java/demo/IceGrid/simple/application.xml
@@ -0,0 +1,29 @@
+<!--
+ **********************************************************************
+
+ Copyright (c) 2003-2005 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.
+
+ **********************************************************************
+-->
+
+<icegrid>
+
+ <application name="Simple">
+
+ <node name="localhost">
+ <server id="SimpleServer" exe="java" pwd="." activation="on-demand">
+ <env>CLASSPATH=classes:$CLASSPATH</env>
+ <option>Server</option>
+ <adapter name="Hello" endpoints="tcp" register="true">
+ <object identity="hello" type="::Hello"/>
+ </adapter>
+ <property name="Identity" value="hello"/>
+ </server>
+ </node>
+
+ </application>
+
+</icegrid>
diff --git a/java/demo/IceGrid/simple/application_with_replication.xml b/java/demo/IceGrid/simple/application_with_replication.xml
new file mode 100644
index 00000000000..ac9397b3d37
--- /dev/null
+++ b/java/demo/IceGrid/simple/application_with_replication.xml
@@ -0,0 +1,39 @@
+<!--
+ **********************************************************************
+
+ Copyright (c) 2003-2005 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.
+
+ **********************************************************************
+-->
+
+<icegrid>
+
+ <application name="Simple">
+
+ <server-template id="SimpleServer">
+ <parameter name="index"/>
+ <server id="SimpleServer-${index}" exe="java" pwd="." activation="on-demand">
+ <env>CLASSPATH=classes:$CLASSPATH</env>
+ <option>Server</option>
+ <adapter name="Hello" endpoints="tcp" register="true" id="ReplicatedHelloAdapter"/>
+ <property name="Identity" value="hello"/>
+ </server>
+ </server-template>
+
+ <replicated-adapter id="ReplicatedHelloAdapter">
+ <load-balancing type="round-robin"/>
+ <object identity="hello" type="::Demo::Hello"/>
+ </replicated-adapter>
+
+ <node name="localhost">
+ <server-instance template="SimpleServer" index="1"/>
+ <server-instance template="SimpleServer" index="2"/>
+ <server-instance template="SimpleServer" index="3"/>
+ </node>
+
+ </application>
+
+</icegrid>
diff --git a/java/demo/IceGrid/simple/application_with_template.xml b/java/demo/IceGrid/simple/application_with_template.xml
new file mode 100644
index 00000000000..b8610bff049
--- /dev/null
+++ b/java/demo/IceGrid/simple/application_with_template.xml
@@ -0,0 +1,34 @@
+<!--
+ **********************************************************************
+
+ Copyright (c) 2003-2005 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.
+
+ **********************************************************************
+-->
+
+<icegrid>
+
+ <application name="Simple">
+
+ <server-template id="SimpleServer">
+ <parameter name="index"/>
+ <server id="SimpleServer-${index}" exe="java" pwd="." activation="on-demand">
+ <env>CLASSPATH=classes:$CLASSPATH</env>
+ <option>Server</option>
+ <adapter name="Hello" endpoints="tcp" register="true">
+ <object identity="hello-${index}" type="::Hello"/>
+ </adapter>
+ <property name="Identity" value="hello-${index}"/>
+ </server>
+ </server-template>
+
+ <node name="localhost">
+ <server-instance template="SimpleServer" index="1"/>
+ </node>
+
+ </application>
+
+</icegrid>
diff --git a/java/demo/IceGrid/simple/build.xml b/java/demo/IceGrid/simple/build.xml
new file mode 100644
index 00000000000..290f6caa6a2
--- /dev/null
+++ b/java/demo/IceGrid/simple/build.xml
@@ -0,0 +1,59 @@
+<!--
+ **********************************************************************
+
+ Copyright (c) 2003-2005 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.
+
+ **********************************************************************
+-->
+
+<!DOCTYPE project [
+<!ENTITY common SYSTEM "file:../../../config/common.xml">
+]>
+
+<project name="demo_IceGrid_simple" default="all" basedir=".">
+
+ <!-- set global properties for this build -->
+ <property name="top.dir" value="../../.."/>
+
+ <!-- Include common definitions -->
+ &common;
+
+ <property name="class.dir" value="classes"/>
+ <property name="generated.dir" value="generated"/>
+
+ <target name="init" depends="config-init">
+ <!-- Create the time stamp -->
+ <tstamp/>
+ </target>
+
+ <target name="generate" depends="init">
+ <!-- Create the output directory for generated code -->
+ <mkdir dir="${generated.dir}"/>
+ <slice2java outputdir="${generated.dir}">
+ <fileset dir="." includes="Hello.ice"/>
+ </slice2java>
+ </target>
+
+ <target name="compile" depends="generate">
+ <mkdir dir="${class.dir}"/>
+ <javac srcdir="${generated.dir}" destdir="${class.dir}"
+ source="1.4" debug="${debug}">
+ <classpath refid="ice.classpath"/>
+ </javac>
+ <javac srcdir="." destdir="${class.dir}" source="1.4"
+ excludes="generated/**" debug="${debug}">
+ <classpath refid="ice.classpath"/>
+ </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/IceGrid/simple/config b/java/demo/IceGrid/simple/config
new file mode 100644
index 00000000000..c7e93d3c133
--- /dev/null
+++ b/java/demo/IceGrid/simple/config
@@ -0,0 +1,31 @@
+#
+# The IceGrid locator proxy.
+#
+Ice.Default.Locator=IceGrid/Locator:default -p 12000
+
+#
+# IceGrid registry configuration.
+#
+IceGrid.Registry.Client.Endpoints=default -p 12000
+IceGrid.Registry.Server.Endpoints=default
+IceGrid.Registry.Internal.Endpoints=default
+IceGrid.Registry.Admin.Endpoints=default
+IceGrid.Registry.Data=db/registry
+
+#
+# IceGrid node configuration.
+#
+IceGrid.Node.Name=localhost
+IceGrid.Node.Endpoints=default
+IceGrid.Node.Data=db/node
+IceGrid.Node.CollocateRegistry=1
+#IceGrid.Node.Output=db
+#IceGrid.Node.RedirectErrToOut=1
+
+#
+# Trace properties.
+#
+IceGrid.Node.Trace.Activator=1
+IceGrid.Node.Trace.Patch=1
+#IceGrid.Node.Trace.Adapter=2
+#IceGrid.Node.Trace.Server=3
diff --git a/java/demo/IceGrid/simple/db/.dummy b/java/demo/IceGrid/simple/db/.dummy
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/java/demo/IceGrid/simple/db/.dummy
diff --git a/java/demo/build.xml b/java/demo/build.xml
index 7680ba6e71d..8299eacf98e 100644
--- a/java/demo/build.xml
+++ b/java/demo/build.xml
@@ -17,6 +17,7 @@
<ant dir="IceBox"/>
<ant dir="IcePack"/>
<ant dir="Glacier2"/>
+ <and dir="IceGrid"/>
<ant dir="book"/>
</target>