diff options
author | Matthew Newhook <matthew@zeroc.com> | 2015-03-18 12:58:16 -0230 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2015-03-18 12:58:16 -0230 |
commit | 9b7668c7c92cf9cb311fe444cdddb489cd2a219d (patch) | |
tree | 5016567c58c81f5654e9d01935e199c6bf4761d2 /java/demo/Ice/interrupt | |
parent | VS add-in & build updates: (diff) | |
download | ice-9b7668c7c92cf9cb311fe444cdddb489cd2a219d.tar.bz2 ice-9b7668c7c92cf9cb311fe444cdddb489cd2a219d.tar.xz ice-9b7668c7c92cf9cb311fe444cdddb489cd2a219d.zip |
Removed demos.
Moved demoscript to distribution.
Diffstat (limited to 'java/demo/Ice/interrupt')
-rw-r--r-- | java/demo/Ice/interrupt/.externalToolBuilders/demo.Ice.interrupt.slice.launch | 15 | ||||
-rw-r--r-- | java/demo/Ice/interrupt/Client.java | 199 | ||||
-rw-r--r-- | java/demo/Ice/interrupt/README | 37 | ||||
-rw-r--r-- | java/demo/Ice/interrupt/Server.java | 91 | ||||
-rw-r--r-- | java/demo/Ice/interrupt/TaskManager.ice | 21 | ||||
-rw-r--r-- | java/demo/Ice/interrupt/TaskManagerI.java | 56 | ||||
-rw-r--r-- | java/demo/Ice/interrupt/config.client | 46 | ||||
-rw-r--r-- | java/demo/Ice/interrupt/config.server | 47 | ||||
-rwxr-xr-x | java/demo/Ice/interrupt/expect.py | 30 |
9 files changed, 0 insertions, 542 deletions
diff --git a/java/demo/Ice/interrupt/.externalToolBuilders/demo.Ice.interrupt.slice.launch b/java/demo/Ice/interrupt/.externalToolBuilders/demo.Ice.interrupt.slice.launch deleted file mode 100644 index f46189ef4a2..00000000000 --- a/java/demo/Ice/interrupt/.externalToolBuilders/demo.Ice.interrupt.slice.launch +++ /dev/null @@ -1,15 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType"> -<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="${project}"/> -<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.Ice.interrupt"/> -<stringAttribute key="org.eclipse.ui.externaltools.ATTR_BUILD_SCOPE" value="${working_set:<?xml version="1.0" encoding="UTF-8"?> <resources> <item path="/demo.Ice.interrupt/TaskManager.ice" type="1"/> </resources>}"/> -<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/demo.Ice.interrupt/build.xml}"/> -<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,"/> -<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/> -</launchConfiguration> diff --git a/java/demo/Ice/interrupt/Client.java b/java/demo/Ice/interrupt/Client.java deleted file mode 100644 index 28c49d1f68c..00000000000 --- a/java/demo/Ice/interrupt/Client.java +++ /dev/null @@ -1,199 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2015 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 java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; - -import Demo.*; -import Ice.LocalException; - -public class Client extends Ice.Application -{ - class ShutdownHook extends Thread - { - @Override - public void - run() - { - try - { - communicator().destroy(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - } - } - } - - private static void - menu() - { - System.out.println( - "usage:\n" + - "t: start a task\n" + - "b: start a blocking task\n" + - "i: interrupt the blocking task\n" + - "s: shutdown server\n" + - "x: exit\n" + - "?: help\n"); - } - - @Override - 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()); - - final TaskManagerPrx taskManager = TaskManagerPrxHelper.checkedCast(communicator().propertyToProxy("TaskManager.Proxy")); - if(taskManager == null) - { - System.err.println("invalid proxy"); - return 1; - } - - menu(); - - java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); - - ExecutorService executor = Executors.newFixedThreadPool(5); - List<Future<?> > futures = new ArrayList<Future<?> >(); - int nextId = 0; - String line = null; - do - { - try - { - System.out.print("==> "); - System.out.flush(); - line = in.readLine(); - if(line == null) - { - break; - } - if(line.equals("t")) - { - final int id = nextId++; - taskManager.begin_run(id, new Callback_TaskManager_run() - { - @Override - public void response() - { - System.out.println("task " + id + " completed running"); - } - - @Override - public void exception(LocalException ex) - { - System.out.println("blocking task " + id + " failed"); - ex.printStackTrace(); - } - }); - } - else if(line.equals("b")) - { - // - // Remove any completed tasks. - // - Iterator<Future<?> > iterator = futures.iterator(); - while(iterator.hasNext()) { - Future<?> f = iterator.next(); - if(f.isDone()) { - iterator.remove(); - } - } - - final int id = nextId++; - Future<?> future = executor.submit(new Runnable() { - @Override - public void - run() - { - try - { - taskManager.run(id); - System.out.println("task " + id + " completed running"); - } - catch(Ice.OperationInterruptedException e) - { - System.out.println("blocking task " + id + " interrupted"); - } - catch(Ice.Exception e) - { - System.out.println("blocking task " + id + " failed"); - e.printStackTrace(); - } - } - }); - futures.add(future); - } - else if(line.equals("i")) - { - for(Future<?> f : futures) - { - f.cancel(true); - } - futures.clear(); - } - else if(line.equals("s")) - { - taskManager.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/interrupt/README b/java/demo/Ice/interrupt/README deleted file mode 100644 index bdc4015713f..00000000000 --- a/java/demo/Ice/interrupt/README +++ /dev/null @@ -1,37 +0,0 @@ -This demo illustrates how to interrupt blocking servant dispatches on -the server and interrupt blocking proxy invocations on the client by -using Thread.interrupt(). - -To run the demo, first start the server: - -$ java -jar build/libs/server.jar - -In a separate window, start the client: - -$ java -jar build/libs/client.jar - -Calling TaskManager::run on the server simulates a long running task -by sleeping 10 seconds. Ordinarily a server will not shutdown until -all executing dispatched requests are complete. By interrupting -dispatch threads using Thread.interrupt() a server shutdown will -proceed, as long as the servant implementation correctly handles the -interrupt. - -The simplest way to interrupt dispatch threads is by using an -Ice.Dispatcher and ExecutorService. Calling shutdownNow on the -ExecutorService interrupts any executing tasks. - -Pressing ^C in the server calls shutdownNow on the executor service, -as does pressing 's' in the client which calls TaskManager::shutdown, -the implementation of which itself calls shutdownNow. - -It is also possible to interrupt blocking invocations on an Ice proxy -by calling Thread.interrupt(). - -In this demo, to interrupt a blocking proxy invocation on the client -press 'b' to run the invocation and 'i' to interrupt the invocation. -Only a single blocking invocation can be active at once. - -Pressing 't' in the client runs the task on the server using a -non-blocking AMI invocation. - diff --git a/java/demo/Ice/interrupt/Server.java b/java/demo/Ice/interrupt/Server.java deleted file mode 100644 index 9377defd4e3..00000000000 --- a/java/demo/Ice/interrupt/Server.java +++ /dev/null @@ -1,91 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2015 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 java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -public class Server extends Ice.Application -{ - @Override - public int - run(String[] args) - { - if(args.length > 0) - { - System.err.println(appName() + ": too many arguments"); - return 1; - } - - // - // If ^C is pressed we want to interrupt all running upcalls from the - // dispatcher and destroy the communicator. - // - setInterruptHook(new Thread() { - @Override - public void - run() - { - // - // Call shutdownNow on the executor. This interrupts all - // executor threads causing any running servant dispatch threads - // to terminate quickly. - // - _executor.shutdownNow(); - try - { - communicator().shutdown(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - } - } - }); - - Ice.ObjectAdapter adapter = communicator().createObjectAdapter("TaskManager"); - adapter.add(new TaskManagerI(_executor), communicator().stringToIdentity("manager")); - adapter.activate(); - communicator().waitForShutdown(); - - return 0; - } - - public static void - main(String[] args) - { - final Server app = new Server(); - - Ice.InitializationData initData = new Ice.InitializationData(); - initData.properties = Ice.Util.createProperties(); - initData.properties.load("config.server"); - - // - // This demo uses a dispatcher to execute any invocations on the server. - // By using an executor it is straightforward to interrupt any servant - // dispatch threads by using ExecutorService.shutdownNow. - // - initData.dispatcher = new Ice.Dispatcher() { - @Override - public void dispatch(Runnable runnable, Ice.Connection con) - { - app.getExecutor().submit(runnable); - } - }; - - int status = app.main("Server", args, initData); - System.exit(status); - } - - ExecutorService getExecutor() - { - return _executor; - } - - private ExecutorService _executor = Executors.newFixedThreadPool(5); -} diff --git a/java/demo/Ice/interrupt/TaskManager.ice b/java/demo/Ice/interrupt/TaskManager.ice deleted file mode 100644 index adc807a242e..00000000000 --- a/java/demo/Ice/interrupt/TaskManager.ice +++ /dev/null @@ -1,21 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2015 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 Demo -{ - -interface TaskManager -{ - void run(int id); - void shutdown(); -}; - -}; diff --git a/java/demo/Ice/interrupt/TaskManagerI.java b/java/demo/Ice/interrupt/TaskManagerI.java deleted file mode 100644 index ab642aeb63d..00000000000 --- a/java/demo/Ice/interrupt/TaskManagerI.java +++ /dev/null @@ -1,56 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2015 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 java.util.concurrent.ExecutorService; - -import Demo.*; - -public class TaskManagerI extends _TaskManagerDisp -{ - public TaskManagerI(ExecutorService executor) - { - _executor = executor; - } - - @Override - public void - run(int id, Ice.Current current) - { - System.out.println("starting task " + id); - // Sleep for 10 seconds. - try - { - Thread.sleep(10000); - System.out.println("stopping task " + id); - } - catch(InterruptedException ex) - { - // - // We are done, the server is shutting down. - // - System.out.println("interrupted task " + id); - } - } - - @Override - public void - shutdown(Ice.Current current) - { - System.out.println("Shutting down..."); - // - // Call shutdownNow on the executor. This interrupts all - // executor threads causing any running upcalls to terminate - // quickly. - // - _executor.shutdownNow(); - current.adapter.getCommunicator().shutdown(); - } - - private ExecutorService _executor; -} diff --git a/java/demo/Ice/interrupt/config.client b/java/demo/Ice/interrupt/config.client deleted file mode 100644 index 93ba30b3ca7..00000000000 --- a/java/demo/Ice/interrupt/config.client +++ /dev/null @@ -1,46 +0,0 @@ -# -# The client reads this property to create the reference to the -# "task manager" object in the server. -# -TaskManager.Proxy=manager:tcp -p 10000 - -# -# ThreadInterruptSafe must be enabled to use interrupt. -# -Ice.ThreadInterruptSafe=1 - -# -# Only connect to the localhost interface by default. -# -Ice.Default.Host=localhost - -# -# 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 - -# -# IceMX configuration. -# -#Ice.Admin.Endpoints=tcp -h localhost -p 10003 -Ice.Admin.InstanceName=client -IceMX.Metrics.Debug.GroupBy=id -IceMX.Metrics.ByParent.GroupBy=parent diff --git a/java/demo/Ice/interrupt/config.server b/java/demo/Ice/interrupt/config.server deleted file mode 100644 index 9d950f604a5..00000000000 --- a/java/demo/Ice/interrupt/config.server +++ /dev/null @@ -1,47 +0,0 @@ -# -# The server creates one single object adapter with the name -# "Hello". The following line sets the endpoints for this -# adapter. -# -TaskManager.Endpoints=tcp -p 10000 - -# -# ThreadInterruptSafe must be enabled to use interrupt. -# -Ice.ThreadInterruptSafe=1 - -# -# Only listen on the localhost interface by default. -# -Ice.Default.Host=localhost - -# -# 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 - -# -# IceMX configuration. -# -#Ice.Admin.Endpoints=tcp -h localhost -p 10002 -Ice.Admin.InstanceName=server -IceMX.Metrics.Debug.GroupBy=id -IceMX.Metrics.ByParent.GroupBy=parent diff --git a/java/demo/Ice/interrupt/expect.py b/java/demo/Ice/interrupt/expect.py deleted file mode 100755 index fdbc8ddeddf..00000000000 --- a/java/demo/Ice/interrupt/expect.py +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env python -# ********************************************************************** -# -# Copyright (c) 2003-2015 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 RuntimeError("can't find toplevel directory!") -sys.path.append(path[0]) - -from demoscript import Util -from demoscript.Ice import interrupt - -server = Util.spawn('java -jar build/libs/server.jar --Ice.PrintAdapterReady --Ice.Warn.Connections=0') -server.expect('.* ready') -client = Util.spawn('java -jar build/libs/client.jar --Ice.Warn.Connections=0') -client.expect('.*==>') - -interrupt.run(client, server) |