diff options
author | Jose <jose@zeroc.com> | 2009-10-02 02:23:52 +0200 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2009-10-02 02:23:52 +0200 |
commit | 1d9f29e281770ecdad4a245271f2b828bd64a32f (patch) | |
tree | ac083f28b06a444e484c24f8fcf1b12a36202c84 /py/demo/Glacier2/callback/Client.py | |
parent | Updated demo README (diff) | |
download | ice-1d9f29e281770ecdad4a245271f2b828bd64a32f.tar.bz2 ice-1d9f29e281770ecdad4a245271f2b828bd64a32f.tar.xz ice-1d9f29e281770ecdad4a245271f2b828bd64a32f.zip |
3772. Recovering from Glacier2 / Ice router session failure.
Diffstat (limited to 'py/demo/Glacier2/callback/Client.py')
-rwxr-xr-x | py/demo/Glacier2/callback/Client.py | 91 |
1 files changed, 17 insertions, 74 deletions
diff --git a/py/demo/Glacier2/callback/Client.py b/py/demo/Glacier2/callback/Client.py index b8a297f5e59..7342aa378ba 100755 --- a/py/demo/Glacier2/callback/Client.py +++ b/py/demo/Glacier2/callback/Client.py @@ -9,7 +9,6 @@ # ********************************************************************** import sys, threading, Ice, Glacier2 - Ice.loadSlice('Callback.ice') import Demo @@ -27,72 +26,35 @@ x: exit ?: help """ -class SessionRefreshThread(threading.Thread): - def __init__(self, router, timeout): - threading.Thread.__init__(self) - self._router = router - self._timeout = timeout - self._terminated = False - self._cond = threading.Condition() - - def run(self): - self._cond.acquire() - try: - while not self._terminated: - self._cond.wait(self._timeout) - if not self._terminated: - try: - self._router.refreshSession() - except Ice.LocalException, ex: - pass - finally: - self._cond.release() - - def terminate(self): - self._cond.acquire() - try: - self._terminated = True - self._cond.notify() - finally: - self._cond.release() - class CallbackReceiverI(Demo.CallbackReceiver): def callback(self, current=None): print "received callback" -class Client(Ice.Application): - def run(self, args): - if len(args) > 1: - print self.appName() + ": too many arguments" - return 1 - - defaultRouter = self.communicator().getDefaultRouter() - if not defaultRouter: - print self.appName() + ": no default router set" - return 1 +class Client(Glacier2.Application): - router = Glacier2.RouterPrx.checkedCast(defaultRouter) - if not router: - print self.appName() + ": configured router is not a Glacier2 router" - return 1 + def createSession(self): + session = None while True: print "This demo accepts any user-id / password combination." id = raw_input("user id: ") pw = raw_input("password: ") try: - router.createSession(id, pw) + session = self.router().createSession(id, pw) break except Glacier2.PermissionDeniedException, ex: print "permission denied:\n" + ex.reason + except Glacier2.CannotCreateSessionException, ex: + print "cannot create session:\n" + ex.reason + return session - refresh = SessionRefreshThread(router, router.getSessionTimeout() / 2.0) - refresh.start() + def runWithSession(self, args): + if len(args) > 1: + print self.appName() + ": too many arguments" + return 1 + + callbackReceiverIdent = self.createCallbackIdentity("callbackReceiver") - category = router.getCategoryForClient() - callbackReceiverIdent = Ice.Identity() - callbackReceiverIdent.name = "callbackReceiver" - callbackReceiverIdent.category = category callbackReceiverFakeIdent = Ice.Identity() callbackReceiverFakeIdent.name = "callbackReceiver" callbackReceiverFakeIdent.category = "fake" @@ -102,12 +64,11 @@ class Client(Ice.Application): oneway = Demo.CallbackPrx.uncheckedCast(twoway.ice_oneway()) batchOneway = Demo.CallbackPrx.uncheckedCast(twoway.ice_batchOneway()) - adapter = self.communicator().createObjectAdapterWithRouter("Callback.Client", defaultRouter) - adapter.add(CallbackReceiverI(), callbackReceiverIdent) - adapter.add(CallbackReceiverI(), callbackReceiverFakeIdent) - adapter.activate() - twowayR = Demo.CallbackReceiverPrx.uncheckedCast(adapter.createProxy(callbackReceiverIdent)) + self.objectAdapter().add(CallbackReceiverI(), callbackReceiverIdent) + self.objectAdapter().add(CallbackReceiverI(), callbackReceiverFakeIdent) + + twowayR = Demo.CallbackReceiverPrx.uncheckedCast(self.objectAdapter().createProxy(callbackReceiverIdent)) onewayR = Demo.CallbackReceiverPrx.uncheckedCast(twowayR.ice_oneway()) override = '' @@ -169,24 +130,6 @@ class Client(Ice.Application): except EOFError: break - # - # 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() - refresh.join() - refresh = None - - try: - router.destroySession() - except Glacier2.SessionNotExistException, ex: - print ex - except Ice.ConnectionLostException: - # Expected: the router closed the connection. - pass - return 0 app = Client() |