summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2006-05-18 13:16:24 +0000
committerDwayne Boone <dwayne@zeroc.com>2006-05-18 13:16:24 +0000
commit5564ca9ff4cab84a8082f6d7acb9fde6585e4901 (patch)
tree4799017c831242e594bb76a28ef9593294a3c4b6
parentMinor edits (diff)
downloadice-5564ca9ff4cab84a8082f6d7acb9fde6585e4901.tar.bz2
ice-5564ca9ff4cab84a8082f6d7acb9fde6585e4901.tar.xz
ice-5564ca9ff4cab84a8082f6d7acb9fde6585e4901.zip
Added sessionactivation demo
-rw-r--r--java/demo/IceGrid/build.xml2
-rw-r--r--java/demo/IceGrid/sessionActivation/Client.java191
-rw-r--r--java/demo/IceGrid/sessionActivation/Hello.ice24
-rw-r--r--java/demo/IceGrid/sessionActivation/HelloI.java33
-rw-r--r--java/demo/IceGrid/sessionActivation/README13
-rw-r--r--java/demo/IceGrid/sessionActivation/Server.java31
-rw-r--r--java/demo/IceGrid/sessionActivation/application.xml28
-rw-r--r--java/demo/IceGrid/sessionActivation/build.xml59
-rw-r--r--java/demo/IceGrid/sessionActivation/config.client4
-rw-r--r--java/demo/IceGrid/sessionActivation/config.grid33
10 files changed, 418 insertions, 0 deletions
diff --git a/java/demo/IceGrid/build.xml b/java/demo/IceGrid/build.xml
index d9029c9c6e8..4c024c03f4f 100644
--- a/java/demo/IceGrid/build.xml
+++ b/java/demo/IceGrid/build.xml
@@ -13,10 +13,12 @@
<target name="all">
<ant dir="simple"/>
+ <ant dir="sessionActivation"/>
</target>
<target name="clean">
<ant dir="simple" target="clean"/>
+ <ant dir="sessionActivation" target="clean"/>
</target>
</project>
diff --git a/java/demo/IceGrid/sessionActivation/Client.java b/java/demo/IceGrid/sessionActivation/Client.java
new file mode 100644
index 00000000000..b2e542ffd9f
--- /dev/null
+++ b/java/demo/IceGrid/sessionActivation/Client.java
@@ -0,0 +1,191 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 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
+{
+ static private class SessionKeepAliveThread extends Thread
+ {
+ SessionKeepAliveThread(IceGrid.SessionPrx session)
+ {
+ _session = session;
+ _timeout = 5000;
+ _terminated = false;
+ }
+
+ synchronized public void
+ run()
+ {
+ while(!_terminated)
+ {
+ try
+ {
+ wait(_timeout);
+ }
+ catch(InterruptedException e)
+ {
+ }
+ if(_terminated)
+ {
+ break;
+ }
+ try
+ {
+ _session.keepAlive();
+ }
+ catch(Ice.LocalException ex)
+ {
+ break;
+ }
+ }
+ }
+
+ synchronized private void
+ terminate()
+ {
+ _terminated = true;
+ notify();
+ }
+
+ final private IceGrid.SessionPrx _session;
+ final private long _timeout;
+ private boolean _terminated;
+ }
+
+ private void
+ menu()
+ {
+ System.out.println(
+ "usage:\n" +
+ "t: send greeting\n" +
+ "x: exit\n" +
+ "?: help\n");
+ }
+
+ public int
+ run(String[] args)
+ {
+ IceGrid.SessionManagerPrx sessionManager =
+ IceGrid.SessionManagerPrxHelper.checkedCast(communicator().stringToProxy("DemoIceGrid/SessionManager"));
+ if(sessionManager == null)
+ {
+ System.err.println(": cound not contact session manager");
+ return 1;
+ }
+
+ java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
+
+ String id = null;
+
+ try
+ {
+ System.out.print("user id: ");
+ System.out.flush();
+ id = in.readLine();
+ id = id.trim();
+ }
+ catch(java.io.IOException ex)
+ {
+ ex.printStackTrace();
+ return 1;
+ }
+
+ IceGrid.SessionPrx session = sessionManager.createLocalSession(id);
+
+ SessionKeepAliveThread keepAlive = new SessionKeepAliveThread(session);
+ keepAlive.start();
+
+ HelloPrx hello = null;
+ try
+ {
+ hello = HelloPrxHelper.checkedCast(session.allocateObjectById(communicator().stringToIdentity("hello")));
+ }
+ catch(IceGrid.AllocationException ex)
+ {
+ System.err.println(": could not allocate object: " + ex.reason);
+ return 1;
+ }
+ catch(IceGrid.ObjectNotRegisteredException ex)
+ {
+ System.err.println(": object not registered with registry");
+ return 1;
+ }
+
+ menu();
+
+ String line = null;
+ do
+ {
+ try
+ {
+ System.out.print("==> ");
+ System.out.flush();
+ line = in.readLine();
+ if(line == null)
+ {
+ break;
+ }
+ if(line.equals("t"))
+ {
+ hello.sayHello();
+ }
+ 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"));
+
+ keepAlive.terminate();
+
+ try
+ {
+ session.releaseObject(hello.ice_getIdentity());
+ }
+ catch(IceGrid.AllocationException ex)
+ {
+ System.err.println(": could not release object: " + ex.reason);
+ return 1;
+ }
+ catch(IceGrid.ObjectNotRegisteredException ex)
+ {
+ System.err.println(": object not registered with registry");
+ return 1;
+ }
+
+ 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/IceGrid/sessionActivation/Hello.ice b/java/demo/IceGrid/sessionActivation/Hello.ice
new file mode 100644
index 00000000000..a83a5c601b7
--- /dev/null
+++ b/java/demo/IceGrid/sessionActivation/Hello.ice
@@ -0,0 +1,24 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 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/sessionActivation/HelloI.java b/java/demo/IceGrid/sessionActivation/HelloI.java
new file mode 100644
index 00000000000..105a27c659a
--- /dev/null
+++ b/java/demo/IceGrid/sessionActivation/HelloI.java
@@ -0,0 +1,33 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 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 HelloI(String name)
+ {
+ _name = name;
+ }
+
+ public void
+ sayHello(Ice.Current current)
+ {
+ System.out.println(_name + " says Hello World!");
+ }
+
+ public void
+ shutdown(Ice.Current current)
+ {
+ System.out.println(_name + " shutting down...");
+ current.adapter.getCommunicator().shutdown();
+ }
+
+ private final String _name;
+}
diff --git a/java/demo/IceGrid/sessionActivation/README b/java/demo/IceGrid/sessionActivation/README
new file mode 100644
index 00000000000..e7b9dc7cfb8
--- /dev/null
+++ b/java/demo/IceGrid/sessionActivation/README
@@ -0,0 +1,13 @@
+To run the demo, first start the IceGrid service:
+
+$ icegridnode --Ice.Config=config.grid
+
+In a separate window:
+
+$ icegridadmin --Ice.Config=config.grid -e "application add 'application.xml'"
+$ java Client
+
+This will deploy the application described in the file "application.xml"
+and start the client.
+
+Messages will be displayed in the IceGrid service window.
diff --git a/java/demo/IceGrid/sessionActivation/Server.java b/java/demo/IceGrid/sessionActivation/Server.java
new file mode 100644
index 00000000000..5ad0ec96c4d
--- /dev/null
+++ b/java/demo/IceGrid/sessionActivation/Server.java
@@ -0,0 +1,31 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 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");
+ Ice.Properties properties = communicator().getProperties();
+ Ice.Identity id = communicator().stringToIdentity(properties.getProperty("Identity"));
+ adapter.add(new HelloI(properties.getProperty("Ice.ServerId")), 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/sessionActivation/application.xml b/java/demo/IceGrid/sessionActivation/application.xml
new file mode 100644
index 00000000000..49a70f84c18
--- /dev/null
+++ b/java/demo/IceGrid/sessionActivation/application.xml
@@ -0,0 +1,28 @@
+<!--
+ **********************************************************************
+
+ 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="Session">
+
+ <node name="localhost">
+ <server id="SessionServer" exe="java" activation="session">
+ <option>Server</option>
+ <adapter name="Hello" endpoints="tcp" register-process="true">
+ <object identity="hello" type="::Demo::Hello"/>
+ </adapter>
+ <property name="Identity" value="hello"/>
+ </server>
+ </node>
+
+ </application>
+
+</icegrid>
diff --git a/java/demo/IceGrid/sessionActivation/build.xml b/java/demo/IceGrid/sessionActivation/build.xml
new file mode 100644
index 00000000000..ca1bbaa4391
--- /dev/null
+++ b/java/demo/IceGrid/sessionActivation/build.xml
@@ -0,0 +1,59 @@
+<!--
+ **********************************************************************
+
+ Copyright (c) 2003-2006 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_sessionActivation" 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="${jdk.version}" debug="${debug}">
+ <classpath refid="ice.classpath"/>
+ </javac>
+ <javac srcdir="." destdir="${class.dir}" source="${jdk.version}"
+ 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/sessionActivation/config.client b/java/demo/IceGrid/sessionActivation/config.client
new file mode 100644
index 00000000000..78100695847
--- /dev/null
+++ b/java/demo/IceGrid/sessionActivation/config.client
@@ -0,0 +1,4 @@
+#
+# The IceGrid locator proxy.
+#
+Ice.Default.Locator=DemoIceGrid/Locator:default -p 12000
diff --git a/java/demo/IceGrid/sessionActivation/config.grid b/java/demo/IceGrid/sessionActivation/config.grid
new file mode 100644
index 00000000000..5f12392aa12
--- /dev/null
+++ b/java/demo/IceGrid/sessionActivation/config.grid
@@ -0,0 +1,33 @@
+IceGrid.InstanceName=DemoIceGrid
+
+#
+# The IceGrid locator proxy.
+#
+Ice.Default.Locator=DemoIceGrid/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