diff options
Diffstat (limited to 'java/demo')
-rw-r--r-- | java/demo/book/evictor_filesystem/Client.java | 2 | ||||
-rw-r--r-- | java/demo/book/evictor_filesystem/DirectoryI.java | 2 | ||||
-rw-r--r-- | java/demo/book/evictor_filesystem/FileI.java | 14 | ||||
-rw-r--r-- | java/demo/book/evictor_filesystem/Server.java | 3 | ||||
-rw-r--r-- | java/demo/book/lifecycle/Client.java | 8 | ||||
-rw-r--r-- | java/demo/book/lifecycle/Server.java | 8 | ||||
-rw-r--r-- | java/demo/book/map_filesystem/Client.java | 2 | ||||
-rw-r--r-- | java/demo/book/map_filesystem/DirectoryI.java | 4 | ||||
-rw-r--r-- | java/demo/book/map_filesystem/FileI.java | 1 | ||||
-rw-r--r-- | java/demo/book/map_filesystem/Server.java | 18 | ||||
-rw-r--r-- | java/demo/book/printer/Client.java | 33 | ||||
-rw-r--r-- | java/demo/book/printer/PrinterI.java | 3 | ||||
-rw-r--r-- | java/demo/book/printer/Server.java | 30 | ||||
-rw-r--r-- | java/demo/book/simple_filesystem/Client.java | 49 | ||||
-rw-r--r-- | java/demo/book/simple_filesystem/Filesystem/DirectoryI.java | 1 | ||||
-rw-r--r-- | java/demo/book/simple_filesystem/Filesystem/FileI.java | 1 | ||||
-rw-r--r-- | java/demo/book/simple_filesystem/Server.java | 33 |
17 files changed, 138 insertions, 74 deletions
diff --git a/java/demo/book/evictor_filesystem/Client.java b/java/demo/book/evictor_filesystem/Client.java index c24556388ce..fd428020a13 100644 --- a/java/demo/book/evictor_filesystem/Client.java +++ b/java/demo/book/evictor_filesystem/Client.java @@ -14,10 +14,12 @@ public class Client extends Ice.Application public int run(String[] args) { + // // Terminate cleanly on receipt of a signal. // shutdownOnInterrupt(); + // // Create a proxy for the root directory // DirectoryPrx rootDir = DirectoryPrxHelper.checkedCast(communicator().propertyToProxy("RootDir.Proxy")); diff --git a/java/demo/book/evictor_filesystem/DirectoryI.java b/java/demo/book/evictor_filesystem/DirectoryI.java index 98cd14d7dbd..f91add94a34 100644 --- a/java/demo/book/evictor_filesystem/DirectoryI.java +++ b/java/demo/book/evictor_filesystem/DirectoryI.java @@ -48,7 +48,7 @@ public final class DirectoryI extends PersistentDirectory { throw new PermissionDenied("Cannot destroy non-empty directory"); } - _destroyed = true; + _destroyed = true; } // diff --git a/java/demo/book/evictor_filesystem/FileI.java b/java/demo/book/evictor_filesystem/FileI.java index 5455b0880c6..08e86aa6eb5 100644 --- a/java/demo/book/evictor_filesystem/FileI.java +++ b/java/demo/book/evictor_filesystem/FileI.java @@ -33,13 +33,13 @@ public final class FileI extends PersistentFile throws PermissionDenied { synchronized(this) - { - if(_destroyed) - { - throw new Ice.ObjectNotExistException(current.id, current.facet, current.operation); - } - _destroyed = true; - } + { + if(_destroyed) + { + throw new Ice.ObjectNotExistException(current.id, current.facet, current.operation); + } + _destroyed = true; + } // // Because we use a transactional evictor, these updates are guaranteed to be atomic. diff --git a/java/demo/book/evictor_filesystem/Server.java b/java/demo/book/evictor_filesystem/Server.java index 55bd40fccc5..857695e8036 100644 --- a/java/demo/book/evictor_filesystem/Server.java +++ b/java/demo/book/evictor_filesystem/Server.java @@ -30,8 +30,7 @@ public class Server extends Ice.Application // // Create an object adapter. // - Ice.ObjectAdapter adapter = - communicator().createObjectAdapter("EvictorFilesystem"); + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("EvictorFilesystem"); // // Create the Freeze evictor (stored in the _evictor diff --git a/java/demo/book/lifecycle/Client.java b/java/demo/book/lifecycle/Client.java index 710a52649e3..c1e0525b7e6 100644 --- a/java/demo/book/lifecycle/Client.java +++ b/java/demo/book/lifecycle/Client.java @@ -14,18 +14,17 @@ public class Client extends Ice.Application public int run(String[] args) { + // // Terminate cleanly on receipt of a signal. // shutdownOnInterrupt(); + // // Create a proxy for the root directory // Ice.ObjectPrx base = communicator().stringToProxy("RootDir:default -p 10000"); - if(base == null) - { - throw new Error("Could not create proxy"); - } + // // Down-cast the proxy to a Directory proxy. // DirectoryPrx rootDir = DirectoryPrxHelper.checkedCast(base); @@ -52,5 +51,4 @@ public class Client extends Ice.Application super(msg); } } - } diff --git a/java/demo/book/lifecycle/Server.java b/java/demo/book/lifecycle/Server.java index 54bc2d2526f..933c777a36e 100644 --- a/java/demo/book/lifecycle/Server.java +++ b/java/demo/book/lifecycle/Server.java @@ -14,16 +14,19 @@ class Server extends Ice.Application public int run(String[] args) { + // // Terminate cleanly on receipt of a signal. // shutdownOnInterrupt(); Ice.Properties properties = communicator().getProperties(); + // // Create an object adapter // Ice.ObjectAdapter adapter = communicator().createObjectAdapterWithEndpoints( - "LifecycleFilesystem", "default -h 127.0.0.1 -p 10000"); + "LifecycleFilesystem", "default -h 127.0.0.1 -p 10000"); + // // Create the root directory. // DirectoryI root = new DirectoryI(); @@ -31,11 +34,12 @@ class Server extends Ice.Application id.name = "RootDir"; adapter.add(root, id); - + // // All objects are created, allow client requests now. // adapter.activate(); + // // Wait until we are done. // communicator().waitForShutdown(); diff --git a/java/demo/book/map_filesystem/Client.java b/java/demo/book/map_filesystem/Client.java index 33542ecf941..163296ffc48 100644 --- a/java/demo/book/map_filesystem/Client.java +++ b/java/demo/book/map_filesystem/Client.java @@ -14,10 +14,12 @@ public class Client extends Ice.Application public int run(String[] args) { + // // Terminate cleanly on receipt of a signal. // shutdownOnInterrupt(); + // // Create a proxy for the root directory // DirectoryPrx rootDir = DirectoryPrxHelper.checkedCast(communicator().propertyToProxy("RootDir.Proxy")); diff --git a/java/demo/book/map_filesystem/DirectoryI.java b/java/demo/book/map_filesystem/DirectoryI.java index 2d8c701f2c0..3c4894add90 100644 --- a/java/demo/book/map_filesystem/DirectoryI.java +++ b/java/demo/book/map_filesystem/DirectoryI.java @@ -23,6 +23,7 @@ public class DirectoryI extends _DirectoryDisp { IdentityDirectoryEntryMap dirDB = new IdentityDirectoryEntryMap(connection, directoriesDB()); + // // Create the record for the root directory if necessary. // for(;;) @@ -182,6 +183,7 @@ public class DirectoryI extends _DirectoryDisp for(;;) { + // // The transaction is necessary since we are altering // two records in one atomic action. // @@ -247,6 +249,7 @@ public class DirectoryI extends _DirectoryDisp for(;;) { + // // The transaction is necessary since we are altering // two records in one atomic action. // @@ -312,6 +315,7 @@ public class DirectoryI extends _DirectoryDisp for(;;) { + // // The transaction is necessary since we are altering // two records in one atomic action. // diff --git a/java/demo/book/map_filesystem/FileI.java b/java/demo/book/map_filesystem/FileI.java index bd7fabe10ba..b52fa00c1f4 100644 --- a/java/demo/book/map_filesystem/FileI.java +++ b/java/demo/book/map_filesystem/FileI.java @@ -142,6 +142,7 @@ public class FileI extends _FileDisp Freeze.Transaction txn = null; try { + // // The transaction is necessary since we are // altering two records in one atomic action. // diff --git a/java/demo/book/map_filesystem/Server.java b/java/demo/book/map_filesystem/Server.java index da9ce6e8617..e7851806949 100644 --- a/java/demo/book/map_filesystem/Server.java +++ b/java/demo/book/map_filesystem/Server.java @@ -21,6 +21,7 @@ public class Server extends Ice.Application public int run(String[] args) { + // // Create an object adapter // Ice.ObjectAdapter adapter = communicator().createObjectAdapter("MapFilesystem"); @@ -28,35 +29,40 @@ public class Server extends Ice.Application Freeze.Connection connection = null; try { + // // Open a connection to the files and directories // database. This should remain open for the duration of the // application for performance reasons. // connection = Freeze.Util.createConnection(communicator(), _envName); - IdentityFileEntryMap fileDB = new IdentityFileEntryMap(connection, FileI.filesDB(), true); + IdentityFileEntryMap fileDB = new IdentityFileEntryMap(connection, FileI.filesDB(), true); IdentityDirectoryEntryMap dirDB = new IdentityDirectoryEntryMap( - connection, DirectoryI.directoriesDB(), true); - + connection, DirectoryI.directoriesDB(), true); + + // // Add default servants for the file and directory. // adapter.addDefaultServant(new FileI(communicator(), _envName), "file"); adapter.addDefaultServant(new DirectoryI(communicator(), _envName), ""); - + + // // Ready to accept requests now // adapter.activate(); - + + // // Wait until we are done // communicator().waitForShutdown(); } finally { + // // Close the connection gracefully. // connection.close(); } - + return 0; } diff --git a/java/demo/book/printer/Client.java b/java/demo/book/printer/Client.java index bb18ab4bc71..8f2fe114658 100644 --- a/java/demo/book/printer/Client.java +++ b/java/demo/book/printer/Client.java @@ -7,34 +7,43 @@ // // ********************************************************************** -public class Client { +public class Client +{ public static void main(String[] args) { int status = 0; Ice.Communicator ic = null; - try { + try + { ic = Ice.Util.initialize(args); - Ice.ObjectPrx base = ic.stringToProxy( - "SimplePrinter:default -p 10000"); + Ice.ObjectPrx base = ic.stringToProxy("SimplePrinter:default -p 10000"); Demo.PrinterPrx printer = Demo.PrinterPrxHelper.checkedCast(base); - if (printer == null) + if(printer == null) + { throw new Error("Invalid proxy"); + } printer.printString("Hello World!"); - } catch (Ice.LocalException e) { + } + catch(Ice.LocalException e) + { e.printStackTrace(); status = 1; - } catch (Exception e) { + } + catch(Exception e) + { System.err.println(e.getMessage()); status = 1; } - if (ic != null) { - // Clean up - // - try { + if(ic != null) + { + try + { ic.destroy(); - } catch (Exception e) { + } + catch(Exception e) + { System.err.println(e.getMessage()); status = 1; } diff --git a/java/demo/book/printer/PrinterI.java b/java/demo/book/printer/PrinterI.java index a00699af269..bf48aad2c8f 100644 --- a/java/demo/book/printer/PrinterI.java +++ b/java/demo/book/printer/PrinterI.java @@ -7,7 +7,8 @@ // // ********************************************************************** -public class PrinterI extends Demo._PrinterDisp { +public class PrinterI extends Demo._PrinterDisp +{ public void printString(String s, Ice.Current current) { diff --git a/java/demo/book/printer/Server.java b/java/demo/book/printer/Server.java index 5d278107c7b..89f8fddae30 100644 --- a/java/demo/book/printer/Server.java +++ b/java/demo/book/printer/Server.java @@ -7,33 +7,35 @@ // // ********************************************************************** -public class Server { +public class Server +{ public static void main(String[] args) { int status = 0; Ice.Communicator ic = null; - try { + try + { ic = Ice.Util.initialize(args); - Ice.ObjectAdapter adapter - = ic.createObjectAdapterWithEndpoints( - "SimplePrinterAdapter", "default -p 10000"); + Ice.ObjectAdapter adapter = ic.createObjectAdapterWithEndpoints("SimplePrinterAdapter", "default -p 10000"); Ice.Object object = new PrinterI(); - adapter.add( - object, - ic.stringToIdentity("SimplePrinter")); + adapter.add(object, ic.stringToIdentity("SimplePrinter")); adapter.activate(); ic.waitForShutdown(); - } catch (Exception e) { + } + catch(Exception e) + { e.printStackTrace(); status = 1; } - if (ic != null) { - // Clean up - // - try { + if(ic != null) + { + try + { ic.destroy(); - } catch (Exception e) { + } + catch(Exception e) + { System.err.println(e.getMessage()); status = 1; } diff --git a/java/demo/book/simple_filesystem/Client.java b/java/demo/book/simple_filesystem/Client.java index fa90748d197..bc3569af867 100644 --- a/java/demo/book/simple_filesystem/Client.java +++ b/java/demo/book/simple_filesystem/Client.java @@ -9,8 +9,8 @@ import Filesystem.*; -public class Client { - +public class Client +{ // Recursively print the contents of directory "dir" in tree fashion. // For files, show the contents of each file. The "depth" // parameter is the current nesting level (for indentation). @@ -24,16 +24,22 @@ public class Client { NodePrx[] contents = dir.list(); - for (int i = 0; i < contents.length; ++i) { + for(int i = 0; i < contents.length; ++i) + { DirectoryPrx subdir = DirectoryPrxHelper.checkedCast(contents[i]); FilePrx file = FilePrxHelper.uncheckedCast(contents[i]); System.out.println(indent + contents[i].name() + (subdir != null ? " (directory):" : " (file):")); - if (subdir != null) { + if(subdir != null) + { listRecursive(subdir, depth); - } else { + } + else + { String[] text = file.read(); - for (int j = 0; j < text.length; ++j) + for(int j = 0; j < text.length; ++j) + { System.out.println(indent + "\t" + text[j]); + } } } } @@ -43,38 +49,51 @@ public class Client { { int status = 0; Ice.Communicator ic = null; - try { + try + { + // // Create a communicator // ic = Ice.Util.initialize(args); + // // Create a proxy for the root directory // Ice.ObjectPrx base = ic.stringToProxy("RootDir:default -p 10000"); + // // Down-cast the proxy to a Directory proxy // DirectoryPrx rootDir = DirectoryPrxHelper.checkedCast(base); - if (rootDir == null) + if(rootDir == null) + { throw new RuntimeException("Invalid proxy"); + } + // // Recursively list the contents of the root directory // System.out.println("Contents of root directory:"); listRecursive(rootDir, 0); - } catch (Ice.LocalException e) { + } + catch(Ice.LocalException e) + { e.printStackTrace(); status = 1; - } catch (Exception e) { + } + catch(Exception e) + { System.err.println(e.getMessage()); status = 1; } - if (ic != null) { - // Clean up - // - try { + if(ic != null) + { + try + { ic.destroy(); - } catch (Exception e) { + } + catch(Exception e) + { System.err.println(e.getMessage()); status = 1; } diff --git a/java/demo/book/simple_filesystem/Filesystem/DirectoryI.java b/java/demo/book/simple_filesystem/Filesystem/DirectoryI.java index f52f8f28a38..7acb88c4112 100644 --- a/java/demo/book/simple_filesystem/Filesystem/DirectoryI.java +++ b/java/demo/book/simple_filesystem/Filesystem/DirectoryI.java @@ -23,7 +23,6 @@ public final class DirectoryI extends _DirectoryDisp // _id = new Ice.Identity(); _id.name = _parent != null ? java.util.UUID.randomUUID().toString() : "RootDir"; - } // Slice Node::name() operation diff --git a/java/demo/book/simple_filesystem/Filesystem/FileI.java b/java/demo/book/simple_filesystem/Filesystem/FileI.java index 69bb0684363..79ecfd1f130 100644 --- a/java/demo/book/simple_filesystem/Filesystem/FileI.java +++ b/java/demo/book/simple_filesystem/Filesystem/FileI.java @@ -21,6 +21,7 @@ public class FileI extends _FileDisp assert(_parent != null); + // // Create an identity // _id = new Ice.Identity(); diff --git a/java/demo/book/simple_filesystem/Server.java b/java/demo/book/simple_filesystem/Server.java index aefca791431..4889a6e47ab 100644 --- a/java/demo/book/simple_filesystem/Server.java +++ b/java/demo/book/simple_filesystem/Server.java @@ -9,41 +9,51 @@ import Filesystem.*; -public class Server extends Ice.Application { +public class Server extends Ice.Application +{ public int run(String[] args) { + // // Terminate cleanly on receipt of a signal // shutdownOnInterrupt(); + // // Create an object adapter. // - Ice.ObjectAdapter adapter = communicator().createObjectAdapterWithEndpoints( - "SimpleFilesystem", "default -h 127.0.0.1 -p 10000"); + Ice.ObjectAdapter adapter = + communicator().createObjectAdapterWithEndpoints("SimpleFilesystem", "default -h 127.0.0.1 -p 10000"); + // // Create the root directory (with name "/" and no parent) // DirectoryI root = new DirectoryI(communicator(), "/", null); root.activate(adapter); + // // Create a file called "README" in the root directory // FileI file = new FileI(communicator(), "README", root); String[] text; text = new String[]{ "This file system contains a collection of poetry." }; - try { + try + { file.write(text, null); - } catch (GenericError e) { + } + catch(GenericError e) + { System.err.println(e.reason); } file.activate(adapter); + // // Create a directory called "Coleridge" in the root directory // DirectoryI coleridge = new DirectoryI(communicator(), "Coleridge", root); coleridge.activate(adapter); + // // Create a file called "Kubla_Khan" in the Coleridge directory // file = new FileI(communicator(), "Kubla_Khan", coleridge); @@ -52,23 +62,30 @@ public class Server extends Ice.Application { "Where Alph, the sacred river, ran", "Through caverns measureless to man", "Down to a sunless sea." }; - try { + try + { file.write(text, null); - } catch (GenericError e) { + } + catch(GenericError e) + { System.err.println(e.reason); } file.activate(adapter); + // // All objects are created, allow client requests now // adapter.activate(); + // // Wait until we are done // communicator().waitForShutdown(); - if (interrupted()) + if(interrupted()) + { System.err.println(appName() + ": terminating"); + } return 0; } |