diff options
author | Jose <jose@zeroc.com> | 2014-11-07 21:28:00 +0100 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2014-11-07 21:28:00 +0100 |
commit | f99742d525f519996a6d321afb323a67fd9be4f9 (patch) | |
tree | f7b4454611d64d1a28bf9609aa64234fe78d3f53 /java/demo/Manual/simple_filesystem | |
parent | Some IceJS linting fixes (diff) | |
download | ice-f99742d525f519996a6d321afb323a67fd9be4f9.tar.bz2 ice-f99742d525f519996a6d321afb323a67fd9be4f9.tar.xz ice-f99742d525f519996a6d321afb323a67fd9be4f9.zip |
Fix for (ICE-5832) Versioning of Jar files
Renaming JAR files
Diffstat (limited to 'java/demo/Manual/simple_filesystem')
9 files changed, 463 insertions, 0 deletions
diff --git a/java/demo/Manual/simple_filesystem/.externalToolBuilders/demo.book.simple_filesystem.launch b/java/demo/Manual/simple_filesystem/.externalToolBuilders/demo.book.simple_filesystem.launch new file mode 100644 index 00000000000..2256b877bae --- /dev/null +++ b/java/demo/Manual/simple_filesystem/.externalToolBuilders/demo.book.simple_filesystem.launch @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType"> +<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AUTO_TARGETS" value="generate,"/> +<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_CLEAN_TARGETS" value="clean,"/> +<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_MANUAL_TARGETS" value="generate,"/> +<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/> +<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/> +<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${container}"/> +<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/> +<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/> +<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/> +<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="demo.book.simple_filesystem"/> +<stringAttribute key="org.eclipse.ui.externaltools.ATTR_BUILD_SCOPE" value="${working_set:<?xml version="1.0" encoding="UTF-8"?> <resources> <item path="/demo.book.simple_filesystem/Filesystem.ice" type="1"/> </resources>}"/> +<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/demo.book.simple_filesystem/build.xml}"/> +<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="incremental,auto,clean"/> +<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/> +</launchConfiguration> diff --git a/java/demo/Manual/simple_filesystem/Client.java b/java/demo/Manual/simple_filesystem/Client.java new file mode 100644 index 00000000000..de1516eb010 --- /dev/null +++ b/java/demo/Manual/simple_filesystem/Client.java @@ -0,0 +1,103 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2014 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 Filesystem.*; + +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). + + static void + listRecursive(DirectoryPrx dir, int depth) + { + char[] indentCh = new char[++depth]; + java.util.Arrays.fill(indentCh, '\t'); + String indent = new String(indentCh); + + NodePrx[] contents = dir.list(); + + 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) + { + listRecursive(subdir, depth); + } + else + { + String[] text = file.read(); + for(int j = 0; j < text.length; ++j) + { + System.out.println(indent + "\t" + text[j]); + } + } + } + } + + public static void + main(String[] args) + { + int status = 0; + Ice.Communicator ic = null; + try + { + // + // Create a communicator + // + ic = Ice.Util.initialize(args); + + // + // Create a proxy for the root directory + // + Ice.ObjectPrx base = ic.stringToProxy("RootDir:default -h localhost -p 10000"); + + // + // Down-cast the proxy to a Directory proxy + // + DirectoryPrx rootDir = DirectoryPrxHelper.checkedCast(base); + 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) + { + e.printStackTrace(); + status = 1; + } + catch(Exception e) + { + System.err.println(e.getMessage()); + status = 1; + } + if(ic != null) + { + try + { + ic.destroy(); + } + catch(Exception e) + { + System.err.println(e.getMessage()); + status = 1; + } + } + System.exit(status); + } +} diff --git a/java/demo/Manual/simple_filesystem/Filesystem.ice b/java/demo/Manual/simple_filesystem/Filesystem.ice new file mode 100755 index 00000000000..21e8a435fcb --- /dev/null +++ b/java/demo/Manual/simple_filesystem/Filesystem.ice @@ -0,0 +1,38 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2014 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. +// +// ********************************************************************** + +#pragma once + +module Filesystem +{ + exception GenericError + { + string reason; + }; + + interface Node + { + idempotent string name(); + }; + + sequence<string> Lines; + + interface File extends Node + { + idempotent Lines read(); + idempotent void write(Lines text) throws GenericError; + }; + + sequence<Node*> NodeSeq; + + interface Directory extends Node + { + idempotent NodeSeq list(); + }; +}; diff --git a/java/demo/Manual/simple_filesystem/Filesystem/DirectoryI.java b/java/demo/Manual/simple_filesystem/Filesystem/DirectoryI.java new file mode 100644 index 00000000000..69f793bb89c --- /dev/null +++ b/java/demo/Manual/simple_filesystem/Filesystem/DirectoryI.java @@ -0,0 +1,72 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2014 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 Filesystem; + +public final class DirectoryI extends _DirectoryDisp +{ + // DirectoryI constructor + + public + DirectoryI(Ice.Communicator communicator, String name, DirectoryI parent) + { + _name = name; + _parent = parent; + + // Create an identity. The root directory has the fixed identity "RootDir" + // + _id = new Ice.Identity(); + _id.name = _parent != null ? java.util.UUID.randomUUID().toString() : "RootDir"; + } + + // Slice Node::name() operation + + public String + name(Ice.Current current) + { + return _name; + } + + // Slice Directory::list() operation + + public NodePrx[] + list(Ice.Current current) + { + NodePrx[] result = new NodePrx[_contents.size()]; + _contents.toArray(result); + return result; + } + + // addChild is called by the child in order to add + // itself to the _contents member of the parent + + void + addChild(NodePrx child) + { + _contents.add(child); + } + + // activate adds the servant to the object adapter and + // adds child nodes ot the parent's _contents list. + + public void + activate(Ice.ObjectAdapter a) + { + NodePrx thisNode = NodePrxHelper.uncheckedCast(a.add(this, _id)); + if(_parent != null) + { + _parent.addChild(thisNode); + } + } + + private String _name; + private DirectoryI _parent; + private Ice.Identity _id; + private java.util.List<NodePrx> _contents = new java.util.ArrayList<NodePrx>(); +} diff --git a/java/demo/Manual/simple_filesystem/Filesystem/FileI.java b/java/demo/Manual/simple_filesystem/Filesystem/FileI.java new file mode 100644 index 00000000000..3a4bff86431 --- /dev/null +++ b/java/demo/Manual/simple_filesystem/Filesystem/FileI.java @@ -0,0 +1,67 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2014 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 Filesystem; + +public class FileI extends _FileDisp +{ + // FileI constructor + + public + FileI(Ice.Communicator communicator, String name, DirectoryI parent) + { + _name = name; + _parent = parent; + + assert(_parent != null); + + // + // Create an identity + // + _id = new Ice.Identity(); + _id.name = java.util.UUID.randomUUID().toString(); + } + + // Slice Node::name() operation + + public String + name(Ice.Current current) + { + return _name; + } + + // Slice File::read() operation + + public String[] + read(Ice.Current current) + { + return _lines; + } + + // Slice File::write() operation + + public void + write(String[] text, Ice.Current current) + throws GenericError + { + _lines = text; + } + + public void + activate(Ice.ObjectAdapter a) + { + NodePrx thisNode = NodePrxHelper.uncheckedCast(a.add(this, _id)); + _parent.addChild(thisNode); + } + + private String _name; + private DirectoryI _parent; + private Ice.Identity _id; + private String[] _lines; +} diff --git a/java/demo/Manual/simple_filesystem/README b/java/demo/Manual/simple_filesystem/README new file mode 100644 index 00000000000..f6ed81b1855 --- /dev/null +++ b/java/demo/Manual/simple_filesystem/README @@ -0,0 +1,10 @@ +This demo implements the simple filesystem application shown at +the end of the client and server Java mapping chapters. + +To run it, start the server in a window: + +$ java -jar build/libs/server.jar + +Then run the client in a separate window: + +$ java -jar build/libs/client.jar diff --git a/java/demo/Manual/simple_filesystem/Server.java b/java/demo/Manual/simple_filesystem/Server.java new file mode 100644 index 00000000000..a5a97aa6140 --- /dev/null +++ b/java/demo/Manual/simple_filesystem/Server.java @@ -0,0 +1,99 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2014 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 Filesystem.*; + +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 localhost -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 + { + file.write(text, null); + } + 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); + text = new String[]{ "In Xanadu did Kubla Khan", + "A stately pleasure-dome decree:", + "Where Alph, the sacred river, ran", + "Through caverns measureless to man", + "Down to a sunless sea." }; + try + { + file.write(text, null); + } + 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()) + { + System.err.println(appName() + ": terminating"); + } + + return 0; + } + + public static void + main(String[] args) + { + Server app = new Server(); + System.exit(app.main("Server", args)); + } +} diff --git a/java/demo/Manual/simple_filesystem/demo_manual_simple_filesystem.iml b/java/demo/Manual/simple_filesystem/demo_manual_simple_filesystem.iml new file mode 100644 index 00000000000..5e03c3e6c62 --- /dev/null +++ b/java/demo/Manual/simple_filesystem/demo_manual_simple_filesystem.iml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/../../.." external.system.id="GRADLE" external.system.module.group="java" external.system.module.version="unspecified" type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" inherit-compiler-output="false"> + <output url="file://$MODULE_DIR$/build/classes" /> + <output-test url="file://$MODULE_DIR$/build/classes/test" /> + <exclude-output /> + <content url="file://$MODULE_DIR$"> + <sourceFolder url="file://$MODULE_DIR$" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/build/generated-src" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> + <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> + <sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" /> + <excludeFolder url="file://$MODULE_DIR$/.gradle" /> + <excludeFolder url="file://$MODULE_DIR$/build/dependency-cache" /> + <excludeFolder url="file://$MODULE_DIR$/build/tmp" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="module" module-name="Ice" exported="" /> + </component> +</module> + diff --git a/java/demo/Manual/simple_filesystem/expect.py b/java/demo/Manual/simple_filesystem/expect.py new file mode 100755 index 00000000000..953113e2054 --- /dev/null +++ b/java/demo/Manual/simple_filesystem/expect.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2014 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, signal + +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 RuntimeError("can't find toplevel directory!") +sys.path.append(path[0]) + +from demoscript import Util + +server = Util.spawn('java -jar build/libs/server.jar --Ice.PrintAdapterReady') +server.expect('.* ready') + +sys.stdout.write("testing... ") +sys.stdout.flush() +client = Util.spawn('java -jar build/libs/client.jar') +client.expect('Contents of root directory:\n.*Down to a sunless sea.') +client.waitTestSuccess() +server.kill(signal.SIGINT) +server.waitTestSuccess() +print("ok") |