• 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 2593 for trunk/components/tools/OmeroPy/src/omero/__init__.py

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

ticket:1018 - Second attempt at improving OmeroSessions in blitz

This tries to keep up with an individual client via a uuid set
on the client side. This may also be sub-optimal. A better idea
may be using individual ServiceFactory instances which talk to
the same session (in which case only the SessionManager? need be
distributed)

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

    r2592 r2593  
    1818from omero_ext import pysys 
    1919import omero_Constants_ice 
     20import uuid 
    2021 
    2122class client(object): 
    … …  
    3132 
    3233        self.sf = None 
    33         self.ic = None 
    34         ic = Ice.initialize(args,id) 
    35         if not ic: 
     34        self.ic = Ice.initialize(args,id) 
     35        if not self.ic: 
    3636            raise ClientError("Improper initialization") 
     37        # Register Object Factory 
    3738        self.of = ObjectFactory() 
    38         self.of.registerObjectFactory(ic) 
    39         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         """ 
    56         self.close_on_destroy = False 
     39        self.of.registerObjectFactory(self.ic) 
     40        # Define our unique identifier (used during close/detach) 
     41        self.ic.getImplicitContext().put(omero.constants.CLIENT_UUID, str(uuid.uuid4())) 
    5742 
    5843    def __del__(self): 
    … …  
    6045            self.destroyConnection() 
    6146        except exceptions.Exception, e: 
    62             print "Error in __del__:" + str(e.__class__) 
     47            print "Ignoring error in client.__del__:" + str(e.__class__) 
    6348 
    6449    def getCommunicator(self): 
    … …  
    216201            file.close() 
    217202 
    218     def destroyConnection(self): 
     203    def closeSession(self): 
    219204        """ 
    220205        Closes the Router connection created by createSession(). Due to a bug in Ice, 
    221206        only one connection is allowed per communicator, so we also destroy the communicator. 
    222207        """ 
     208 
     209        # If 'sf' exists we remove it. 
     210        if not hasattr(self, 'sf'): 
     211            self.sf = None 
     212 
    223213        # If 'ic' does not exist we don't have anything to do 
    224214        if not hasattr(self, 'ic') or not self.ic: 
    225215            return 
    226  
    227         if self.close_on_destroy: 
    228             self.closeSession() 
    229216 
    230217        prx = self.ic.getDefaultRouter() 
    … …  
    250237        self.ic = None 
    251238 
    252     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         """ 
    258         # If 'sf' does not exist we don't have a session at all 
    259         if not hasattr(self, 'sf'): 
    260             return 
    261         # But even if we do have 'sf', the connection may have been lost and 'close' will fail 
    262         try: 
    263             try: 
    264                 self.sf.close() 
    265             except: 
    266                 pass 
    267         finally: 
    268             self.sf = None 
    269  
    270239    def _env(self, method, *args): 
    271240        """ Helper method to access session environment""" 

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/