summaryrefslogtreecommitdiff
path: root/java/demo
diff options
context:
space:
mode:
Diffstat (limited to 'java/demo')
-rw-r--r--java/demo/Database/README6
-rw-r--r--java/demo/Database/library/LibraryI.java3
-rw-r--r--java/demo/Database/library/Scanner.java2
-rw-r--r--java/demo/Database/library/Server.java7
-rw-r--r--java/demo/Freeze/bench/build.xml5
-rw-r--r--java/demo/Freeze/casino/Client.java16
-rw-r--r--java/demo/Freeze/casino/build.xml5
-rw-r--r--java/demo/Freeze/library/Collocated.java2
-rw-r--r--java/demo/Freeze/library/Scanner.java2
-rw-r--r--java/demo/Freeze/library/Server.java2
-rw-r--r--java/demo/Freeze/library/build.xml5
-rw-r--r--java/demo/Freeze/phonebook/Collocated.java2
-rw-r--r--java/demo/Freeze/phonebook/Scanner.java2
-rw-r--r--java/demo/Freeze/phonebook/Server.java2
-rw-r--r--java/demo/Freeze/phonebook/build.xml9
-rw-r--r--java/demo/Freeze/transform/build.xml5
-rw-r--r--java/demo/Glacier2/callback/CallbackI.java2
-rw-r--r--java/demo/Ice/README5
-rw-r--r--java/demo/Ice/applet/HelloApplet.java18
-rw-r--r--java/demo/Ice/applet/README75
-rw-r--r--java/demo/Ice/applet/build.xml4
-rw-r--r--java/demo/Ice/applet/hello.html6
-rw-r--r--java/demo/Ice/build.xml2
-rw-r--r--java/demo/Ice/callback/CallbackSenderI.java2
-rw-r--r--java/demo/Ice/nested/NestedI.java2
-rw-r--r--java/demo/Ice/protobuf/Client.java127
-rw-r--r--java/demo/Ice/protobuf/Hello.ice27
-rw-r--r--java/demo/Ice/protobuf/HelloI.java26
-rw-r--r--java/demo/Ice/protobuf/Person.proto18
-rw-r--r--java/demo/Ice/protobuf/README41
-rw-r--r--java/demo/Ice/protobuf/Server.java37
-rw-r--r--java/demo/Ice/protobuf/ant/ProtocTask.java367
-rw-r--r--java/demo/Ice/protobuf/build.xml63
-rw-r--r--java/demo/Ice/protobuf/config.client23
-rw-r--r--java/demo/Ice/protobuf/config.server24
-rwxr-xr-xjava/demo/Ice/protobuf/expect.py30
-rw-r--r--java/demo/Ice/serialize/Client.java142
-rw-r--r--java/demo/Ice/serialize/Demo/MyGreeting.java15
-rw-r--r--java/demo/Ice/serialize/Greet.ice26
-rw-r--r--java/demo/Ice/serialize/GreetI.java33
-rw-r--r--java/demo/Ice/serialize/README37
-rw-r--r--java/demo/Ice/serialize/Server.java37
-rw-r--r--java/demo/Ice/serialize/build.xml52
-rw-r--r--java/demo/Ice/serialize/config.client28
-rw-r--r--java/demo/Ice/serialize/config.server29
-rwxr-xr-xjava/demo/Ice/serialize/expect.py30
-rw-r--r--java/demo/Ice/value/Client.java6
-rw-r--r--java/demo/book/README18
-rw-r--r--java/demo/book/freeze_filesystem/Client.java31
-rw-r--r--java/demo/book/freeze_filesystem/DirectoryI.java24
-rw-r--r--java/demo/book/freeze_filesystem/FileI.java29
-rw-r--r--java/demo/book/freeze_filesystem/Server.java3
-rw-r--r--java/demo/book/freeze_filesystem/build.xml5
-rw-r--r--java/demo/book/lifecycle/FilesystemI/DirectoryI.java200
-rw-r--r--java/demo/book/lifecycle/FilesystemI/FileI.java18
-rw-r--r--java/demo/book/lifecycle/Parser.java2
-rw-r--r--java/demo/book/lifecycle/Scanner.java2
-rw-r--r--java/demo/book/lifecycle/Server.java6
-rw-r--r--java/demo/book/simple_filesystem/Filesystem/DirectoryI.java3
-rw-r--r--java/demo/book/simple_filesystem/Filesystem/FileI.java3
60 files changed, 1484 insertions, 269 deletions
diff --git a/java/demo/Database/README b/java/demo/Database/README
new file mode 100644
index 00000000000..676202f8cf8
--- /dev/null
+++ b/java/demo/Database/README
@@ -0,0 +1,6 @@
+Demos in this directory:
+
+- library
+
+ This demo shows how to implement an Ice server that uses mysql through
+ a JDBC API.
diff --git a/java/demo/Database/library/LibraryI.java b/java/demo/Database/library/LibraryI.java
index 81bae5c6de7..9ec48815b36 100644
--- a/java/demo/Database/library/LibraryI.java
+++ b/java/demo/Database/library/LibraryI.java
@@ -90,7 +90,8 @@ class LibraryI extends _LibraryDisp
}
// Build a query that finds all books by these authors.
- StringBuffer sb = new StringBuffer("(");
+ StringBuilder sb = new StringBuilder(128);
+ sb.append("(");
boolean front = true;
do
{
diff --git a/java/demo/Database/library/Scanner.java b/java/demo/Database/library/Scanner.java
index 879396725b4..ecf325de077 100644
--- a/java/demo/Database/library/Scanner.java
+++ b/java/demo/Database/library/Scanner.java
@@ -151,7 +151,7 @@ class Scanner
return null;
}
- StringBuffer buf = new StringBuffer();
+ StringBuilder buf = new StringBuilder(128);
if(c == ';' || c == '\n')
{
diff --git a/java/demo/Database/library/Server.java b/java/demo/Database/library/Server.java
index b2e66386ffa..4763f589010 100644
--- a/java/demo/Database/library/Server.java
+++ b/java/demo/Database/library/Server.java
@@ -9,7 +9,7 @@
import Demo.*;
-class LibraryServer extends Ice.Application
+class Server extends Ice.Application
{
static class LocatorI implements Ice.ServantLocator
{
@@ -129,14 +129,11 @@ class LibraryServer extends Ice.Application
return 0;
}
-}
-public class Server
-{
static public void
main(String[] args)
{
- LibraryServer app = new LibraryServer();
+ Server app = new Server();
app.main("demo.Database.library.Server", args, "config.server");
}
}
diff --git a/java/demo/Freeze/bench/build.xml b/java/demo/Freeze/bench/build.xml
index 420ed9850c5..309f7c9ed9c 100644
--- a/java/demo/Freeze/bench/build.xml
+++ b/java/demo/Freeze/bench/build.xml
@@ -57,7 +57,10 @@
<mkdir dir="${class.dir}"/>
<javac srcdir="${generated.dir}" destdir="${class.dir}"
debug="${debug}">
- <classpath refid="ice.classpath"/>
+ <classpath>
+ <path refid="ice.classpath"/>
+ <path refid="db.classpath"/>
+ </classpath>
<compilerarg value="${javac.lint}"/>
</javac>
<javac srcdir="." destdir="${class.dir}"
diff --git a/java/demo/Freeze/casino/Client.java b/java/demo/Freeze/casino/Client.java
index d5e5965c31f..0f0fd53bf95 100644
--- a/java/demo/Freeze/casino/Client.java
+++ b/java/demo/Freeze/casino/Client.java
@@ -9,6 +9,14 @@
public class Client extends Ice.Application
{
+ //
+ // Number of bets placed by each player
+ // You can (should) increase these values by a factor of 5 or more
+ // on a fast system
+ //
+ static final int betCount1 = 100;
+ static final int betCount2 = 20;
+
private void
printBalances(Casino.PlayerPrx[] players)
{
@@ -79,10 +87,10 @@ public class Client extends Ice.Application
System.out.println("All chips accounted for? " + (bank.checkAllChips() ? "yes" : "no"));
- System.out.print("Create 500 10-chips bets... ");
+ System.out.print("Create " + betCount1 + " 10-chips bets... ");
System.out.flush();
- for(int b = 0; b < 500; ++b)
+ for(int b = 0; b < betCount1; ++b)
{
Casino.BetPrx bet = bank.createBet(10, 200 + random.nextInt(4000));
for(int i = 0; i < players.length; ++i)
@@ -147,10 +155,10 @@ public class Client extends Ice.Application
System.out.println("Live bets: " + bank.getLiveBetCount());
- System.out.print("Create 100 10-chips bets... ");
+ System.out.print("Create " + betCount2 + " 10-chips bets... ");
System.out.flush();
- for(int b = 0; b < 100; ++b)
+ for(int b = 0; b < betCount2; ++b)
{
Casino.BetPrx bet = bank.createBet(10, 200 + random.nextInt(4000));
for(int i = 0; i < players.length; ++i)
diff --git a/java/demo/Freeze/casino/build.xml b/java/demo/Freeze/casino/build.xml
index cec4df18549..c5e1ed1536f 100644
--- a/java/demo/Freeze/casino/build.xml
+++ b/java/demo/Freeze/casino/build.xml
@@ -39,7 +39,10 @@
</javac>
<javac srcdir="." destdir="${class.dir}"
excludes="generated/**" debug="${debug}">
- <classpath refid="ice.classpath"/>
+ <classpath>
+ <path refid="ice.classpath"/>
+ <path refid="db.classpath"/>
+ </classpath>
<compilerarg value="${javac.lint}"/>
</javac>
</target>
diff --git a/java/demo/Freeze/library/Collocated.java b/java/demo/Freeze/library/Collocated.java
index 7e275e1d229..8629e894d7a 100644
--- a/java/demo/Freeze/library/Collocated.java
+++ b/java/demo/Freeze/library/Collocated.java
@@ -64,7 +64,7 @@ class Collocated extends Ice.Application
// Create and install a factory and initializer for books.
//
Ice.ObjectFactory bookFactory = new BookFactory(library);
- communicator().addObjectFactory(bookFactory, "::Demo::Book");
+ communicator().addObjectFactory(bookFactory, Demo.Book.ice_staticId());
//
// Everything ok, let's go.
diff --git a/java/demo/Freeze/library/Scanner.java b/java/demo/Freeze/library/Scanner.java
index 975eaece2dd..ff61f1289da 100644
--- a/java/demo/Freeze/library/Scanner.java
+++ b/java/demo/Freeze/library/Scanner.java
@@ -155,7 +155,7 @@ class Scanner
return null;
}
- StringBuffer buf = new StringBuffer();
+ StringBuilder buf = new StringBuilder(128);
if(c == ';' || c == '\n')
{
diff --git a/java/demo/Freeze/library/Server.java b/java/demo/Freeze/library/Server.java
index 2edfb823034..7af7e3a8a61 100644
--- a/java/demo/Freeze/library/Server.java
+++ b/java/demo/Freeze/library/Server.java
@@ -47,7 +47,7 @@ class Server extends Ice.Application
// Create and install a factory for books.
//
Ice.ObjectFactory bookFactory = new BookFactory(library);
- communicator().addObjectFactory(bookFactory, "::Demo::Book");
+ communicator().addObjectFactory(bookFactory, Demo.Book.ice_staticId());
//
// Everything ok, let's go.
diff --git a/java/demo/Freeze/library/build.xml b/java/demo/Freeze/library/build.xml
index ae9ae29f883..41ec51eeafa 100644
--- a/java/demo/Freeze/library/build.xml
+++ b/java/demo/Freeze/library/build.xml
@@ -49,7 +49,10 @@
</javac>
<javac srcdir="." destdir="${class.dir}"
excludes="generated/**" debug="${debug}">
- <classpath refid="ice.classpath"/>
+ <classpath>
+ <path refid="ice.classpath"/>
+ <path refid="db.classpath"/>
+ </classpath>
<compilerarg value="${javac.lint}"/>
</javac>
</target>
diff --git a/java/demo/Freeze/phonebook/Collocated.java b/java/demo/Freeze/phonebook/Collocated.java
index 47abe391520..9d1b316ddfd 100644
--- a/java/demo/Freeze/phonebook/Collocated.java
+++ b/java/demo/Freeze/phonebook/Collocated.java
@@ -41,7 +41,7 @@ class Collocated extends Ice.Application
// Create and install a factory for contacts.
//
ContactFactory contactFactory = new ContactFactory();
- communicator().addObjectFactory(contactFactory, "::Demo::Contact");
+ communicator().addObjectFactory(contactFactory, Demo.Contact.ice_staticId());
//
// Create an object adapter
diff --git a/java/demo/Freeze/phonebook/Scanner.java b/java/demo/Freeze/phonebook/Scanner.java
index db438f8fe5f..790a672f7b0 100644
--- a/java/demo/Freeze/phonebook/Scanner.java
+++ b/java/demo/Freeze/phonebook/Scanner.java
@@ -155,7 +155,7 @@ class Scanner
return null;
}
- StringBuffer buf = new StringBuffer();
+ StringBuilder buf = new StringBuilder(128);
if(c == ';' || c == '\n')
{
diff --git a/java/demo/Freeze/phonebook/Server.java b/java/demo/Freeze/phonebook/Server.java
index 3dbf0d0d0d1..692b465da7f 100644
--- a/java/demo/Freeze/phonebook/Server.java
+++ b/java/demo/Freeze/phonebook/Server.java
@@ -24,7 +24,7 @@ class Server extends Ice.Application
// Create and install a factory for contacts.
//
ContactFactory contactFactory = new ContactFactory();
- communicator().addObjectFactory(contactFactory, "::Demo::Contact");
+ communicator().addObjectFactory(contactFactory, Demo.Contact.ice_staticId());
//
// Create an object adapter
diff --git a/java/demo/Freeze/phonebook/build.xml b/java/demo/Freeze/phonebook/build.xml
index 233435b6cde..c5616897bdd 100644
--- a/java/demo/Freeze/phonebook/build.xml
+++ b/java/demo/Freeze/phonebook/build.xml
@@ -41,12 +41,19 @@
<mkdir dir="${class.dir}"/>
<javac srcdir="${generated.dir}" destdir="${class.dir}"
debug="${debug}">
- <classpath refid="ice.classpath"/>
+ <classpath>
+ <path refid="ice.classpath"/>
+ <path refid="db.classpath"/>
+ </classpath>
<compilerarg value="${javac.lint}"/>
</javac>
<javac srcdir="." destdir="${class.dir}"
excludes="generated/**" debug="${debug}">
<classpath refid="ice.classpath"/>
+ <classpath>
+ <path refid="ice.classpath"/>
+ <path refid="db.classpath"/>
+ </classpath>
<compilerarg value="${javac.lint}"/>
</javac>
</target>
diff --git a/java/demo/Freeze/transform/build.xml b/java/demo/Freeze/transform/build.xml
index cf84d604e26..0250da01c04 100644
--- a/java/demo/Freeze/transform/build.xml
+++ b/java/demo/Freeze/transform/build.xml
@@ -43,7 +43,10 @@
<mkdir dir="${class.dir}"/>
<javac srcdir="${generated.dir}" destdir="${class.dir}"
debug="${debug}">
- <classpath refid="ice.classpath"/>
+ <classpath>
+ <path refid="ice.classpath"/>
+ <path refid="db.classpath"/>
+ </classpath>
<compilerarg value="${javac.lint}"/>
</javac>
<javac srcdir="." destdir="${class.dir}"
diff --git a/java/demo/Glacier2/callback/CallbackI.java b/java/demo/Glacier2/callback/CallbackI.java
index 2013f349ded..1dd07491790 100644
--- a/java/demo/Glacier2/callback/CallbackI.java
+++ b/java/demo/Glacier2/callback/CallbackI.java
@@ -17,7 +17,7 @@ public final class CallbackI extends _CallbackDisp
System.out.println("initiating callback to: " + current.adapter.getCommunicator().proxyToString(proxy));
try
{
- proxy.callback(current.ctx);
+ proxy.callback();
}
catch(Ice.LocalException ex)
{
diff --git a/java/demo/Ice/README b/java/demo/Ice/README
index 6a9eceee376..5714a88aa20 100644
--- a/java/demo/Ice/README
+++ b/java/demo/Ice/README
@@ -52,6 +52,11 @@ Demos in this directory:
A demo to illustrate how nested callbacks work, and how the size of
the thread pool affects the maximum nesting depth.
+- serialize
+
+ This demo illustrates how to transfer serializable Java classes
+ with Ice.
+
- session
This demo shows how to use sessions to clean up client-specific
diff --git a/java/demo/Ice/applet/HelloApplet.java b/java/demo/Ice/applet/HelloApplet.java
index 504f775a148..dd351a7918d 100644
--- a/java/demo/Ice/applet/HelloApplet.java
+++ b/java/demo/Ice/applet/HelloApplet.java
@@ -46,24 +46,10 @@ public class HelloApplet extends JApplet
initData.properties.setProperty("Ice.Trace.Network", "3");
initData.properties.setProperty("IceSSL.Trace.Security", "3");
initData.properties.setProperty("IceSSL.Password", "password");
- initData.properties.setProperty("Ice.InitPlugins", "0");
+ initData.properties.setProperty("IceSSL.Keystore", "client.jks");
+ initData.properties.setProperty("IceSSL.Truststore", "client.jks");
initData.properties.setProperty("Ice.Plugin.IceSSL", "IceSSL.PluginFactory");
_communicator = Ice.Util.initialize(initData);
-
- //
- // We delayed the initialization of the IceSSL plug-in by setting Ice.InitPlugins=0.
- // Now we obtain a reference to the plugin so that we can supply a keystore and
- // truststore using a resource file.
- //
- IceSSL.Plugin plugin = (IceSSL.Plugin)_communicator.getPluginManager().getPlugin("IceSSL");
- java.io.InputStream certs = getClass().getClassLoader().getResourceAsStream("client.jks");
- plugin.setKeystoreStream(certs);
- plugin.setTruststoreStream(certs);
-
- //
- // Finally, we're ready to complete the initialization.
- //
- _communicator.getPluginManager().initializePlugins();
}
catch(Throwable ex)
{
diff --git a/java/demo/Ice/applet/README b/java/demo/Ice/applet/README
index dbf2e18ff20..9bda261e7c3 100644
--- a/java/demo/Ice/applet/README
+++ b/java/demo/Ice/applet/README
@@ -1,8 +1,15 @@
+Introduction
+------------
+
This demo presents an unsigned applet that shows how to make
asynchronous Ice invocations in a graphical application. It also
demonstrates how to configure IceSSL using a resource file as the
keystore.
+
+Preparing the applet
+--------------------
+
The demo includes a start page (hello.html) that you will need to
publish on a web server. This page assumes that the demo applet is
stored in a fully self-contained archive named Hello.jar. In order to
@@ -11,7 +18,7 @@ with ProGuard in your CLASSPATH. After a successful build, copy
Hello.jar from this subdirectory to the same directory as hello.html
on your web server.
-NOTE: We recommend using ProGuard 4.3 or later.
+NOTE: If you use ProGuard, you must use version 4.3 or later.
If you did not build the applet with ProGuard in your CLASSPATH, the
Hello.jar archive contains only the applet classes. In this case you
@@ -26,19 +33,63 @@ applet with the following commands:
ant clean
ant
-To run the demo, you must start a "hello" server on the web server
-host. You can use the hello server from the ../hello directory or
-a hello server from any other Ice language mapping. Note that you may
-need to temporarily relax the firewall restrictions on your web server
-host to allow the applet to establish connections to the hello server.
-Next, start a web browser and open the hello.html page on your web
-server.
+
+Preparing the Ice server
+------------------------
+
+The applet requires a "hello" server. You can use the Java server
+from the ../hello directory or a hello server from any other Ice
+language mapping. You may need to temporarily relax the firewall
+restrictions on your server host to allow the applet to establish
+connections to the hello server.
+
+
+Loading the applet locally
+--------------------------
+
+The simplest way to use the applet is to open the start page
+(hello.html) as a local file directly from your browser. In this case,
+you must start the hello server on the same host and enter "localhost"
+or "127.0.0.1" as the server host name in the applet.
+
+Note however that the applet security manager in some versions of Java
+may prevent the applet from connecting to the local host. If the
+applet reports a SocketException error in its status bar, open the
+Java console and review the exception stack trace. The most likely
+occurrence is an "access denied" error, which indicates that the
+security manager rejected the applet's connection attempt. You can
+solve this issue by temporarily granting for the applet to connect to
+the local machine. For example, if you are using JRE6 on Windows, open
+the following file:
+
+ C:\Program Files\Java\jre6\lib\security\java.policy
+
+In the "grant" section, add the line shown below:
+
+ permission java.net.SocketPermission "localhost:1024-", "connect,resolve";
+
+Restart your browser and try the applet again. If the applet still
+cannot establish a connection, try loading it from a web server
+instead.
+
+
+Loading the applet from a web server
+------------------------------------
+
+Start a hello server on the web server host. Next, start a web browser
+and open the start page (hello.html) on your web server.
Once the applet has started, verify that the name of your web server
-host is correct in the "Hostname" field and press the "Hello World!"
-button. You will notice that the server prints a "Hello World!"
-message to the console for each invocation. To make other types of Ice
-invocations, select a different mode from the combobox.
+host is shown correctly in the "Hostname" field.
+
+
+Using the applet
+----------------
+
+Press the "Hello World!" button. You will notice that the server
+prints a "Hello World!" message to the console for each invocation. To
+make other types of Ice invocations, select a different mode from the
+combobox.
The two sliders allow you to experiment with various timeout settings.
The "Timeout" slider determines how long the Ice run time will wait
diff --git a/java/demo/Ice/applet/build.xml b/java/demo/Ice/applet/build.xml
index 495021109ad..adfc97057af 100644
--- a/java/demo/Ice/applet/build.xml
+++ b/java/demo/Ice/applet/build.xml
@@ -52,7 +52,7 @@
<include name="Demo/**"/>
<include name="HelloApplet*"/>
</jar>
- <jar jarfile="Hello.jar" update="true" basedir="${top.dir}/../certs">
+ <jar jarfile="Hello.jar" update="true" basedir="${certs.dir}">
<include name="client.jks"/>
</jar>
</target>
@@ -80,7 +80,7 @@
<proguard configuration="applet.pro">
<injar path="${class.dir}"/>
- <injar path="${top.dir}/../certs/client.jks"/>
+ <injar path="${certs.dir}/client.jks"/>
<injar refid="ice.classpath" filter="!META-INF/**"/>
<outjar path="Hello.jar"/>
<libraryjar path="${library.jars}"/>
diff --git a/java/demo/Ice/applet/hello.html b/java/demo/Ice/applet/hello.html
index c0a48d8f38f..4ebae2dce92 100644
--- a/java/demo/Ice/applet/hello.html
+++ b/java/demo/Ice/applet/hello.html
@@ -7,7 +7,7 @@
<object
classid = "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
codebase = "http://java.sun.com/update/1.5.0/jinstall-1_5-windows-i586.cab#Version=1,5,0,0"
- WIDTH = 300 HEIGHT = 175 >
+ WIDTH = 350 HEIGHT = 215 >
<PARAM NAME = CODE VALUE = "HelloApplet" >
<param name = "type" value = "application/x-java-applet;version=1.5">
<param name = "scriptable" value = "false">
@@ -18,8 +18,8 @@
type = "application/x-java-applet;version=1.5" \
CODE = "HelloApplet" \
ARCHIVE = "Hello.jar" \
- WIDTH = 300 \
- HEIGHT = 175
+ WIDTH = 350 \
+ HEIGHT = 215
scriptable = false
pluginspage = "http://java.sun.com/products/plugin/index.html#download">
<noembed>
diff --git a/java/demo/Ice/build.xml b/java/demo/Ice/build.xml
index a8f43061344..c101f7c9627 100644
--- a/java/demo/Ice/build.xml
+++ b/java/demo/Ice/build.xml
@@ -22,6 +22,7 @@
<ant dir="minimal"/>
<ant dir="multicast"/>
<ant dir="nested"/>
+ <ant dir="serialize"/>
<ant dir="session"/>
<ant dir="throughput"/>
<ant dir="value"/>
@@ -38,6 +39,7 @@
<ant dir="minimal" target="clean"/>
<ant dir="multicast" target="clean"/>
<ant dir="nested" target="clean"/>
+ <ant dir="serialize" target="clean"/>
<ant dir="session" target="clean"/>
<ant dir="throughput" target="clean"/>
<ant dir="value" target="clean"/>
diff --git a/java/demo/Ice/callback/CallbackSenderI.java b/java/demo/Ice/callback/CallbackSenderI.java
index d30d40b5ce6..fe86e7beb9e 100644
--- a/java/demo/Ice/callback/CallbackSenderI.java
+++ b/java/demo/Ice/callback/CallbackSenderI.java
@@ -17,7 +17,7 @@ public final class CallbackSenderI extends _CallbackSenderDisp
System.out.println("initiating callback");
try
{
- proxy.callback(current.ctx);
+ proxy.callback();
}
catch(Ice.LocalException ex)
{
diff --git a/java/demo/Ice/nested/NestedI.java b/java/demo/Ice/nested/NestedI.java
index 023cffce52f..7ba7cfabbdf 100644
--- a/java/demo/Ice/nested/NestedI.java
+++ b/java/demo/Ice/nested/NestedI.java
@@ -22,7 +22,7 @@ class NestedI extends _NestedDisp
System.out.println("" + level);
if(--level > 0)
{
- proxy.nestedCall(level, _self, current.ctx);
+ proxy.nestedCall(level, _self);
}
}
diff --git a/java/demo/Ice/protobuf/Client.java b/java/demo/Ice/protobuf/Client.java
new file mode 100644
index 00000000000..cbdbb7aca2b
--- /dev/null
+++ b/java/demo/Ice/protobuf/Client.java
@@ -0,0 +1,127 @@
+// **********************************************************************
+//
+// 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.*;
+
+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 greeting\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 hello = HelloPrxHelper.checkedCast(communicator().propertyToProxy("Hello.Proxy"));
+ if(hello == null)
+ {
+ System.err.println("invalid proxy");
+ return 1;
+ }
+
+ tutorial.PersonPB.Person p = tutorial.PersonPB.Person.newBuilder().
+ setId(1).setName("Fred Jones").setEmail("fred@jones.com").build();
+
+ 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"))
+ {
+ hello.sayHello(p);
+ }
+ else if(line.equals("s"))
+ {
+ hello.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/protobuf/Hello.ice b/java/demo/Ice/protobuf/Hello.ice
new file mode 100644
index 00000000000..8ddbbbd34ae
--- /dev/null
+++ b/java/demo/Ice/protobuf/Hello.ice
@@ -0,0 +1,27 @@
+// **********************************************************************
+//
+// 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 HELLO_ICE
+#define HELLO_ICE
+
+module Demo
+{
+
+["cpp:protobuf:tutorial::Person", "java:protobuf:tutorial.PersonPB.Person", "python:protobuf:Person_pb2.Person"]
+sequence<byte> Person;
+
+interface Hello
+{
+ idempotent void sayHello(Person p);
+ void shutdown();
+};
+
+};
+
+#endif
diff --git a/java/demo/Ice/protobuf/HelloI.java b/java/demo/Ice/protobuf/HelloI.java
new file mode 100644
index 00000000000..e3fcf7008bb
--- /dev/null
+++ b/java/demo/Ice/protobuf/HelloI.java
@@ -0,0 +1,26 @@
+// **********************************************************************
+//
+// 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.*;
+
+public class HelloI extends _HelloDisp
+{
+ public void
+ sayHello(tutorial.PersonPB.Person p, Ice.Current current)
+ {
+ System.out.println("Hello World from " + p);
+ }
+
+ public void
+ shutdown(Ice.Current current)
+ {
+ System.out.println("Shutting down...");
+ current.adapter.getCommunicator().shutdown();
+ }
+}
diff --git a/java/demo/Ice/protobuf/Person.proto b/java/demo/Ice/protobuf/Person.proto
new file mode 100644
index 00000000000..6ee58a3f246
--- /dev/null
+++ b/java/demo/Ice/protobuf/Person.proto
@@ -0,0 +1,18 @@
+// **********************************************************************
+//
+// 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.
+//
+// **********************************************************************
+
+package tutorial;
+
+option java_outer_classname = "PersonPB";
+
+message Person {
+ required int32 id = 1;
+ required string name = 2;
+ optional string email = 3;
+}
diff --git a/java/demo/Ice/protobuf/README b/java/demo/Ice/protobuf/README
new file mode 100644
index 00000000000..5ab7020aa68
--- /dev/null
+++ b/java/demo/Ice/protobuf/README
@@ -0,0 +1,41 @@
+This demo shows how to integrate Google Protocol Buffers with Ice.
+
+The Protocol Buffers distribution and documentation can be found at
+
+ http://code.google.com/apis/protocolbuffers/
+
+This demo was tested with Protocol Buffers version 2.0.3.
+
+We have added new metadata that makes it possible for you to specify
+protocol buffers message types in your Slice definitions, with Ice
+handling the serialization chores for you automatically. The metadata,
+which may only be used on a sequence<byte> type, has the following
+syntax in Java:
+
+ java:protobuf:protoc-generated-class
+
+For example:
+
+ ["java:protobuf:tutorial.PersonPB.Person"] sequence<byte> Person;
+
+The type name specified in this example, tutorial.PersonPB.Person,
+corresponds to the Java class generated by the Protocol Buffers
+compiler (protoc) for the definition shown below:
+
+ package tutorial;
+ option java_outer_classname = "PersonPB";
+ message Person { ... };
+
+This demo uses an ant build task, located in the "ant" subdirectory,
+for compiling .proto files.
+
+Prior to building the demo, you should add protoc to your PATH and
+protobuf-java-2.0.3.jar to your CLASSPATH.
+
+To run the demo, first start the server:
+
+ $ java Server
+
+In a separate window, start the client:
+
+ $ java Client
diff --git a/java/demo/Ice/protobuf/Server.java b/java/demo/Ice/protobuf/Server.java
new file mode 100644
index 00000000000..6ffab5d02fb
--- /dev/null
+++ b/java/demo/Ice/protobuf/Server.java
@@ -0,0 +1,37 @@
+// **********************************************************************
+//
+// 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.*;
+
+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/protobuf/ant/ProtocTask.java b/java/demo/Ice/protobuf/ant/ProtocTask.java
new file mode 100644
index 00000000000..b102cb9fccd
--- /dev/null
+++ b/java/demo/Ice/protobuf/ant/ProtocTask.java
@@ -0,0 +1,367 @@
+// **********************************************************************
+//
+// 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.
+//
+// **********************************************************************
+
+//package Ice.Ant;
+
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.taskdefs.ExecTask;
+import org.apache.tools.ant.taskdefs.Execute;
+import org.apache.tools.ant.taskdefs.PumpStreamHandler;
+import org.apache.tools.ant.types.Commandline;
+import org.apache.tools.ant.types.Commandline.Argument;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.Reference;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.StringReader;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+
+/**
+ * An ant task for protoc.
+ *
+ * Attributes specific to protoc:
+ *
+ * translator - The pathname of the translator (default: "protoc").
+ * protocpath - The value for the --proto_path translator option.
+ * outputdir - The value for the --java_out translator option.
+ * dependencyfile - The file in which dependencies are stored (default: ".pbdepend").
+ *
+ * Example:
+ *
+ * <project ...>
+ * <taskdef name="protoc" classname="ProtocTask" />
+ * <property name="protoc.dir" value="../include/protoc"/>
+ * <target name="generate">
+ * <mkdir dir="tags" />
+ * <protoc tagdir="tags" outputdir="out">
+ * <fileset dir="${protoc.dir}">
+ * <include name="*.ice" />
+ * </fileset>
+ * </protoc>
+ * </target>
+ * </project>
+ *
+ * The <taskdef> element installs the protoctask task.
+ */
+public class ProtocTask extends org.apache.tools.ant.Task
+{
+ public
+ ProtocTask()
+ {
+ _translator = null;
+ _outputDir = null;
+ _protocPath = null;
+ _outputDirString = null;
+ }
+
+ public void
+ setDependencyFile(File file)
+ {
+ _dependencyFile = file;
+ }
+
+ public void
+ setOutputdir(File dir)
+ {
+ _outputDir = dir;
+ _outputDirString = _outputDir.toString();
+ if(_outputDirString.indexOf(' ') != -1)
+ {
+ _outputDirString = '"' + _outputDirString + '"';
+ }
+ }
+
+ public void
+ setProtocpath(File dir)
+ {
+ _protocPath = dir.toString();
+ }
+
+ public void
+ setTranslator(File prog)
+ {
+ _translator = prog;
+ }
+
+ public FileSet
+ createFileset()
+ {
+ FileSet fileset = new FileSet();
+ _fileSets.add(fileset);
+
+ return fileset;
+ }
+
+ public void
+ execute()
+ throws BuildException
+ {
+ if(_fileSets.isEmpty())
+ {
+ throw new BuildException("No fileset specified");
+ }
+
+ //
+ // Read the set of dependencies for this task.
+ //
+ java.util.HashMap dependencies = readDependencies();
+
+ //
+ // Compose a list of the files that need to be translated. A
+ // file needs to translated if we can't find a dependency in
+ // the dependency table or if its dependency is not up-to-date
+ // anymore (the proto file changed since the dependency was
+ // last updated)
+ //
+ java.util.Vector buildList = new java.util.Vector();
+ java.util.Vector skipList = new java.util.Vector();
+ java.util.Iterator p = _fileSets.iterator();
+ while(p.hasNext())
+ {
+ FileSet fileset = (FileSet)p.next();
+
+ DirectoryScanner scanner = fileset.getDirectoryScanner(getProject());
+ scanner.scan();
+ String[] files = scanner.getIncludedFiles();
+ for(int i = 0; i < files.length; i++)
+ {
+ File proto = new File(fileset.getDir(getProject()), files[i]);
+
+ ProtoDependency depend = (ProtoDependency)dependencies.get(getTargetKey(proto.toString()));
+ if(depend == null || !depend.isUpToDate())
+ {
+ buildList.addElement(proto);
+ }
+ else
+ {
+ skipList.addElement(proto);
+ }
+ }
+
+ java.util.Iterator i = skipList.iterator();
+ while(i.hasNext())
+ {
+ File file = (File)i.next();
+ log("skipping " + file.getName());
+ }
+ }
+
+ //
+ // Run the translator
+ //
+ if(!buildList.isEmpty())
+ {
+ String translator;
+ if(_translator == null)
+ {
+ translator = "protoc";
+ }
+ else
+ {
+ translator = _translator.toString();
+ }
+
+ StringBuilder cmd = new StringBuilder(128);
+
+ //
+ // Add --java_out.
+ //
+ if(_outputDir != null)
+ {
+ cmd.append(" --java_out=");
+ cmd.append(stripDriveLetter(_outputDirString));
+ }
+
+ //
+ // Add --proto_path
+ //
+ if(_protocPath != null)
+ {
+ cmd.append(" --proto_path=");
+ cmd.append(stripDriveLetter(_protocPath));
+ }
+
+ //
+ // Add files to be translated
+ //
+ for(int i = 0; i < buildList.size(); i++)
+ {
+ File f = (File)buildList.elementAt(i);
+ cmd.append(" ");
+ String s = stripDriveLetter(f.toString());
+ if(s.indexOf(' ') != -1)
+ {
+ cmd.append('"' + s + '"');
+ }
+ else
+ {
+ cmd.append(s);
+ }
+ }
+
+ //
+ // Execute
+ //
+ log(translator + " " + cmd);
+ ExecTask task = (ExecTask)getProject().createTask("exec");
+ task.setFailonerror(true);
+ Argument arg = task.createArg();
+ arg.setLine(cmd.toString());
+ task.setExecutable(translator);
+ task.execute();
+
+ //
+ // Update dependency file.
+ //
+ for(int i = 0; i < buildList.size(); i++)
+ {
+ ProtoDependency depend = new ProtoDependency();
+ depend._timeStamp = new java.util.Date().getTime();
+ depend._dependency = ((File)buildList.elementAt(i)).toString();
+ dependencies.put(getTargetKey(depend._dependency), depend);
+ }
+
+ writeDependencies(dependencies);
+ }
+ }
+
+ private String
+ getTargetKey(String proto)
+ {
+ //
+ // Since the dependency file can be shared by several proto
+ // tasks we need to make sure that each dependency has a
+ // unique key. We use the name of the task, the output
+ // directory and the name of the proto file to be compiled.
+ //
+ // If there's two protoc tasks using the same dependency
+ // file, with the same output dir and which compiles the same
+ // protoc file they'll use the same dependency.
+ //
+ return "protoc " + _outputDir.toString() + " " + proto;
+ }
+
+ // This is to work around a bug with protoc, where it does not
+ // accept drive letters in path names. See
+ // http://bugzilla/bugzilla/show_bug.cgi?id=3349
+ //
+ private String
+ stripDriveLetter(String s)
+ {
+ if(s.length() > 1 && s.charAt(1) == ':')
+ {
+ return s.substring(2);
+ }
+ return s;
+ }
+
+ //
+ // Read the dependency file.
+ //
+ private java.util.HashMap
+ readDependencies()
+ {
+ if(_dependencyFile == null)
+ {
+ if(_outputDir != null)
+ {
+ _dependencyFile = new File(_outputDir, ".pbdepend");
+ }
+ else
+ {
+ _dependencyFile = new File(".pbdepend");
+ }
+ }
+
+ try
+ {
+ java.io.ObjectInputStream in = new java.io.ObjectInputStream(new java.io.FileInputStream(_dependencyFile));
+ java.util.HashMap dependencies = (java.util.HashMap)in.readObject();
+ in.close();
+ return dependencies;
+ }
+ catch(java.io.IOException ex)
+ {
+ }
+ catch(java.lang.ClassNotFoundException ex)
+ {
+ }
+
+ return new java.util.HashMap();
+ }
+
+ private void
+ writeDependencies(java.util.HashMap dependencies)
+ {
+ try
+ {
+ java.io.ObjectOutputStream out = new java.io.ObjectOutputStream(new FileOutputStream(_dependencyFile));
+ out.writeObject(dependencies);
+ out.close();
+ }
+ catch(java.io.IOException ex)
+ {
+ throw new BuildException("Unable to write dependencies in file " + _dependencyFile.getPath() + ": " + ex);
+ }
+ }
+
+ //
+ // A proto dependency.
+ //
+ // * the _timeStamp attribute contains the last time the proto
+ // file was compiled.
+ //
+ // * the _dependency attribute contains the .proto file.
+ //
+ private class ProtoDependency implements java.io.Serializable
+ {
+ private void writeObject(java.io.ObjectOutputStream out)
+ throws java.io.IOException
+ {
+ out.writeObject(_dependency);
+ out.writeLong(_timeStamp);
+ }
+
+ private void readObject(java.io.ObjectInputStream in)
+ throws java.io.IOException, java.lang.ClassNotFoundException
+ {
+ _dependency = (String)in.readObject();
+ _timeStamp = in.readLong();
+ }
+
+ public boolean
+ isUpToDate()
+ {
+ File dep = new File(_dependency);
+ if(!dep.exists() || _timeStamp < dep.lastModified())
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public String _dependency;
+ public long _timeStamp;
+ }
+
+ private File _translator;
+ private File _dependencyFile;
+ private File _outputDir;
+ private String _outputDirString;
+ private String _protocPath;
+ private java.util.List _fileSets = new java.util.LinkedList();
+}
diff --git a/java/demo/Ice/protobuf/build.xml b/java/demo/Ice/protobuf/build.xml
new file mode 100644
index 00000000000..aa336420300
--- /dev/null
+++ b/java/demo/Ice/protobuf/build.xml
@@ -0,0 +1,63 @@
+<!--
+ **********************************************************************
+
+ 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.
+
+ **********************************************************************
+-->
+
+<project name="demo_Ice_protobuf" 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="protoc" depends="init">
+ <!-- Build protoc task -->
+ <mkdir dir="${class.dir}"/>
+ <javac srcdir="ant" destdir="${class.dir}" debug="${debug}">
+ <compilerarg value="${javac.lint}"/>
+ </javac>
+ </target>
+
+ <target name="generate" depends="protoc">
+ <!-- Add the protoc task -->
+ <taskdef name="protoc" classpath="${class.dir}" classname="ProtocTask" />
+ <!-- Create the output directory for generated code -->
+ <mkdir dir="${generated.dir}"/>
+ <slice2java outputdir="${generated.dir}">
+ <meta value="${java2metadata}"/>
+ <fileset dir="." includes="Hello.ice"/>
+ </slice2java>
+ <protoc outputdir="${generated.dir}" protocpath=".">
+ <fileset dir="." includes="Person.proto"/>
+ </protoc>
+ </target>
+
+ <target name="compile" depends="generate">
+ <mkdir dir="${class.dir}"/>
+ <javac srcdir="${generated.dir}" destdir="${class.dir}"
+ debug="${debug}">
+ <classpath refid="ice.classpath"/>
+ <compilerarg value="${javac.lint}"/>
+ </javac>
+ <javac srcdir="." destdir="${class.dir}"
+ excludes="generated/**, ant/**" debug="${debug}">
+ <classpath refid="ice.classpath"/>
+ <compilerarg value="${javac.lint}"/>
+ </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/protobuf/config.client b/java/demo/Ice/protobuf/config.client
new file mode 100644
index 00000000000..a02cab0f4cb
--- /dev/null
+++ b/java/demo/Ice/protobuf/config.client
@@ -0,0 +1,23 @@
+#
+# The client reads this property to create the reference to the
+# "hello" object in the server.
+#
+Hello.Proxy=hello:tcp -p 10000
+
+#
+# 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/protobuf/config.server b/java/demo/Ice/protobuf/config.server
new file mode 100644
index 00000000000..309db9731b2
--- /dev/null
+++ b/java/demo/Ice/protobuf/config.server
@@ -0,0 +1,24 @@
+#
+# The server creates one single object adapter with the name
+# "Hello". The following line sets the endpoints for this
+# adapter.
+#
+Hello.Endpoints=tcp -p 10000
+
+#
+# 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/protobuf/expect.py b/java/demo/Ice/protobuf/expect.py
new file mode 100755
index 00000000000..60dabda57bf
--- /dev/null
+++ b/java/demo/Ice/protobuf/expect.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+# **********************************************************************
+#
+# Copyright (c) 2003-2009 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
+
+path = [ ".", "..", "../..", "../../..", "../../../.." ]
+head = os.path.dirname(sys.argv[0])
+if len(head) > 0:
+ path = [os.path.join(head, p) for p in path]
+path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "demoscript")) ]
+if len(path) == 0:
+ raise "can't find toplevel directory!"
+sys.path.append(path[0])
+
+from demoscript import *
+from demoscript.Ice import protobuf
+
+server = Util.spawn('java Server --Ice.PrintAdapterReady --Ice.Warn.Connections=0')
+server.expect('.* ready')
+client = Util.spawn('java Client --Ice.Warn.Connections=0')
+client.expect('.*==>')
+
+protobuf.run(client, server)
diff --git a/java/demo/Ice/serialize/Client.java b/java/demo/Ice/serialize/Client.java
new file mode 100644
index 00000000000..e5c6ce82fb0
--- /dev/null
+++ b/java/demo/Ice/serialize/Client.java
@@ -0,0 +1,142 @@
+// **********************************************************************
+//
+// 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.*;
+
+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" +
+ "g: send greeting\n" +
+ "t: toggle null greeting\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());
+
+ GreetPrx greet = GreetPrxHelper.checkedCast(communicator().propertyToProxy("Greet.Proxy"));
+ if(greet == null) {
+
+ System.err.println("invalid proxy");
+ return 1;
+ }
+
+ MyGreeting greeting = new MyGreeting();
+ greeting.text = "Hello there!";
+ MyGreeting nullGreeting = null;
+
+ boolean sendNull = false;
+
+ 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("g"))
+ {
+ if(sendNull)
+ {
+ greet.sendGreeting(nullGreeting);
+ }
+ else
+ {
+ greet.sendGreeting(greeting);
+ }
+ }
+ else if(line.equals("t"))
+ {
+ sendNull = !sendNull;
+ }
+ else if(line.equals("s"))
+ {
+ greet.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/serialize/Demo/MyGreeting.java b/java/demo/Ice/serialize/Demo/MyGreeting.java
new file mode 100644
index 00000000000..bbefc3e687b
--- /dev/null
+++ b/java/demo/Ice/serialize/Demo/MyGreeting.java
@@ -0,0 +1,15 @@
+// **********************************************************************
+//
+// 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.
+//
+// **********************************************************************
+
+package Demo;
+
+public class MyGreeting implements java.io.Serializable
+{
+ public String text;
+}
diff --git a/java/demo/Ice/serialize/Greet.ice b/java/demo/Ice/serialize/Greet.ice
new file mode 100644
index 00000000000..e06d9d04f6d
--- /dev/null
+++ b/java/demo/Ice/serialize/Greet.ice
@@ -0,0 +1,26 @@
+// **********************************************************************
+//
+// 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 GREET_ICE
+#define GREET_ICE
+
+module Demo
+{
+
+["java:serializable:Demo.MyGreeting"] sequence<byte> Greeting;
+
+interface Greet
+{
+ idempotent void sendGreeting(Greeting g);
+ void shutdown();
+};
+
+};
+
+#endif
diff --git a/java/demo/Ice/serialize/GreetI.java b/java/demo/Ice/serialize/GreetI.java
new file mode 100644
index 00000000000..855af5173f5
--- /dev/null
+++ b/java/demo/Ice/serialize/GreetI.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.*;
+
+public class GreetI extends _GreetDisp
+{
+ public void
+ sendGreeting(MyGreeting greeting, Ice.Current current)
+ {
+ if(greeting != null)
+ {
+ System.out.println(greeting.text);
+ }
+ else
+ {
+ System.out.println("Received null greeting");
+ }
+ }
+
+ public void
+ shutdown(Ice.Current current)
+ {
+ System.out.println("Shutting down...");
+ current.adapter.getCommunicator().shutdown();
+ }
+}
diff --git a/java/demo/Ice/serialize/README b/java/demo/Ice/serialize/README
new file mode 100644
index 00000000000..c472c81bef0
--- /dev/null
+++ b/java/demo/Ice/serialize/README
@@ -0,0 +1,37 @@
+This demo illustrates how to transfer serializable Java classes
+with Ice.
+
+The Java classes are transferred as byte sequences by Ice. It was
+always possible to do this, but required you to explicitly serialize
+your class into a byte sequence and then pass that sequence to your
+operations to be deserialized by the receiver. You can now accomplish
+the same thing more conveniently via metadata.
+
+In your Slice definitions, you must declare a byte sequence using the
+"java:serializable" metadata and specify the Java class name, as shown
+below:
+
+["java:serializable:JavaClassName"] sequence<byte> SliceType;
+
+Now, wherever you use the declared Slice type in your operations or
+data types, you can supply an instance of the designated Java class
+and Ice automatically converts it to and from the byte sequence that
+is passed over the wire. (The Java class you pass must derive from
+java.io.Serializable.)
+
+With the "java:serializable" metadata, if you have a serializable
+class as an out-parameter, the out-parameter is passed as
+Ice.Holder<JavaClassName>. For example, if you have a Java class
+MyPackage.Car as an out-parameter, the out-parameter is passed as
+Ice.Holder<MyPackage.Car>.
+
+To run the demo, first start the server:
+
+$ java Server
+
+In a separate window, start the client:
+
+$ java Client
+
+The client allows you to toggle between sending a real class instance
+and sending a null value, to show that passing null is supported.
diff --git a/java/demo/Ice/serialize/Server.java b/java/demo/Ice/serialize/Server.java
new file mode 100644
index 00000000000..6550ea79a6d
--- /dev/null
+++ b/java/demo/Ice/serialize/Server.java
@@ -0,0 +1,37 @@
+// **********************************************************************
+//
+// 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.*;
+
+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("Greet");
+ adapter.add(new GreetI(), communicator().stringToIdentity("greet"));
+ 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/serialize/build.xml b/java/demo/Ice/serialize/build.xml
new file mode 100644
index 00000000000..96b3470fb12
--- /dev/null
+++ b/java/demo/Ice/serialize/build.xml
@@ -0,0 +1,52 @@
+<!--
+ **********************************************************************
+
+ 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.
+
+ **********************************************************************
+-->
+
+<project name="demo_Ice_serialize" 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="Greet.ice"/>
+ </slice2java>
+ </target>
+
+ <target name="compile" depends="generate">
+ <mkdir dir="${class.dir}"/>
+ <javac srcdir="." destdir="${class.dir}" includes="Demo/**" debug="${debug}">
+ <classpath refid="ice.classpath"/>
+ <compilerarg value="${javac.lint}"/>
+ </javac>
+ <javac srcdir="${generated.dir}" destdir="${class.dir}" debug="${debug}">
+ <classpath refid="ice.classpath"/>
+ <compilerarg value="${javac.lint}"/>
+ </javac>
+ <javac srcdir="." destdir="${class.dir}" excludes="generated/**,Serialize/**" debug="${debug}">
+ <classpath refid="ice.classpath"/>
+ <compilerarg value="${javac.lint}"/>
+ </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/serialize/config.client b/java/demo/Ice/serialize/config.client
new file mode 100644
index 00000000000..cdf6f093e41
--- /dev/null
+++ b/java/demo/Ice/serialize/config.client
@@ -0,0 +1,28 @@
+#
+# The client reads this property to create the reference to the
+# "greet" object in the server.
+#
+Greet.Proxy=greet:tcp -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/serialize/config.server b/java/demo/Ice/serialize/config.server
new file mode 100644
index 00000000000..41bfe6caa46
--- /dev/null
+++ b/java/demo/Ice/serialize/config.server
@@ -0,0 +1,29 @@
+#
+# The server creates one single object adapter with the name
+# "Greet". The following line sets the endpoints for this
+# adapter.
+#
+Greet.Endpoints=tcp -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/serialize/expect.py b/java/demo/Ice/serialize/expect.py
new file mode 100755
index 00000000000..76bc8e43408
--- /dev/null
+++ b/java/demo/Ice/serialize/expect.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+# **********************************************************************
+#
+# Copyright (c) 2003-2009 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
+
+path = [ ".", "..", "../..", "../../..", "../../../.." ]
+head = os.path.dirname(sys.argv[0])
+if len(head) > 0:
+ path = [os.path.join(head, p) for p in path]
+path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "demoscript")) ]
+if len(path) == 0:
+ raise "can't find toplevel directory!"
+sys.path.append(path[0])
+
+from demoscript import *
+from demoscript.Ice import serialize
+
+server = Util.spawn('java Server --Ice.PrintAdapterReady --Ice.Warn.Connections=0')
+server.expect('.* ready')
+client = Util.spawn('java Client --Ice.Warn.Connections=0')
+client.expect('.*==>')
+
+serialize.run(client, server)
diff --git a/java/demo/Ice/value/Client.java b/java/demo/Ice/value/Client.java
index dbac804ad37..58ee94fcdbc 100644
--- a/java/demo/Ice/value/Client.java
+++ b/java/demo/Ice/value/Client.java
@@ -104,7 +104,7 @@ public class Client extends Ice.Application
readline(in);
Ice.ObjectFactory factory = new ObjectFactory();
- communicator().addObjectFactory(factory, "::Demo::Printer");
+ communicator().addObjectFactory(factory, Demo.Printer.ice_staticId());
initial.getPrinter(printer, printerProxy);
System.out.println("==> " + printer.value.message);
@@ -136,7 +136,7 @@ public class Client extends Ice.Application
Printer derivedAsBase = initial.getDerivedPrinter();
System.out.println("==> The type ID of the received object is \"" + derivedAsBase.ice_id() + "\"");
- assert(derivedAsBase.ice_id().equals("::Demo::Printer"));
+ assert(derivedAsBase.ice_id().equals(Demo.Printer.ice_staticId()));
System.out.println();
System.out.println("Now we install a factory for the derived class, and try again.");
@@ -145,7 +145,7 @@ public class Client extends Ice.Application
System.out.println("[press enter]");
readline(in);
- communicator().addObjectFactory(factory, "::Demo::DerivedPrinter");
+ communicator().addObjectFactory(factory, Demo.DerivedPrinter.ice_staticId());
derivedAsBase = initial.getDerivedPrinter();
DerivedPrinter derived = (Demo.DerivedPrinter)derivedAsBase;
diff --git a/java/demo/book/README b/java/demo/book/README
index bbace203f6d..3d58a2ba06f 100644
--- a/java/demo/book/README
+++ b/java/demo/book/README
@@ -6,6 +6,15 @@ Demos in this directory:
the Ice Run Time chapter. You can copy and modify this code to
suit your needs.
+- freeze_filesystem
+
+ An implementation of the persistent version of the file system
+ example described in the Freeze chapter.
+
+- lifecycle
+
+ An implementation of the file system that supports life cycle operations.
+
- printer
An implementation of the simple printer example at the beginning of
@@ -15,12 +24,3 @@ Demos in this directory:
An implementation of the simple (non-persistent, non-life-cycle)
version of the file system example.
-
-- lifecycle
-
- An implementation of the file system that supports life cycle operations.
-
-- freeze_filesystem
-
- An implementation of the persistent version of the file system
- example described in the Freeze chapter.
diff --git a/java/demo/book/freeze_filesystem/Client.java b/java/demo/book/freeze_filesystem/Client.java
index b665940d541..2c0056e1451 100644
--- a/java/demo/book/freeze_filesystem/Client.java
+++ b/java/demo/book/freeze_filesystem/Client.java
@@ -79,9 +79,10 @@ public class Client extends Ice.Application
//
// Create a file called "README" in the root directory.
//
+ FilePrx readme = null;
try
{
- FilePrx readme = rootDir.createFile("README");
+ readme = rootDir.createFile("README");
String[] text = new String[1];
text[0] = "This file system contains a collection of poetry.";
readme.write(text);
@@ -89,9 +90,9 @@ public class Client extends Ice.Application
}
catch(NameInUse ex)
{
- //
- // Ignore - file already exists.
- //
+ NodeDesc desc = rootDir.find("README");
+ readme = FilePrxHelper.checkedCast(desc.proxy);
+ assert(readme != null);
}
//
@@ -113,9 +114,10 @@ public class Client extends Ice.Application
//
// Create a file called "Kubla_Khan" in the Coleridge directory.
//
+ FilePrx file = null;
try
{
- FilePrx file = coleridge.createFile("Kubla_Khan");
+ file = coleridge.createFile("Kubla_Khan");
String[] text = new String[5];
text[0] = "In Xanadu did Kubla Khan";
text[1] = "A stately pleasure-dome decree:";
@@ -127,9 +129,9 @@ public class Client extends Ice.Application
}
catch(NameInUse ex)
{
- //
- // Ignore - file already exists.
- //
+ NodeDesc desc = coleridge.find("Kubla_Khan");
+ file = FilePrxHelper.checkedCast(desc.proxy);
+ assert(file != null);
}
System.out.println("Contents of filesystem:");
@@ -138,13 +140,12 @@ public class Client extends Ice.Application
//
// Destroy the filesystem.
//
- NodeDesc[] contents = rootDir.list();
- for(int i = 0; i < contents.length; ++i)
- {
- NodeDesc d = contents[i];
- System.out.println("Destroying " + d.name);
- d.proxy.destroy();
- }
+ System.out.println("Destroying " + file.name());
+ file.destroy();
+ System.out.println("Destroying " + readme.name());
+ readme.destroy();
+ System.out.println("Destroying " + coleridge.name());
+ coleridge.destroy();
}
catch(Ice.UserException ex)
{
diff --git a/java/demo/book/freeze_filesystem/DirectoryI.java b/java/demo/book/freeze_filesystem/DirectoryI.java
index 03d9d3039c2..2a3ca7c9c17 100644
--- a/java/demo/book/freeze_filesystem/DirectoryI.java
+++ b/java/demo/book/freeze_filesystem/DirectoryI.java
@@ -42,34 +42,22 @@ public final class DirectoryI extends PersistentDirectory
{
if(parent == null)
{
- throw new PermissionDenied("cannot remove root directory");
+ throw new PermissionDenied("cannot destroy root directory");
}
- java.util.Map children = null;
-
synchronized(this)
{
if(_destroyed)
{
throw new Ice.ObjectNotExistException(current.id, current.facet, current.operation);
}
-
- children = (java.util.Map)((java.util.HashMap)nodes).clone();
- _destroyed = true;
- }
-
- //
- // For consistency with C++, we iterate over the children outside of synchronization.
- //
- java.util.Iterator p = children.values().iterator();
- while(p.hasNext())
- {
- NodeDesc desc = (NodeDesc)p.next();
- desc.proxy.destroy();
+ if(!nodes.isEmpty())
+ {
+ throw new PermissionDenied("cannot destroy non-empty directory");
+ }
+ _destroyed = true;
}
- assert(nodes.isEmpty());
-
parent.removeNode(nodeName);
_evictor.remove(_id);
}
diff --git a/java/demo/book/freeze_filesystem/FileI.java b/java/demo/book/freeze_filesystem/FileI.java
index 12c92654a1b..8b84ae13b34 100644
--- a/java/demo/book/freeze_filesystem/FileI.java
+++ b/java/demo/book/freeze_filesystem/FileI.java
@@ -14,17 +14,24 @@ public final class FileI extends PersistentFile
public
FileI()
{
+ _destroyed = false;
}
public
FileI(Ice.Identity id)
{
_id = id;
+ _destroyed = false;
}
- public String
+ public synchronized String
name(Ice.Current current)
{
+ if(_destroyed)
+ {
+ throw new Ice.ObjectNotExistException(current.id, current.facet, current.operation);
+ }
+
return nodeName;
}
@@ -32,6 +39,15 @@ public final class FileI extends PersistentFile
destroy(Ice.Current current)
throws PermissionDenied
{
+ synchronized(this)
+ {
+ if(_destroyed)
+ {
+ throw new Ice.ObjectNotExistException(current.id, current.facet, current.operation);
+ }
+ _destroyed = true;
+ }
+
parent.removeNode(nodeName);
_evictor.remove(_id);
}
@@ -39,6 +55,11 @@ public final class FileI extends PersistentFile
public synchronized String[]
read(Ice.Current current)
{
+ if(_destroyed)
+ {
+ throw new Ice.ObjectNotExistException(current.id, current.facet, current.operation);
+ }
+
return (String[])text.clone();
}
@@ -46,9 +67,15 @@ public final class FileI extends PersistentFile
write(String[] text, Ice.Current current)
throws GenericError
{
+ if(_destroyed)
+ {
+ throw new Ice.ObjectNotExistException(current.id, current.facet, current.operation);
+ }
+
this.text = text;
}
public static Freeze.Evictor _evictor;
public Ice.Identity _id;
+ private boolean _destroyed;
}
diff --git a/java/demo/book/freeze_filesystem/Server.java b/java/demo/book/freeze_filesystem/Server.java
index 10deb39e8a6..da37b3d4664 100644
--- a/java/demo/book/freeze_filesystem/Server.java
+++ b/java/demo/book/freeze_filesystem/Server.java
@@ -38,7 +38,8 @@ public class Server extends Ice.Application
// static member).
//
Freeze.ServantInitializer init = new NodeInitializer();
- Freeze.Evictor evictor = Freeze.Util.createBackgroundSaveEvictor(adapter, _envName, "evictorfs", init, null, true);
+ Freeze.Evictor evictor = Freeze.Util.createTransactionalEvictor(adapter, _envName, "evictorfs",
+ null, init, null, true);
DirectoryI._evictor = evictor;
FileI._evictor = evictor;
diff --git a/java/demo/book/freeze_filesystem/build.xml b/java/demo/book/freeze_filesystem/build.xml
index 3b0e0824433..51564430850 100644
--- a/java/demo/book/freeze_filesystem/build.xml
+++ b/java/demo/book/freeze_filesystem/build.xml
@@ -39,7 +39,10 @@
</javac>
<javac srcdir="." destdir="${class.dir}"
excludes="generated/**" debug="${debug}">
- <classpath refid="ice.classpath"/>
+ <classpath>
+ <path refid="ice.classpath"/>
+ <path refid="db.classpath"/>
+ </classpath>
<compilerarg value="${javac.lint}"/>
</javac>
</target>
diff --git a/java/demo/book/lifecycle/FilesystemI/DirectoryI.java b/java/demo/book/lifecycle/FilesystemI/DirectoryI.java
index f1745305e0b..410bbafcd9d 100644
--- a/java/demo/book/lifecycle/FilesystemI/DirectoryI.java
+++ b/java/demo/book/lifecycle/FilesystemI/DirectoryI.java
@@ -12,7 +12,7 @@ package FilesystemI;
import Ice.*;
import Filesystem.*;
-public class DirectoryI extends _DirectoryDisp implements NodeI, _DirectoryOperations
+public class DirectoryI extends _DirectoryDisp implements NodeI
{
// Slice name() operation.
@@ -37,115 +37,91 @@ public class DirectoryI extends _DirectoryDisp implements NodeI, _DirectoryOpera
// Slice list() operation.
- public NodeDesc[]
+ public synchronized NodeDesc[]
list(Current c)
{
- synchronized(this)
+ if(_destroyed)
{
- if(_destroyed)
- {
- throw new ObjectNotExistException();
- }
+ throw new ObjectNotExistException();
}
- synchronized(_lcMutex)
+ NodeDesc[] ret = new NodeDesc[_contents.size()];
+ java.util.Iterator<java.util.Map.Entry<String, NodeI> > pos = _contents.entrySet().iterator();
+ for(int i = 0; i < _contents.size(); ++i)
{
- reap();
-
- NodeDesc[] ret = new NodeDesc[_contents.size()];
- java.util.Iterator<java.util.Map.Entry<String, NodeI> > pos = _contents.entrySet().iterator();
- for(int i = 0; i < _contents.size(); ++i)
- {
- java.util.Map.Entry<String, NodeI> e = pos.next();
- NodeI p = e.getValue();
- ret[i] = new NodeDesc();
- ret[i].name = e.getKey();
- ret[i].type = p instanceof FileI ? NodeType.FileType : NodeType.DirType;
- ret[i].proxy = NodePrxHelper.uncheckedCast(c.adapter.createProxy(p.id()));
- }
- return ret;
+ java.util.Map.Entry<String, NodeI> e = pos.next();
+ NodeI p = e.getValue();
+ ret[i] = new NodeDesc();
+ ret[i].name = e.getKey();
+ ret[i].type = p instanceof FileI ? NodeType.FileType : NodeType.DirType;
+ ret[i].proxy = NodePrxHelper.uncheckedCast(c.adapter.createProxy(p.id()));
}
+ return ret;
}
// Slice find() operation.
- public NodeDesc
+ public synchronized NodeDesc
find(String name, Current c) throws NoSuchName
{
- synchronized(this)
+ if(_destroyed)
{
- if(_destroyed)
- {
- throw new ObjectNotExistException();
- }
+ throw new ObjectNotExistException();
}
- synchronized(_lcMutex)
+ NodeI p = _contents.get(name);
+ if(p == null)
{
- reap();
-
- NodeI p = (NodeI)_contents.get(name);
- if(p == null)
- {
- throw new NoSuchName(name);
- }
-
- NodeDesc d = new NodeDesc();
- d.name = name;
- d.type = p instanceof FileI ? NodeType.FileType : NodeType.DirType;
- d.proxy = NodePrxHelper.uncheckedCast(c.adapter.createProxy(p.id()));
- return d;
+ throw new NoSuchName(name);
}
+
+ NodeDesc d = new NodeDesc();
+ d.name = name;
+ d.type = p instanceof FileI ? NodeType.FileType : NodeType.DirType;
+ d.proxy = NodePrxHelper.uncheckedCast(c.adapter.createProxy(p.id()));
+ return d;
}
// Slice createFile() operation.
- public FilePrx
+ public synchronized FilePrx
createFile(String name, Current c) throws NameInUse
{
- synchronized(this)
+ if(_destroyed)
{
- if(_destroyed)
- {
- throw new ObjectNotExistException();
- }
+ throw new ObjectNotExistException();
}
- synchronized(_lcMutex)
+ if(name.length() == 0 || _contents.containsKey(name))
{
- reap();
-
- if(_contents.containsKey(name))
- {
- throw new NameInUse(name);
- }
- return new FileI(name, this).activate(c.adapter);
+ throw new NameInUse(name);
}
+
+ FileI f = new FileI(name, this);
+ ObjectPrx node = c.adapter.add(f, f.id());
+ _contents.put(name, f);
+ return FilePrxHelper.uncheckedCast(node);
}
// Slice createDirectory() operation.
- public DirectoryPrx
+ public synchronized DirectoryPrx
createDirectory(String name, Current c) throws NameInUse
{
- synchronized(this)
+ if(_destroyed)
{
- if(_destroyed)
- {
- throw new ObjectNotExistException();
- }
+ throw new ObjectNotExistException();
}
- synchronized(_lcMutex)
+ if(name.length() == 0 || _contents.containsKey(name))
{
- reap();
-
- if(_contents.containsKey(name))
- {
- throw new NameInUse(name);
- }
- return new DirectoryI(name, this).activate(c.adapter);
+ throw new NameInUse(name);
}
+
+ DirectoryI d = new DirectoryI(name, this);
+ ObjectPrx node = c.adapter.add(d, d.id());
+ _contents.put(name, d);
+ return DirectoryPrxHelper.uncheckedCast(node);
}
// Slice destroy() operation.
@@ -165,20 +141,16 @@ public class DirectoryI extends _DirectoryDisp implements NodeI, _DirectoryOpera
throw new ObjectNotExistException();
}
- synchronized(_lcMutex)
+ if(_contents.size() != 0)
{
- reap();
-
- if(_contents.size() != 0)
- {
- throw new PermissionDenied("Cannot destroy non-empty directory");
- }
-
- c.adapter.remove(id());
- _parent.addReapEntry(_name);
- _destroyed = true;
+ throw new PermissionDenied("Cannot destroy non-empty directory");
}
+
+ c.adapter.remove(id());
+ _destroyed = true;
}
+
+ _parent.removeEntry(_name);
}
// DirectoryI constructor for root directory.
@@ -201,75 +173,17 @@ public class DirectoryI extends _DirectoryDisp implements NodeI, _DirectoryOpera
_id.name = parent == null ? "RootDir" : java.util.UUID.randomUUID().toString();
}
+ // Remove the entry from the _contents map.
- // Add servant to ASM and to parent's _contents map.
-
- public DirectoryPrx
- activate(Ice.ObjectAdapter a)
+ public synchronized void
+ removeEntry(String name)
{
- DirectoryPrx node = DirectoryPrxHelper.uncheckedCast(a.add(this, _id));
- if(_parent != null)
- {
- _parent.addChild(_name, this);
- }
- return node;
+ _contents.remove(name);
}
- // Add the name-node pair to the _contents map.
-
- public void
- addChild(String name, NodeI node)
- {
- _contents.put(name, node);
- }
-
- // Add this directory and the name of a deleted entry to the reap map.
-
- public void
- addReapEntry(String name)
- {
- java.util.List<String> l = _reapMap.get(this);
- if(l != null)
- {
- l.add(name);
- }
- else
- {
- l = new java.util.ArrayList<String>();
- l.add(name);
- _reapMap.put(this, l);
- }
- }
-
- // Remove all names in the reap map from the corresponding directory contents.
-
- private static void
- reap()
- {
- java.util.Iterator<java.util.Map.Entry<DirectoryI, java.util.List<String> > > i =
- _reapMap.entrySet().iterator();
- while(i.hasNext())
- {
- java.util.Map.Entry<DirectoryI, java.util.List<String> > e = i.next();
- DirectoryI dir = e.getKey();
- java.util.List<String> l = e.getValue();
- java.util.Iterator<String> j = l.iterator();
- while(j.hasNext())
- {
- dir._contents.remove(j.next());
- }
- }
- _reapMap.clear();
- }
-
- public static java.lang.Object _lcMutex = new java.lang.Object();
-
private String _name; // Immutable
private DirectoryI _parent; // Immutable
private Identity _id; // Immutable
private boolean _destroyed;
private java.util.Map<String, NodeI> _contents;
-
- private static java.util.Map<DirectoryI, java.util.List<String> > _reapMap =
- new java.util.HashMap<DirectoryI, java.util.List<String> >();
}
diff --git a/java/demo/book/lifecycle/FilesystemI/FileI.java b/java/demo/book/lifecycle/FilesystemI/FileI.java
index 0994fdc6e8f..4bc98683b12 100644
--- a/java/demo/book/lifecycle/FilesystemI/FileI.java
+++ b/java/demo/book/lifecycle/FilesystemI/FileI.java
@@ -13,7 +13,7 @@ import Ice.*;
import Filesystem.*;
import FilesystemI.*;
-public class FileI extends _FileDisp implements NodeI, _FileOperations
+public class FileI extends _FileDisp implements NodeI
{
public synchronized String
name(Current c)
@@ -62,14 +62,12 @@ public class FileI extends _FileDisp implements NodeI, _FileOperations
{
throw new ObjectNotExistException();
}
- _destroyed = true;
- }
- synchronized(_parent._lcMutex)
- {
c.adapter.remove(id());
- _parent.addReapEntry(_name);
+ _destroyed = true;
}
+
+ _parent.removeEntry(_name);
}
public FileI(String name, DirectoryI parent)
@@ -81,14 +79,6 @@ public class FileI extends _FileDisp implements NodeI, _FileOperations
_id.name = java.util.UUID.randomUUID().toString();
}
- public FilePrx
- activate(Ice.ObjectAdapter a)
- {
- FilePrx node = FilePrxHelper.uncheckedCast(a.add(this, _id));
- _parent.addChild(_name, this);
- return node;
- }
-
private String _name;
private DirectoryI _parent;
private boolean _destroyed;
diff --git a/java/demo/book/lifecycle/Parser.java b/java/demo/book/lifecycle/Parser.java
index 3bf9e0965dd..96800a88040 100644
--- a/java/demo/book/lifecycle/Parser.java
+++ b/java/demo/book/lifecycle/Parser.java
@@ -50,7 +50,7 @@ class Parser
void
list(Filesystem.DirectoryPrx dir, boolean recursive, int depth)
{
- StringBuffer b = new StringBuffer();
+ StringBuilder b = new StringBuilder();
for(int i = 0; i < depth; ++i)
{
b.append('\t');
diff --git a/java/demo/book/lifecycle/Scanner.java b/java/demo/book/lifecycle/Scanner.java
index 3283176018d..c4c695fcd8b 100644
--- a/java/demo/book/lifecycle/Scanner.java
+++ b/java/demo/book/lifecycle/Scanner.java
@@ -151,7 +151,7 @@ class Scanner
return null;
}
- StringBuffer buf = new StringBuffer();
+ StringBuilder buf = new StringBuilder(128);
if(c == ';' || c == '\n')
{
diff --git a/java/demo/book/lifecycle/Server.java b/java/demo/book/lifecycle/Server.java
index afa26093a42..6e3286ebafb 100644
--- a/java/demo/book/lifecycle/Server.java
+++ b/java/demo/book/lifecycle/Server.java
@@ -27,15 +27,17 @@ class Server extends Ice.Application
// Create the root directory.
//
DirectoryI root = new DirectoryI();
- root.activate(adapter);
+ Ice.Identity id = new Ice.Identity();
+ id.name = "RootDir";
+ adapter.add(root, id);
// All objects are created, allow client requests now.
//
adapter.activate();
- //
// Wait until we are done.
+ //
communicator().waitForShutdown();
if(interrupted())
{
diff --git a/java/demo/book/simple_filesystem/Filesystem/DirectoryI.java b/java/demo/book/simple_filesystem/Filesystem/DirectoryI.java
index 5b7ee2e8668..f52f8f28a38 100644
--- a/java/demo/book/simple_filesystem/Filesystem/DirectoryI.java
+++ b/java/demo/book/simple_filesystem/Filesystem/DirectoryI.java
@@ -21,7 +21,8 @@ public final class DirectoryI extends _DirectoryDisp
// Create an identity. The root directory has the fixed identity "RootDir"
//
- _id = communicator.stringToIdentity(_parent != null ? java.util.UUID.randomUUID().toString() : "RootDir");
+ _id = new Ice.Identity();
+ _id.name = _parent != null ? java.util.UUID.randomUUID().toString() : "RootDir";
}
diff --git a/java/demo/book/simple_filesystem/Filesystem/FileI.java b/java/demo/book/simple_filesystem/Filesystem/FileI.java
index a90f681be86..69bb0684363 100644
--- a/java/demo/book/simple_filesystem/Filesystem/FileI.java
+++ b/java/demo/book/simple_filesystem/Filesystem/FileI.java
@@ -23,7 +23,8 @@ public class FileI extends _FileDisp
// Create an identity
//
- _id = communicator.stringToIdentity(java.util.UUID.randomUUID().toString());
+ _id = new Ice.Identity();
+ _id.name = java.util.UUID.randomUUID().toString();
}
// Slice Node::name() operation