• Views
  • Iteration Report
  • My Iteration Report
  •  
OMERO.server
  • Login
  • Help/Guide
  • About Trac
  • Preferences
  • Wiki
  • Timeline
  • Roadmap
  • Browse Source
  • View Tickets
  • Search

Context Navigation

  • ← Previous Change
  • Next Change →

Changeset 2592 for trunk/components/tools/OmeroPy/src/omero/__init__.py

Show
Ignore:
Timestamp:
07/05/08 22:16:04 (5 months ago)
Author:
jmoore
Message:

ticket:1018 - Initial version of OmeroSessions reference counting

Implementation is incomplete in the blitz case since there are two
possible "closers" - the user and the glacier session, which must
be taken into account.

Files:
1 modified

  • trunk/components/tools/OmeroPy/src/omero/__init__.py (modified) (5 diffs)

Legend:

Unmodified
Added
Removed
  • trunk/components/tools/OmeroPy/src/omero/__init__.py

    r2396 r2592  
    1111""" 
    1212 
    13 import exceptions 
     13import exceptions, traceback 
    1414import Ice, Glacier2 
    1515import api 
    … …  
    2121class client(object): 
    2222    """ 
    23     Central blitz entry point 
     23    Central blitz entry point. Currently useful for a single session, after closing the 
     24    connection, create another instance. 
    2425 
    2526    Typical usage includes: 
    … …  
    3738        self.of.registerObjectFactory(ic) 
    3839        self.ic = ic 
     40        self.close_on_destroy = True 
     41 
     42    def closeOnDestroy(self): 
     43        """ 
     44        Closes the blitz session when destroyConnection() is called on exit. 
     45        This prevents other clients from attaching to the same blitz session, 
     46        and is more secure. 
     47        """ 
     48        self.close_on_destroy = True 
     49 
     50    def detachOnDestroy(self): 
     51        """ 
     52        Prevents the blitz session from being closed when destroyConnection() 
     53        is called. This will allow other clients to attach to the session for 
     54        distribtued work. This is less secure, but in many cases valuable. 
     55        """ 
    3956        self.close_on_destroy = False 
    4057 
    41     def closeOnDestroy(self): 
    42         self.close_on_destroy = True 
    43  
    4458    def __del__(self): 
    45         if self.close_on_destroy: 
    46             self.closeSession() 
    47         if self.ic: 
    48             try: 
    49                 self.ic.destroy() 
    50             except (), msg: 
    51                 pysys.stderr.write("Ice exception while destroying communicator:") 
    52                 pysys.stderr.write(msg) 
    53             self.ic = None 
     59        try: 
     60            self.destroyConnection() 
     61        except exceptions.Exception, e: 
     62            print "Error in __del__:" + str(e.__class__) 
    5463 
    5564    def getCommunicator(self): 
    … …  
    207216            file.close() 
    208217 
     218    def destroyConnection(self): 
     219        """ 
     220        Closes the Router connection created by createSession(). Due to a bug in Ice, 
     221        only one connection is allowed per communicator, so we also destroy the communicator. 
     222        """ 
     223        # If 'ic' does not exist we don't have anything to do 
     224        if not hasattr(self, 'ic') or not self.ic: 
     225            return 
     226 
     227        if self.close_on_destroy: 
     228            self.closeSession() 
     229 
     230        prx = self.ic.getDefaultRouter() 
     231        router = Glacier2.RouterPrx.checkedCast(prx) 
     232 
     233        # Now destroy the actual session if possible, 
     234        # which will always trigger an exception, 
     235        # regardless of actually being connected or not 
     236        if router: 
     237            try: 
     238                router.destroySession() 
     239            except exceptions.Exception, e: 
     240                pass 
     241                # SNEE happens if we call sf.close() before 
     242                # calling destroySession(). CLE happens since 
     243                # we are disconnecting 
     244 
     245        try: 
     246            self.ic.destroy() 
     247        except (), msg: 
     248            pysys.stderr.write("Ice exception while destroying communicator:") 
     249            pysys.stderr.write(msg) 
     250        self.ic = None 
     251 
    209252    def closeSession(self): 
     253        """ 
     254        Call close on the session (ServiceFactoryPrx) which first decrements 
     255        the reference count. If its reference count becomes 0, then the session 
     256        will be removed from the server. 
     257        """ 
    210258        # If 'sf' does not exist we don't have a session at all 
    211259        if not hasattr(self, 'sf'): 
    … …  
    219267        finally: 
    220268            self.sf = None 
    221         # Now destroy the actual session, which will always trigger an exception, regardless of 
    222         # actually being connected or not 
    223         prx = self.ic.getDefaultRouter() 
    224         router = Glacier2.RouterPrx.checkedCast(prx) 
    225         try: 
    226             router.destroySession() 
    227         except Ice.ConnectionLostException: 
    228             pass 
    229269 
    230270    def _env(self, method, *args): 

Download in other formats:

  • Unified Diff
  • Zip Archive

Trac Powered

Powered by Trac 0.11
By Edgewall Software.

Visit the Trac open source project at
http://trac.edgewall.org/