diff options
author | Mark Spruiell <mes@zeroc.com> | 2005-02-08 22:00:55 +0000 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2005-02-08 22:00:55 +0000 |
commit | 880d45b7baf6ce19006fe461b3cd3070299c7b52 (patch) | |
tree | 6264f16f009542bcbbbe576b9ae45abc705f8169 /py/demo/Ice/bidir/Server.py | |
parent | Remove glacier test (diff) | |
download | ice-880d45b7baf6ce19006fe461b3cd3070299c7b52.tar.bz2 ice-880d45b7baf6ce19006fe461b3cd3070299c7b52.tar.xz ice-880d45b7baf6ce19006fe461b3cd3070299c7b52.zip |
adding bidir demo
Diffstat (limited to 'py/demo/Ice/bidir/Server.py')
-rw-r--r-- | py/demo/Ice/bidir/Server.py | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/py/demo/Ice/bidir/Server.py b/py/demo/Ice/bidir/Server.py new file mode 100644 index 00000000000..e73f72d6632 --- /dev/null +++ b/py/demo/Ice/bidir/Server.py @@ -0,0 +1,85 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2004 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 os, sys, traceback, threading, Ice + +slice_dir = os.getenv('ICEPY_HOME', '') +if len(slice_dir) == 0 or not os.path.exists(os.path.join(slice_dir, "slice")): + slice_dir = os.getenv('ICE_HOME', '') +if len(slice_dir) == 0 or not os.path.exists(os.path.join(slice_dir, "slice")): + print sys.argv[0] + ': Slice directory not found. Define ICEPY_HOME or ICE_HOME.' + sys.exit(1) + +Ice.loadSlice('-I' + slice_dir + '/slice Callback.ice') +import Demo + +class CallbackSenderI(Demo.CallbackSender, threading.Thread): + def __init__(self): + threading.Thread.__init__(self) + self._destroy = False + self._num = 0 + self._clients = [] + self._cond = threading.Condition() + + def destroy(self): + self._cond.acquire() + + print "destroying callback sender" + self._destroy = True + + try: + self._cond.notify() + finally: + self._cond.release() + + self.join() + + def addClient(self, ident, current=None): + print "adding client `" + Ice.identityToString(ident) + "'" + + client = Demo.CallbackReceiverPrx.uncheckedCast(current.con.createProxy(ident)) + self._clients.append(client) + + def run(self): + self._cond.acquire() + + try: + while not self._destroy: + self._cond.wait(2) + + if not self._destroy and len(self._clients) > 0: + self._num = self._num + 1 + + for p in self._clients[:]: # Iterate over a copy so we can modify the original list. + try: + p.callback(self._num) + except: + print "removing client `" + Ice.identityToString(p.ice_getIdentity()) + "':" + traceback.print_exc() + self._clients.remove(p) + finally: + self._cond.release() + +class CallbackServer(Ice.Application): + def run(self, args): + adapter = self.communicator().createObjectAdapter("Callback.Server") + sender = CallbackSenderI() + adapter.add(sender, Ice.stringToIdentity("sender")) + adapter.activate() + + sender.start() + try: + self.communicator().waitForShutdown() + finally: + sender.destroy() + + return 0 + +app = CallbackServer() +sys.exit(app.main(sys.argv, "config")) |