summaryrefslogtreecommitdiff
path: root/java/demo/Database/library
diff options
context:
space:
mode:
Diffstat (limited to 'java/demo/Database/library')
-rw-r--r--java/demo/Database/library/Glacier2Session.ice50
-rw-r--r--java/demo/Database/library/Glacier2SessionManagerI.java33
-rw-r--r--java/demo/Database/library/Library.ice58
-rw-r--r--java/demo/Database/library/README23
-rw-r--r--java/demo/Database/library/ReapThread.java24
-rw-r--r--java/demo/Database/library/RunParser.java122
-rw-r--r--java/demo/Database/library/Server.java1
-rw-r--r--java/demo/Database/library/Session.ice72
-rw-r--r--java/demo/Database/library/SessionFactoryI.java15
-rw-r--r--java/demo/Database/library/SessionI.java2
-rw-r--r--java/demo/Database/library/build.xml15
-rw-r--r--java/demo/Database/library/config.client37
12 files changed, 362 insertions, 90 deletions
diff --git a/java/demo/Database/library/Glacier2Session.ice b/java/demo/Database/library/Glacier2Session.ice
new file mode 100644
index 00000000000..4686486a929
--- /dev/null
+++ b/java/demo/Database/library/Glacier2Session.ice
@@ -0,0 +1,50 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2008 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 LIBRARY_GLACIER2_SESSION_ICE
+#define LIBRARY_GLACIER2_SESSION_ICE
+
+#include <Glacier2/Session.ice>
+
+module Demo
+{
+
+/* Forward declaration. */
+interface Library;
+
+/**
+ *
+ * The session object. This is used to retrieve a per-session library
+ * on behalf of the client. If the session is not refreshed on a
+ * periodic basis, it will be automatically destroyed.
+ *
+ */
+interface Glacier2Session extends Glacier2::Session
+{
+ /**
+ *
+ * Get the library object.
+ *
+ * @return A proxy for the new library.
+ *
+ **/
+ Library* getLibrary();
+
+ /**
+ *
+ * Refresh a session. If a session is not refreshed on a regular
+ * basis by the client, it will be automatically destroyed.
+ *
+ **/
+ idempotent void refresh();
+};
+
+};
+
+#endif
diff --git a/java/demo/Database/library/Glacier2SessionManagerI.java b/java/demo/Database/library/Glacier2SessionManagerI.java
new file mode 100644
index 00000000000..8e36b88a681
--- /dev/null
+++ b/java/demo/Database/library/Glacier2SessionManagerI.java
@@ -0,0 +1,33 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2008 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.*;
+
+class Glacier2SessionManagerI extends Glacier2._SessionManagerDisp
+{
+ public Glacier2.SessionPrx
+ create(String userId, Glacier2.SessionControlPrx control, Ice.Current c)
+ {
+ SessionI session = new SessionI(_logger, c.adapter);
+ _Glacier2SessionTie servant = new _Glacier2SessionTie(session);
+ Glacier2.SessionPrx proxy = Glacier2.SessionPrxHelper.uncheckedCast(c.adapter.addWithUUID(servant));
+ _logger.trace("SessionFactory", "create new session: " + proxy.ice_getIdentity());
+ _reaper.add(proxy, session);
+ return proxy;
+ }
+
+ Glacier2SessionManagerI(Ice.Logger logger, ReapThread reaper)
+ {
+ _logger = logger;
+ _reaper = reaper;
+ }
+
+ private Ice.Logger _logger;
+ private ReapThread _reaper;
+}
diff --git a/java/demo/Database/library/Library.ice b/java/demo/Database/library/Library.ice
index 5111dd7fc1a..61a4fac5dcb 100644
--- a/java/demo/Database/library/Library.ice
+++ b/java/demo/Database/library/Library.ice
@@ -231,64 +231,6 @@ interface Library
throws BookExistsException;
};
-/**
- *
- * The session object. This is used to retrieve a per-session library
- * on behalf of the client. If the session is not refreshed on a
- * periodic basis, it will be automatically destroyed.
- *
- */
-interface Session
-{
- /**
- *
- * Get the library object.
- *
- * @return A proxy for the new library.
- *
- **/
- Library* getLibrary();
-
- /**
- *
- * Refresh a session. If a session is not refreshed on a regular
- * basis by the client, it will be automatically destroyed.
- *
- **/
- idempotent void refresh();
-
- /**
- *
- * Destroy the session.
- *
- **/
- void destroy();
-};
-
-/**
- *
- * Interface to create new sessions.
- *
- **/
-interface SessionFactory
-{
- /**
- *
- * Create a session.
- *
- * @return A proxy to the session.
- *
- **/
- Session* create();
-};
-
-/*
-interface Glacier2SessionFactory extends Glacier2::Session
-{
- Session* create();
-};
-*/
-
};
#endif
diff --git a/java/demo/Database/library/README b/java/demo/Database/library/README
index f7340d80620..51b60cf23d7 100644
--- a/java/demo/Database/library/README
+++ b/java/demo/Database/library/README
@@ -37,7 +37,7 @@ change them to connect to your mysql server.
To run the demo, first start the server:
- $ java Server
+$ java Server
In another window, populate the server's database by starting the
client and redirecting its input from the file "books":
@@ -49,3 +49,24 @@ Then start the client again to use the demo interactively:
$ java Client
Type "help" to get a list of valid commands.
+
+The demo also supports a Glacier2 deployment. To do so, edit
+config.client and uncomment the three configuration parameters:
+
+#Ice.Default.Router=DemoGlacier2/router:ssl -p 4064 -h 127.0.0.1
+#Ice.ACM.Client=0
+#Ice.RetryIntervals=-1
+
+Then to run the demo:
+
+Start the server:
+
+$ java Server
+
+In a separate window, start the Glacier2 router:
+
+$ glacier2router --Ice.Config=config.glacier2
+
+In a separate window, start the client:
+
+$ java Client
diff --git a/java/demo/Database/library/ReapThread.java b/java/demo/Database/library/ReapThread.java
index 5bef3cd3c50..0735f3d243e 100644
--- a/java/demo/Database/library/ReapThread.java
+++ b/java/demo/Database/library/ReapThread.java
@@ -15,10 +15,19 @@ class ReapThread extends Thread
{
SessionProxyPair(Demo.SessionPrx p, SessionI s)
{
+ glacier2proxy = null;
proxy = p;
session = s;
}
+ SessionProxyPair(Glacier2.SessionPrx p, SessionI s)
+ {
+ glacier2proxy = p;
+ proxy = null;
+ session = s;
+ }
+
+ Glacier2.SessionPrx glacier2proxy;
Demo.SessionPrx proxy;
SessionI session;
}
@@ -57,7 +66,14 @@ class ReapThread extends Thread
if((System.currentTimeMillis() - s.session.timestamp()) > _timeout)
{
_logger.trace("ReapThread", "The session " + s.proxy.ice_getIdentity() + " has timed out.");
- s.proxy.destroy();
+ if(s.proxy != null)
+ {
+ s.proxy.destroy();
+ }
+ else
+ {
+ s.glacier2proxy.destroy();
+ }
p.remove();
}
}
@@ -95,6 +111,12 @@ class ReapThread extends Thread
_sessions.add(new SessionProxyPair(proxy, session));
}
+ synchronized public void
+ add(Glacier2.SessionPrx proxy, SessionI session)
+ {
+ _sessions.add(new SessionProxyPair(proxy, session));
+ }
+
private final long _timeout = 10 * 1000; // 10 seconds.
private Ice.Logger _logger;
private boolean _terminated = false;
diff --git a/java/demo/Database/library/RunParser.java b/java/demo/Database/library/RunParser.java
index 42b10910861..93e31cc2206 100644
--- a/java/demo/Database/library/RunParser.java
+++ b/java/demo/Database/library/RunParser.java
@@ -11,9 +11,67 @@ import Demo.*;
class RunParser
{
+ //
+ // Adapter for the two types of session objects.
+ //
+ interface SessionAdapter
+ {
+ public LibraryPrx getLibrary();
+ public void destroy();
+ public void refresh();
+ }
+
+ static class Glacier2SessionAdapter implements SessionAdapter
+ {
+ public LibraryPrx getLibrary()
+ {
+ return _session.getLibrary();
+ }
+ public void destroy()
+ {
+ _session.destroy();
+ }
+
+ public void refresh()
+ {
+ _session.refresh();
+ }
+
+ Glacier2SessionAdapter(Glacier2SessionPrx session)
+ {
+ _session = session;
+ }
+
+ private Glacier2SessionPrx _session;
+ }
+
+ static class DemoSessionAdapter implements SessionAdapter
+ {
+ public LibraryPrx getLibrary()
+ {
+ return _session.getLibrary();
+ }
+ public void destroy()
+ {
+ _session.destroy();
+ }
+
+ public void refresh()
+ {
+ _session.refresh();
+ }
+
+ DemoSessionAdapter(SessionPrx session)
+ {
+ _session = session;
+ }
+
+ private SessionPrx _session;
+ }
+
static private class SessionRefreshThread extends Thread
{
- SessionRefreshThread(Ice.Logger logger, long timeout, SessionPrx session)
+ SessionRefreshThread(Ice.Logger logger, long timeout, SessionAdapter session)
{
_logger = logger;
_session = session;
@@ -55,7 +113,7 @@ class RunParser
}
final private Ice.Logger _logger;
- final private SessionPrx _session;
+ final private SessionAdapter _session;
final private long _timeout;
private boolean _terminated = false;
}
@@ -63,15 +121,61 @@ class RunParser
static int
runParser(String appName, String[] args, Ice.Communicator communicator)
{
- SessionFactoryPrx factory = SessionFactoryPrxHelper.checkedCast(
- communicator.propertyToProxy("SessionFactory.Proxy"));
- if(factory == null)
+ SessionAdapter session;
+ Glacier2.RouterPrx router = Glacier2.RouterPrxHelper.uncheckedCast(communicator.getDefaultRouter());
+ if(router != null)
{
- System.err.println(appName + ": invalid object reference");
- return 1;
- }
+ Glacier2.SessionPrx glacier2session = null;
+ java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
+ while(true)
+ {
+ System.out.println("This demo accepts any user-id / password combination.");
- SessionPrx session = factory.create();
+ try
+ {
+ String id;
+ System.out.print("user id: ");
+ System.out.flush();
+ id = in.readLine();
+
+ String pw;
+ System.out.print("password: ");
+ System.out.flush();
+ pw = in.readLine();
+
+ try
+ {
+ glacier2session = router.createSession(id, pw);
+ break;
+ }
+ catch(Glacier2.PermissionDeniedException ex)
+ {
+ System.out.println("permission denied:\n" + ex.reason);
+ }
+ catch(Glacier2.CannotCreateSessionException ex)
+ {
+ System.out.println("cannot create session:\n" + ex.reason);
+ }
+ }
+ catch(java.io.IOException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ session = new Glacier2SessionAdapter(Glacier2SessionPrxHelper.uncheckedCast(glacier2session));
+ }
+ else
+ {
+ SessionFactoryPrx factory = SessionFactoryPrxHelper.checkedCast(
+ communicator.propertyToProxy("SessionFactory.Proxy"));
+ if(factory == null)
+ {
+ System.err.println(appName + ": invalid object reference");
+ return 1;
+ }
+
+ session = new DemoSessionAdapter(factory.create());
+ }
SessionRefreshThread refresh = new SessionRefreshThread(communicator.getLogger(), 5000, session);
refresh.start();
diff --git a/java/demo/Database/library/Server.java b/java/demo/Database/library/Server.java
index 39cee6a0492..d1043988a55 100644
--- a/java/demo/Database/library/Server.java
+++ b/java/demo/Database/library/Server.java
@@ -125,6 +125,7 @@ class LibraryServer extends Ice.Application
LocatorI locator = new LocatorI(logger, pool, new BookI(logger), new LibraryI(logger));
adapter.add(new SessionFactoryI(logger, reaper), communicator().stringToIdentity("SessionFactory"));
+ adapter.add(new Glacier2SessionManagerI(logger, reaper), communicator().stringToIdentity("LibrarySessionManager"));
adapter.addServantLocator(locator, "book");
adapter.addServantLocator(locator, "library");
diff --git a/java/demo/Database/library/Session.ice b/java/demo/Database/library/Session.ice
new file mode 100644
index 00000000000..f833c9d0394
--- /dev/null
+++ b/java/demo/Database/library/Session.ice
@@ -0,0 +1,72 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2008 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 LIBRARY_SESSION_ICE
+#define LIBRARY_SESSION_ICE
+
+module Demo
+{
+
+/* Forward declaration. */
+interface Library;
+
+/**
+ *
+ * The session object. This is used to retrieve a per-session library
+ * on behalf of the client. If the session is not refreshed on a
+ * periodic basis, it will be automatically destroyed.
+ *
+ */
+interface Session
+{
+ /**
+ *
+ * Get the library object.
+ *
+ * @return A proxy for the new library.
+ *
+ **/
+ Library* getLibrary();
+
+ /**
+ *
+ * Refresh a session. If a session is not refreshed on a regular
+ * basis by the client, it will be automatically destroyed.
+ *
+ **/
+ idempotent void refresh();
+
+ /**
+ *
+ * Destroy the session.
+ *
+ **/
+ void destroy();
+};
+
+/**
+ *
+ * Interface to create new sessions.
+ *
+ **/
+interface SessionFactory
+{
+ /**
+ *
+ * Create a session.
+ *
+ * @return A proxy to the session.
+ *
+ **/
+ Session* create();
+};
+
+};
+
+#endif
diff --git a/java/demo/Database/library/SessionFactoryI.java b/java/demo/Database/library/SessionFactoryI.java
index f3e6c934b33..f8463b5cdb6 100644
--- a/java/demo/Database/library/SessionFactoryI.java
+++ b/java/demo/Database/library/SessionFactoryI.java
@@ -11,22 +11,23 @@ import Demo.*;
class SessionFactoryI extends _SessionFactoryDisp
{
- SessionFactoryI(Ice.Logger logger, ReapThread reaper)
- {
- _logger = logger;
- _reaper = reaper;
- }
-
public synchronized SessionPrx
create(Ice.Current c)
{
SessionI session = new SessionI(_logger, c.adapter);
- SessionPrx proxy = SessionPrxHelper.uncheckedCast(c.adapter.addWithUUID(session));
+ _SessionTie servant = new _SessionTie(session);
+ SessionPrx proxy = SessionPrxHelper.uncheckedCast(c.adapter.addWithUUID(servant));
_logger.trace("SessionFactory", "create new session: " + proxy.ice_getIdentity());
_reaper.add(proxy, session);
return proxy;
}
+ SessionFactoryI(Ice.Logger logger, ReapThread reaper)
+ {
+ _logger = logger;
+ _reaper = reaper;
+ }
+
private Ice.Logger _logger;
private ReapThread _reaper;
}
diff --git a/java/demo/Database/library/SessionI.java b/java/demo/Database/library/SessionI.java
index 5b94172b2c0..f5bc36702d4 100644
--- a/java/demo/Database/library/SessionI.java
+++ b/java/demo/Database/library/SessionI.java
@@ -9,7 +9,7 @@
import Demo.*;
-class SessionI extends _SessionDisp
+class SessionI implements _SessionOperations, _Glacier2SessionOperations
{
static public SessionI
getSession(Ice.Identity id)
diff --git a/java/demo/Database/library/build.xml b/java/demo/Database/library/build.xml
index cd874693901..5497ed50a9e 100644
--- a/java/demo/Database/library/build.xml
+++ b/java/demo/Database/library/build.xml
@@ -20,24 +20,15 @@
<target name="generate" depends="init">
<!-- Create the output directory for generated code -->
<mkdir dir="${generated.dir}"/>
- <slice2java outputdir="${generated.dir}">
+ <slice2java outputdir="${generated.dir}" tie="on">
<meta value="${java2metadata}"/>
<includepath>
<pathelement path="${slice.dir}" />
</includepath>
<fileset dir="." includes="Library.ice"/>
+ <fileset dir="." includes="Session.ice"/>
+ <fileset dir="." includes="Glacier2Session.ice"/>
</slice2java>
- <slice2freezej ice="on" outputdir="${generated.dir}">
- <meta value="${java2metadata}"/>
- <includepath>
- <pathelement path="${slice.dir}" />
- </includepath>
- <fileset dir="${slice.dir}/Ice">
- <include name="BuiltinSequences.ice" />
- </fileset>
- <fileset dir="." includes="Library.ice"/>
- <dict name="StringIsbnSeqDict" key="string" value="Ice::StringSeq"/>
- </slice2freezej>
</target>
<target name="compile" depends="generate">
diff --git a/java/demo/Database/library/config.client b/java/demo/Database/library/config.client
index 93ae62d757e..7041c592de8 100644
--- a/java/demo/Database/library/config.client
+++ b/java/demo/Database/library/config.client
@@ -2,7 +2,25 @@
# The client reads this property to create the reference to the
# "SessionFactory" object in the server.
#
-SessionFactory.Proxy=SessionFactory:default -p 10000
+#SessionFactory.Proxy=SessionFactory:default -p 10000
+
+#
+# The proxy to the Glacier2 router for all outgoing connections. This
+# must match the value of Glacier2.Client.Endpoints in config.glacier2.
+#
+Ice.Default.Router=DemoGlacier2/router:ssl -p 4064 -h 127.0.0.1
+
+#
+# No active connection management is permitted with Glacier2.
+# Connections must remain established.
+#
+Ice.ACM.Client=0
+
+#
+# Connection retry is not possible with Glacier2. Connections must
+# remain established.
+#
+Ice.RetryIntervals=-1
#
# Warn about connection exceptions
@@ -26,3 +44,20 @@ Ice.Warn.Connections=1
# 1 = trace protocol messages
#
#Ice.Trace.Protocol=1
+
+#
+# Security Tracing
+#
+# 0 = no security tracing
+# 1 = trace messages
+#
+#IceSSL.Trace.Security=1
+
+#
+# SSL Configuration
+#
+Ice.Plugin.IceSSL=IceSSL.PluginFactory
+IceSSL.DefaultDir=../../../../certs
+IceSSL.Keystore=client.jks
+IceSSL.Password=password
+IceSSL.Truststore=certs.jks