diff options
Diffstat (limited to 'java/demo/Glacier2/callback/Client.java')
-rw-r--r-- | java/demo/Glacier2/callback/Client.java | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/java/demo/Glacier2/callback/Client.java b/java/demo/Glacier2/callback/Client.java index 8f3eba5a129..17f3590f810 100644 --- a/java/demo/Glacier2/callback/Client.java +++ b/java/demo/Glacier2/callback/Client.java @@ -11,6 +11,52 @@ import Demo.*; public class Client extends Ice.Application { + + static private class SessionRefreshThread extends Thread + { + SessionRefreshThread(Glacier2.RouterPrx router, long timeout) + { + _router = router; + _timeout = timeout; + } + + synchronized public void + run() + { + while(!_terminated) + { + try + { + wait(_timeout); + } + catch(InterruptedException e) + { + } + if(!_terminated) + { + try + { + _router.ice_ping(); + } + catch(Ice.LocalException ex) + { + } + } + } + } + + synchronized private void + terminate() + { + _terminated = true; + notify(); + } + + final private Glacier2.RouterPrx _router; + final private long _timeout; + private boolean _terminated = false; + } + class ShutdownHook extends Thread { public void @@ -110,6 +156,9 @@ public class Client extends Ice.Application } } + SessionRefreshThread refresh = new SessionRefreshThread(router, router.getSessionTimeout() * 500); + refresh.start(); + String category = router.getCategoryForClient(); Ice.Identity callbackReceiverIdent = new Ice.Identity(); callbackReceiverIdent.name = "callbackReceiver"; @@ -246,6 +295,21 @@ public class Client extends Ice.Application } while(!line.equals("x")); + // + // The refresher thread must be terminated before the session + // is destroyed, otherwise it might get + // ObjectNotExistException. + // + refresh.terminate(); + try + { + refresh.join(); + } + catch(InterruptedException e) + { + } + refresh = null; + try { router.destroySession(); |