diff options
author | Matthew Newhook <matthew@zeroc.com> | 2006-12-22 18:52:53 +0000 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2006-12-22 18:52:53 +0000 |
commit | 84d9f5c369fceccfa16401ed50783ed2ad209559 (patch) | |
tree | 689d30c8707629f1db8155edadb47ce1bce363ad /java/demo | |
parent | Added autoflushing of batches (diff) | |
download | ice-84d9f5c369fceccfa16401ed50783ed2ad209559.tar.bz2 ice-84d9f5c369fceccfa16401ed50783ed2ad209559.tar.xz ice-84d9f5c369fceccfa16401ed50783ed2ad209559.zip |
http://bugzilla.zeroc.com/bugzilla/show_bug.cgi?id=1391.
Diffstat (limited to 'java/demo')
-rw-r--r-- | java/demo/Freeze/library/Client.java | 23 | ||||
-rw-r--r-- | java/demo/Freeze/library/Collocated.java | 23 | ||||
-rw-r--r-- | java/demo/Freeze/phonebook/Client.java | 23 | ||||
-rw-r--r-- | java/demo/Freeze/phonebook/Collocated.java | 23 | ||||
-rw-r--r-- | java/demo/Glacier2/callback/Client.java | 23 | ||||
-rw-r--r-- | java/demo/Ice/callback/Client.java | 23 | ||||
-rw-r--r-- | java/demo/Ice/hello/Client.java | 24 | ||||
-rw-r--r-- | java/demo/Ice/invoke/Client.java | 23 | ||||
-rw-r--r-- | java/demo/Ice/nested/Client.java | 32 | ||||
-rw-r--r-- | java/demo/Ice/session/Client.java | 101 | ||||
-rw-r--r-- | java/demo/Ice/throughput/Client.java | 23 | ||||
-rw-r--r-- | java/demo/Ice/value/Client.java | 23 | ||||
-rw-r--r-- | java/demo/IceBox/hello/Client.java | 23 | ||||
-rw-r--r-- | java/demo/IceGrid/allocate/Client.java | 72 | ||||
-rw-r--r-- | java/demo/IceGrid/sessionActivation/Client.java | 70 | ||||
-rw-r--r-- | java/demo/IceGrid/simple/Client.java | 23 |
16 files changed, 490 insertions, 62 deletions
diff --git a/java/demo/Freeze/library/Client.java b/java/demo/Freeze/library/Client.java index 3105354d443..67b6af17477 100644 --- a/java/demo/Freeze/library/Client.java +++ b/java/demo/Freeze/library/Client.java @@ -9,9 +9,32 @@ public class Client extends Ice.Application { + class ShutdownHook extends Thread + { + public void + run() + { + try + { + communicator().destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } + } + public int run(String[] args) { + // + // Since this is an interactive demo we want to clear the + // Application installed interrupt callback and install our + // own shutdown hook. + // + setInterruptHook(new ShutdownHook()); + return RunParser.runParser(appName(), args, communicator()); } diff --git a/java/demo/Freeze/library/Collocated.java b/java/demo/Freeze/library/Collocated.java index ec6beade155..8cb11e19a00 100644 --- a/java/demo/Freeze/library/Collocated.java +++ b/java/demo/Freeze/library/Collocated.java @@ -9,9 +9,32 @@ class LibraryCollocated extends Ice.Application { + class ShutdownHook extends Thread + { + public void + run() + { + try + { + communicator().destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } + } + public int run(String[] args) { + // + // Since this is an interactive demo we want to clear the + // Application installed interrupt callback and install our + // own shutdown hook. + // + setInterruptHook(new ShutdownHook()); + Ice.Properties properties = communicator().getProperties(); // diff --git a/java/demo/Freeze/phonebook/Client.java b/java/demo/Freeze/phonebook/Client.java index c4ec8377276..ede5856bcd4 100644 --- a/java/demo/Freeze/phonebook/Client.java +++ b/java/demo/Freeze/phonebook/Client.java @@ -9,9 +9,32 @@ public class Client extends Ice.Application { + class ShutdownHook extends Thread + { + public void + run() + { + try + { + communicator().destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } + } + public int run(String[] args) { + // + // Since this is an interactive demo we want to clear the + // Application installed interrupt callback and install our + // own shutdown hook. + // + setInterruptHook(new ShutdownHook()); + return RunParser.runParser(appName(), args, communicator()); } diff --git a/java/demo/Freeze/phonebook/Collocated.java b/java/demo/Freeze/phonebook/Collocated.java index 825da566780..a02ba0a96f4 100644 --- a/java/demo/Freeze/phonebook/Collocated.java +++ b/java/demo/Freeze/phonebook/Collocated.java @@ -9,9 +9,32 @@ class PhoneBookCollocated extends Ice.Application { + class ShutdownHook extends Thread + { + public void + run() + { + try + { + communicator().destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } + } + public int run(String[] args) { + // + // Since this is an interactive demo we want to clear the + // Application installed interrupt callback and install our + // own shutdown hook. + // + setInterruptHook(new ShutdownHook()); + Ice.Properties properties = communicator().getProperties(); // diff --git a/java/demo/Glacier2/callback/Client.java b/java/demo/Glacier2/callback/Client.java index b1e90ce021c..b86e111c1cf 100644 --- a/java/demo/Glacier2/callback/Client.java +++ b/java/demo/Glacier2/callback/Client.java @@ -11,6 +11,22 @@ 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() { @@ -30,6 +46,13 @@ public class Client extends Ice.Application public int run(String[] args) { + // + // Since this is an interactive demo we want to clear the + // Application installed interrupt callback and install our + // own shutdown hook. + // + setInterruptHook(new ShutdownHook()); + Ice.RouterPrx defaultRouter = communicator().getDefaultRouter(); if(defaultRouter == null) { diff --git a/java/demo/Ice/callback/Client.java b/java/demo/Ice/callback/Client.java index 35a91f8b6ac..f382f6cbf66 100644 --- a/java/demo/Ice/callback/Client.java +++ b/java/demo/Ice/callback/Client.java @@ -11,6 +11,22 @@ 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() { @@ -31,6 +47,13 @@ public class Client extends Ice.Application public int run(String[] args) { + // + // Since this is an interactive demo we want to clear the + // Application installed interrupt callback and install our + // own shutdown hook. + // + setInterruptHook(new ShutdownHook()); + CallbackSenderPrx twoway = CallbackSenderPrxHelper.checkedCast( communicator().propertyToProxy("Callback.Client.CallbackServer"). ice_twoway().ice_timeout(-1).ice_secure(false)); diff --git a/java/demo/Ice/hello/Client.java b/java/demo/Ice/hello/Client.java index df647df390e..67fd95e2d3e 100644 --- a/java/demo/Ice/hello/Client.java +++ b/java/demo/Ice/hello/Client.java @@ -11,6 +11,22 @@ 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() { @@ -33,6 +49,13 @@ public class Client extends Ice.Application public int run(String[] args) { + // + // 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 twoway = HelloPrxHelper.checkedCast( communicator().propertyToProxy("Hello.Proxy").ice_twoway().ice_timeout(-1).ice_secure(false)); if(twoway == null) @@ -206,3 +229,4 @@ public class Client extends Ice.Application System.exit(status); } } + diff --git a/java/demo/Ice/invoke/Client.java b/java/demo/Ice/invoke/Client.java index 0ba48171d1c..1275ecaad12 100644 --- a/java/demo/Ice/invoke/Client.java +++ b/java/demo/Ice/invoke/Client.java @@ -30,9 +30,32 @@ public class Client extends Ice.Application "?: help\n"); } + class ShutdownHook extends Thread + { + public void + run() + { + try + { + communicator().destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } + } + public int run(String[] args) { + // + // Since this is an interactive demo we want to clear the + // Application installed interrupt callback and install our + // own shutdown hook. + // + setInterruptHook(new ShutdownHook()); + Ice.ObjectPrx obj = communicator().propertyToProxy("Printer.Proxy"); menu(); diff --git a/java/demo/Ice/nested/Client.java b/java/demo/Ice/nested/Client.java index b16a183b257..60264585c7e 100644 --- a/java/demo/Ice/nested/Client.java +++ b/java/demo/Ice/nested/Client.java @@ -11,10 +11,40 @@ import Demo.*; public class Client extends Ice.Application { + class ShutdownHook extends Thread + { + public void + run() + { + /* + * For this demo we won't destroy the communicator since it has to + * wait for any outstanding invocations to complete which may take + * some time if the nesting level is exceeded. + * + try + { + communicator().destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + */ + } + } + public int run(String[] args) { - NestedPrx nested = NestedPrxHelper.checkedCast(communicator().propertyToProxy("Nested.Client.NestedServer")); + // + // Since this is an interactive demo we want to clear the + // Application installed interrupt callback and install our + // own shutdown hook. + // + setInterruptHook(new ShutdownHook()); + + NestedPrx nested = NestedPrxHelper.checkedCast( + communicator().propertyToProxy("Nested.Client.NestedServer")); if(nested == null) { System.err.println("invalid proxy"); diff --git a/java/demo/Ice/session/Client.java b/java/demo/Ice/session/Client.java index 5b5a0be67a1..0009a2fefec 100644 --- a/java/demo/Ice/session/Client.java +++ b/java/demo/Ice/session/Client.java @@ -11,6 +11,24 @@ import Demo.*; public class Client extends Ice.Application { + class ShutdownHook extends Thread + { + public void + run() + { + System.out.println("Hi"); + cleanup(true); + try + { + communicator().destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } + } + static private class SessionRefreshThread extends Thread { SessionRefreshThread(Ice.Logger logger, long timeout, SessionPrx session) @@ -76,6 +94,13 @@ public class Client extends Ice.Application public int run(String[] args) { + // + // Since this is an interactive demo we want to clear the + // Application installed interrupt callback and install our + // own shutdown hook. + // + setInterruptHook(new ShutdownHook()); + java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); String name; try @@ -102,15 +127,17 @@ public class Client extends Ice.Application return 1; } - SessionPrx session = factory.create(name); - SessionRefreshThread refresh = new SessionRefreshThread(communicator().getLogger(), 5000, session); - refresh.start(); - + synchronized(this) + { + _session = factory.create(name); + _refresh = new SessionRefreshThread(communicator().getLogger(), 5000, _session); + _refresh.start(); + } + java.util.ArrayList hellos = new java.util.ArrayList(); menu(); - try { boolean destroy = true; @@ -149,7 +176,7 @@ public class Client extends Ice.Application } else if(line.equals("c")) { - hellos.add(session.createHello()); + hellos.add(_session.createHello()); System.out.println("created hello object " + (hellos.size()-1)); } else if(line.equals("s")) @@ -177,26 +204,8 @@ public class Client extends Ice.Application menu(); } } - // - // The refresher thread must be terminated before destroy is - // called, otherwise it might get ObjectNotExistException. refresh - // is set to 0 so that if session->destroy() raises an exception - // the thread will not be re-terminated and re-joined. - // - refresh.terminate(); - try - { - refresh.join(); - } - catch(InterruptedException e) - { - } - refresh = null; - if(destroy) - { - session.destroy(); - } + cleanup(destroy); if(shutdown) { factory.shutdown(); @@ -212,22 +221,39 @@ public class Client extends Ice.Application } finally { - if(refresh != null) - { - refresh.terminate(); - try - { - refresh.join(); - } - catch(InterruptedException e) - { - } - } + cleanup(true); } return 0; } + synchronized private void + cleanup(boolean destroy) + { + // + // The refresher thread must be terminated before destroy is + // called, otherwise it might get ObjectNotExistException. + // + if(_refresh != null) + { + _refresh.terminate(); + try + { + _refresh.join(); + } + catch(InterruptedException e) + { + } + _refresh = null; + } + + if(destroy && _session != null) + { + _session.destroy(); + _session = null; + } + } + public static void main(String[] args) { @@ -235,4 +261,7 @@ public class Client extends Ice.Application int status = app.main("Client", args, "config.client"); System.exit(status); } + + private SessionRefreshThread _refresh = null; + private SessionPrx _session = null; } diff --git a/java/demo/Ice/throughput/Client.java b/java/demo/Ice/throughput/Client.java index 99bfdcef97a..1d926a71b0a 100644 --- a/java/demo/Ice/throughput/Client.java +++ b/java/demo/Ice/throughput/Client.java @@ -11,6 +11,22 @@ 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() { @@ -38,6 +54,13 @@ public class Client extends Ice.Application public int run(String[] args) { + // + // Since this is an interactive demo we want to clear the + // Application installed interrupt callback and install our + // own shutdown hook. + // + setInterruptHook(new ShutdownHook()); + Ice.ObjectPrx base = communicator().propertyToProxy("Throughput.Throughput"); ThroughputPrx throughput = ThroughputPrxHelper.checkedCast(base); if(throughput == null) diff --git a/java/demo/Ice/value/Client.java b/java/demo/Ice/value/Client.java index 3ef39e8a35b..f33166da5fd 100644 --- a/java/demo/Ice/value/Client.java +++ b/java/demo/Ice/value/Client.java @@ -11,6 +11,22 @@ 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 readline(java.io.BufferedReader in) { @@ -27,6 +43,13 @@ public class Client extends Ice.Application public int run(String[] args) { + // + // Since this is an interactive demo we want to clear the + // Application installed interrupt callback and install our + // own shutdown hook. + // + setInterruptHook(new ShutdownHook()); + Ice.ObjectPrx base = communicator().propertyToProxy("Value.Initial"); InitialPrx initial = InitialPrxHelper.checkedCast(base); if(initial == null) diff --git a/java/demo/IceBox/hello/Client.java b/java/demo/IceBox/hello/Client.java index cfa4701dd7c..6a7c1f5156a 100644 --- a/java/demo/IceBox/hello/Client.java +++ b/java/demo/IceBox/hello/Client.java @@ -11,6 +11,22 @@ 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 void menu() { @@ -29,6 +45,13 @@ public class Client extends Ice.Application public int run(String[] args) { + // + // 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 twoway = HelloPrxHelper.checkedCast( communicator().propertyToProxy("Hello.Proxy").ice_twoway().ice_timeout(-1).ice_secure(false)); if(twoway == null) diff --git a/java/demo/IceGrid/allocate/Client.java b/java/demo/IceGrid/allocate/Client.java index a82004d6763..d8eb2e81b0d 100644 --- a/java/demo/IceGrid/allocate/Client.java +++ b/java/demo/IceGrid/allocate/Client.java @@ -11,6 +11,23 @@ import Demo.*; public class Client extends Ice.Application { + class ShutdownHook extends Thread + { + public void + run() + { + cleanup(); + try + { + communicator().destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } + } + static private class SessionKeepAliveThread extends Thread { SessionKeepAliveThread(IceGrid.SessionPrx session, long timeout) @@ -73,6 +90,13 @@ public class Client extends Ice.Application public int run(String[] args) { + // + // Since this is an interactive demo we want to clear the + // Application installed interrupt callback and install our + // own shutdown hook. + // + setInterruptHook(new ShutdownHook()); + int status = 0; IceGrid.RegistryPrx registry = IceGrid.RegistryPrxHelper.checkedCast(communicator().stringToProxy("DemoIceGrid/Registry")); @@ -83,7 +107,6 @@ public class Client extends Ice.Application } java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); - IceGrid.SessionPrx session; while(true) { System.out.println("This demo accepts any user-id / password combination."); @@ -102,7 +125,10 @@ public class Client extends Ice.Application try { - session = registry.createSession(id, pw); + synchronized(this) + { + _session = registry.createSession(id, pw); + } break; } catch(IceGrid.PermissionDeniedException ex) @@ -116,8 +142,11 @@ public class Client extends Ice.Application } } - SessionKeepAliveThread keepAlive = new SessionKeepAliveThread(session, registry.getSessionTimeout() / 2); - keepAlive.start(); + synchronized(this) + { + _keepAlive = new SessionKeepAliveThread(_session, registry.getSessionTimeout() / 2); + _keepAlive.start(); + } try { @@ -132,11 +161,11 @@ public class Client extends Ice.Application try { hello = HelloPrxHelper.checkedCast( - session.allocateObjectById(communicator().stringToIdentity("hello"))); + _session.allocateObjectById(communicator().stringToIdentity("hello"))); } catch(IceGrid.ObjectNotRegisteredException ex) { - hello = HelloPrxHelper.checkedCast(session.allocateObjectByType("::Demo::Hello")); + hello = HelloPrxHelper.checkedCast(_session.allocateObjectByType("::Demo::Hello")); } menu(); @@ -197,22 +226,36 @@ public class Client extends Ice.Application status = 1; } + cleanup(); + + return status; + } + + synchronized void + cleanup() + { // // Destroy the keepAlive thread and the sesion object otherwise // the session will be kept allocated until the timeout occurs. // Destroying the session will release all allocated objects. // - keepAlive.terminate(); - try + if(_keepAlive != null) { - keepAlive.join(); + _keepAlive.terminate(); + try + { + _keepAlive.join(); + } + catch(InterruptedException e) + { + } + _keepAlive = null; } - catch(InterruptedException e) + if(_session != null) { + _session.destroy(); + _session = null; } - session.destroy(); - - return status; } public static void @@ -222,4 +265,7 @@ public class Client extends Ice.Application int status = app.main("Client", args, "config.client"); System.exit(status); } + + SessionKeepAliveThread _keepAlive; + IceGrid.SessionPrx _session; } diff --git a/java/demo/IceGrid/sessionActivation/Client.java b/java/demo/IceGrid/sessionActivation/Client.java index 7b89d4b16f9..3449068b79a 100644 --- a/java/demo/IceGrid/sessionActivation/Client.java +++ b/java/demo/IceGrid/sessionActivation/Client.java @@ -11,6 +11,23 @@ import Demo.*; public class Client extends Ice.Application { + class ShutdownHook extends Thread + { + public void + run() + { + cleanup(); + try + { + communicator().destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } + } + static private class SessionKeepAliveThread extends Thread { SessionKeepAliveThread(IceGrid.SessionPrx session, long timeout) @@ -72,6 +89,13 @@ public class Client extends Ice.Application public int run(String[] args) { + // + // Since this is an interactive demo we want to clear the + // Application installed interrupt callback and install our + // own shutdown hook. + // + setInterruptHook(new ShutdownHook()); + int status = 0; IceGrid.RegistryPrx registry = IceGrid.RegistryPrxHelper.checkedCast(communicator().stringToProxy("DemoIceGrid/Registry")); @@ -82,7 +106,6 @@ public class Client extends Ice.Application } java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); - IceGrid.SessionPrx session; while(true) { System.out.println("This demo accepts any user-id / password combination."); @@ -101,7 +124,10 @@ public class Client extends Ice.Application try { - session = registry.createSession(id, pw); + synchronized(this) + { + _session = registry.createSession(id, pw); + } break; } catch(IceGrid.PermissionDeniedException ex) @@ -115,13 +141,16 @@ public class Client extends Ice.Application } } - SessionKeepAliveThread keepAlive = new SessionKeepAliveThread(session, registry.getSessionTimeout() / 2); - keepAlive.start(); + synchronized(this) + { + _keepAlive = new SessionKeepAliveThread(_session, registry.getSessionTimeout() / 2); + _keepAlive.start(); + } try { HelloPrx hello = HelloPrxHelper.checkedCast( - session.allocateObjectById(communicator().stringToIdentity("hello"))); + _session.allocateObjectById(communicator().stringToIdentity("hello"))); menu(); @@ -182,22 +211,36 @@ public class Client extends Ice.Application status = 1; } + cleanup(); + + return status; + } + + synchronized void + cleanup() + { // // Destroy the keepAlive thread and the sesion object otherwise // the session will be kept allocated until the timeout occurs. // Destroying the session will release all allocated objects. // - keepAlive.terminate(); - try + if(_keepAlive != null) { - keepAlive.join(); + _keepAlive.terminate(); + try + { + _keepAlive.join(); + } + catch(InterruptedException e) + { + } + _keepAlive = null; } - catch(InterruptedException e) + if(_session != null) { + _session.destroy(); + _session = null; } - session.destroy(); - - return status; } public static void @@ -207,4 +250,7 @@ public class Client extends Ice.Application int status = app.main("Client", args, "config.client"); System.exit(status); } + + SessionKeepAliveThread _keepAlive; + IceGrid.SessionPrx _session; } diff --git a/java/demo/IceGrid/simple/Client.java b/java/demo/IceGrid/simple/Client.java index 1c9333080ba..d5ae5065837 100644 --- a/java/demo/IceGrid/simple/Client.java +++ b/java/demo/IceGrid/simple/Client.java @@ -11,6 +11,22 @@ 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 void menu() { @@ -26,6 +42,13 @@ public class Client extends Ice.Application run(String[] args) { // + // Since this is an interactive demo we want to clear the + // Application installed interrupt callback and install our + // own shutdown hook. + // + setInterruptHook(new ShutdownHook()); + + // // First we try to connect to the object with the `hello' // identity. If it's not registered with the registry, we // search for an object with the ::Demo::Hello type. |