• 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 Changeset
  • Next Changeset →

Changeset 2597

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

ticket:1018 - Fixing memory leak in solution

  • Added ome/services/messaging.xml to publish messages to child contexts
  • Fixed ordering issues SessionManagerI
  • Also:
    • Using ice_getCommunicator() if ic null in omero.client
    • Catching exceptions on session close in test.integration.library
Location:
trunk/components
Files:
10 modified

  • blitz/resources/beanRefContext.xml (modified) (2 diffs)
  • blitz/resources/omero/test.xml (modified) (2 diffs)
  • blitz/src/ome/services/blitz/fire/SessionManagerI.java (modified) (3 diffs)
  • blitz/src/ome/services/blitz/impl/ServiceFactoryI.java (modified) (5 diffs)
  • blitz/test/ome/icy/model/utests/ServiceFactoryServiceCreationDestructionTest.java (modified) (1 diff)
  • server/resources/beanRefContext.xml (modified) (2 diffs)
  • server/src/ome/services/sessions/SessionManager.java (modified) (1 diff)
  • tools/OmeroPy/src/omero/__init__.py (modified) (1 diff)
  • tools/OmeroPy/test/integration/isession.py (modified) (3 diffs)
  • tools/OmeroPy/test/integration/library.py (modified) (3 diffs)

Legend:

Unmodified
Added
Removed
  • trunk/components/blitz/resources/beanRefContext.xml

    r2142 r2597  
    2424        <constructor-arg index="0"> 
    2525      <list> 
     26        <value>classpath:ome/services/messaging.xml</value> 
    2627        <value>classpath:omero/server.xml</value> 
    2728        <value>classpath:omero/constants.xml</value> 
    … …  
    5556        <constructor-arg index="0"> 
    5657      <list> 
     58        <value>classpath:ome/services/messaging.xml</value> 
    5759        <value>classpath:omero/server.xml</value> 
    5860        <value>classpath:omero/constants.xml</value> 
  • trunk/components/blitz/resources/omero/test.xml

    r2142 r2597  
    3737 <bean id="methodSecurity" factory-bean="methodMock" factory-method="proxy"/> 
    3838 <bean id="sessionManager" factory-bean="sessionsMock" factory-method="proxy"/> 
    39   
     39 <bean id="executor"       factory-bean="executorMock" factory-method="proxy"/> 
    4040 <!-- Here it is necessary to specify the HardWiredInterceptors instances 
    4141 even if they are *not* specified in Spring --> 
    … …  
    7777 </bean> 
    7878 
     79  
     80  <bean id="executorMock" class="ome.icy.fixtures.ExecutorMockFactory"/> 
     81 
    7982</beans> 
  • trunk/components/blitz/src/ome/services/blitz/fire/SessionManagerI.java

    r2596 r2597  
    128128                log.debug(String.format("Created session %s for user %s", 
    129129                        id.name, userId)); 
    130             } else { 
    131                 sessionToClientIds.get(s.getUuid()).add(session.clientId); 
    132                 if (log.isDebugEnabled()) { 
    133                     log.debug(String.format("Rejoined session %s for user %s", 
    134                             id.name, userId)); 
    135                 } 
    136  
    137             } 
     130            } 
     131            sessionToClientIds.get(s.getUuid()).add(session.clientId); 
     132            if (log.isDebugEnabled()) { 
     133                log.debug(String.format("Rejoined session %s for user %s", 
     134                        id.name, userId)); 
     135            } 
     136 
    138137            return Glacier2.SessionPrxHelper.uncheckedCast(_prx); 
    139138 
    140139        } catch (Exception t) { 
     140 
     141            if (t instanceof ApiUsageException) { 
     142                ApiUsageException aue = (ApiUsageException) t; 
     143                throw new CannotCreateSessionException(aue.message); 
     144            } 
     145 
    141146            ConvertToBlitzExceptionMessage convert = new ConvertToBlitzExceptionMessage( 
    142147                    this, t); 
    … …  
    150155            if (convert.to instanceof CannotCreateSessionException) { 
    151156                throw (CannotCreateSessionException) convert.to; 
    152             } else if (convert.to instanceof ApiUsageException) { 
    153                 ApiUsageException aue = (ApiUsageException) convert.to; 
    154                 throw new CannotCreateSessionException(aue.message); 
    155157            } 
    156158 
    … …  
    207209     *            {@link Ice.ObjectAdapter} 
    208210     */ 
    209     private void reapSessions(Ice.Current cantUseThisCurrent) { 
     211    public void reapSessions(Ice.Current cantUseThisCurrent) { 
    210212        Ice.ObjectAdapter adapter = cantUseThisCurrent.adapter; 
    211213        synchronized (sessionsForReaping) { 
    212             List<String> ids = new ArrayList<String>(sessionsForReaping); 
    213             for (String id : ids) { 
    214                 for (String clientId : sessionToClientIds.get(id)) { 
     214            List<String> sessionIds = new ArrayList<String>(sessionsForReaping); 
     215            for (String sessionId : sessionIds) { 
     216                Set<String> clientIds = sessionToClientIds.keySet(); 
     217                for (String clientId : clientIds) { 
    215218                    try { 
    216219                        Ice.Identity iid = ServiceFactoryI.sessionId(clientId, 
    217                                 id); 
     220                                sessionId); 
    218221                        Ice.Object obj = adapter.find(iid); 
    219222                        if (obj == null) { 
    220                             log.debug(id + " already removed."); 
     223                            log.debug(Ice.Util.identityToString(iid) 
     224                                    + " already removed."); 
    221225                        } else { 
    222226                            ServiceFactoryI sf = (ServiceFactoryI) obj; 
    223227                            sf.doDestroy(adapter); 
    224228                        } 
    225                         sessionsForReaping.remove(id); 
    226229                    } catch (Exception e) { 
    227                         log.error("Error reaping session " + id 
     230                        log.error("Error reaping session " + sessionId 
    228231                                + " from client " + clientId, e); 
    229232                    } 
    230233                } 
     234                sessionToClientIds.remove(sessionId); 
     235                sessionsForReaping.remove(sessionId); 
    231236            } 
    232237        } 
  • trunk/components/blitz/src/ome/services/blitz/impl/ServiceFactoryI.java

    r2596 r2597  
    2121import ome.api.JobHandle; 
    2222import ome.api.ServiceInterface; 
    23 import ome.conditions.InternalException; 
    2423import ome.logic.HardWiredInterceptor; 
    2524import ome.services.blitz.fire.AopContextInitializer; 
    … …  
    516515 
    517516        } 
     517 
     518        // All resources cleaned up or not based on the reference count. 
     519        // Now we can remove the current session. If an exception if thrown, 
     520        // there's not much we can do. 
     521        try { 
     522            current.adapter.remove(sessionId(principal.getName())); 
     523        } catch (Throwable t) { 
     524            // FIXME 
     525            log.error("Possible memory leak: can't remove service factory", t); 
     526        } 
     527 
    518528    } 
    519529 
    520530    /** 
    521      * Performs the actual cleanup operation. Since {@link #destroy()} is called 
    522      * non-discriminantly by the router, even when a client has just died, we 
    523      * have this internal method for handling the actual closing of resources. 
     531     * Performs the actual cleanup operation on all the resources shared between 
     532     * this and other {@link ServiceFactoryI} instances in the same 
     533     * {@link Session}. Since {@link #destroy()} is called regardless by the 
     534     * router, even when a client has just died, we have this internal method 
     535     * for handling the actual closing of resources. 
    524536     */ 
    525537    public void doDestroy(Ice.ObjectAdapter adapter) { 
    … …  
    534546        Set<String> ipIds = interactiveSlots.keySet(); 
    535547        for (String id : ipIds) { 
    536             InteractiveProcessorI ip = (InteractiveProcessorI) interactiveSlots 
    537                     .get(id); 
    538             ip.stop(); 
    539             adapter.remove(Ice.Util.stringToIdentity(id)); 
    540             interactiveSlots.remove(id); 
     548            InteractiveProcessorI ip = null; 
     549            try { 
     550                ip = (InteractiveProcessorI) interactiveSlots.get(id); 
     551                ip.stop(); 
     552            } catch (Exception e) { 
     553                log.error("Error stopping interactive processor: " + ip); 
     554            } finally { 
     555                adapter.remove(Ice.Util.stringToIdentity(id)); 
     556                interactiveSlots.remove(id); 
     557            } 
    541558        } 
    542559 
    … …  
    568585        } 
    569586 
    570         // All resources cleaned up to the best of our ability, 
    571         // now we can remove the current session. If an exception if thrown, 
    572         // there's not much we can do. 
    573         try { 
    574             adapter.remove(sessionId(principal.getName())); 
    575         } catch (Throwable t) { 
    576             // FIXME 
    577             InternalException ie = new InternalException(t.getMessage()); 
    578             ie.setStackTrace(t.getStackTrace()); 
    579         } 
    580587    } 
    581588 
    … …  
    710717            if (null == already) { 
    711718                current.adapter.add(servant, id); 
     719                if (log.isInfoEnabled()) { 
     720                    log.info("Created servant:" + servantString(id, servant)); 
     721                } 
    712722            } else { 
    713723                current.adapter.remove(id); 
    714724                current.adapter.add(servant, id); 
    715             } 
    716             if (log.isInfoEnabled()) { 
    717                 log.info("Created servant:" + servantString(id, servant)); 
     725                if (already.hashCode() != servant.hashCode()) { 
     726                    log.info(String.format("Replacing %s with %s", 
     727                            servantString(id, already), servantString(id, 
     728                                    servant))); 
     729                } 
    718730            } 
    719731        } catch (Exception e) { 
  • trunk/components/blitz/test/ome/icy/model/utests/ServiceFactoryServiceCreationDestructionTest.java

    r2383 r2597  
    165165        callsActiveServices(Collections.singletonList(reServiceId)); 
    166166        String id = sf.activeServices(curr).get(0).toString(); 
    167         Ice.Current curr = new Ice.Current(); 
    168         curr.id = Ice.Util.stringToIdentity("username/sessionid"); 
    169         curr.adapter = adapter; 
    170167        // Events now called by SessionManagerI 
    171         sf.unregisterServant(Ice.Util.stringToIdentity(id), curr); 
     168        sf.unregisterServant(Ice.Util.stringToIdentity(id), adapter); 
    172169    } 
    173170 
  • trunk/components/server/resources/beanRefContext.xml

    r2128 r2597  
    2424    <constructor-arg index="0"> 
    2525      <list> 
     26        <value>classpath:ome/services/messaging.xml</value> 
    2627        <value>classpath:ome/model.xml</value> 
    2728      </list> 
    … …  
    3435    <constructor-arg index="0"> 
    3536      <list> 
     37        <value>classpath:ome/services/messaging.xml</value> 
    3638        <!-- Arranged roughly in stack order --> 
    3739        <value>classpath:ome/services/config-local.xml</value> 
  • trunk/components/server/src/ome/services/sessions/SessionManager.java

    r2594 r2597  
    7070 
    7171    /** 
     72     * Return the number of client which are presumed to be attached to this 
     73     * session. 
     74     */ 
     75    int getReferenceCount(String uuid); 
     76 
     77    /** 
    7278     * @param sessionId 
    7379     * @return A current session. Null if the session id is not found. 
  • trunk/components/tools/OmeroPy/src/omero/__init__.py

    r2595 r2597  
    219219        """ 
    220220 
    221         # If 'sf' exists we remove it. 
     221        # If 'sf' exists we remove it, but save it for the weird chance that ic is None 
     222        sf = None 
    222223        if hasattr(self, 'sf'): 
     224            sf = self.sf 
    223225            self.sf = None 
    224226 
    225227        # If 'ic' does not exist we don't have anything to do 
    226228        if not hasattr(self, 'ic') or not self.ic: 
    227             return 
     229            if sf: 
     230                self.ic = sf.ice_getCommunicator() 
     231            else: 
     232                return 
    228233 
    229234        try: 
  • trunk/components/tools/OmeroPy/test/integration/isession.py

    r2592 r2597  
    99 
    1010""" 
     11import unittest 
    1112import test.integration.library as lib 
    1213import omero 
    1314import omero_RTypes_ice 
     15import omero_Constants_ice 
    1416from omero_model_PixelsI import PixelsI 
    1517from omero_model_ImageI import ImageI 
    … …  
    4446 
    4547    def testCreateSessionForUser(self): 
    46         user = self.root.sf.getQueryService().findAllByQuery(""" 
     48        p = omero.sys.Parameters() 
     49        p.theFilter = omero.sys.Filter() 
     50        p.theFilter.limit = omero.RInt(1) 
     51        user = self.root.sf.getQueryService().findByQuery(""" 
    4752            select e from Experimenter e where e.id > 0 and e.omeName != 'guest' 
    48             """, None)[0] 
     53            """, p) 
    4954        p = omero.sys.Principal() 
    5055        p.name  = user.omeName.val 
    … …  
    7176 
    7277    def testCreationDestructionClosing(self): 
    73         self.client.detachOnDestroy() 
    74         sess = self.client.sf.ice_getIdentity().category 
    75         self.client.destroyConnection() 
     78        c1 = omero.client() 
     79        s1 = c1.createSession() 
     80        s1.detachOnDestroy() 
     81        uuid = s1.ice_getIdentity().name 
    7682 
    77         self.client = omero.client() 
    78         self.client.createSession(sess, sess) 
    79         self.client.closeOnDestroy() 
    80         self.client.destroyConnection() 
     83        # Intermediate "disrupter" 
     84        c2 = omero.client() 
     85        s2 = c2.createSession(uuid, uuid) 
     86        s2.closeOnDestroy() 
     87        s2.getAdminService().getEventContext() 
     88        c2.closeSession() 
     89 
     90        # 1 should still be able to continue 
     91        s1.getAdminService().getEventContext() 
     92 
     93        # Now if s1 exists another session should be able to connect 
     94        c1.closeSession() 
     95        c3 = omero.client() 
     96        s3 = c3.createSession(uuid, uuid) 
     97        s3.closeOnDestroy() 
     98        s3.getAdminService().getEventContext() 
     99        c3.closeSession() 
     100 
     101        # Now a connection should not be possible 
     102        c4 = omero.client() 
     103        s4 = c4.createSession(uuid, uuid); 
     104 
     105    def testSimpleDestruction(self): 
     106        c = omero.client() 
     107        c.ic.getImplicitContext().put(omero.constants.CLIENTUUID,"SimpleDestruction") 
     108        s = c.createSession() 
     109        s.closeOnDestroy() 
     110        c.closeSession() 
    81111 
    82112if __name__ == '__main__': 
  • trunk/components/tools/OmeroPy/test/integration/library.py

    r2397 r2597  
    1212import omero 
    1313import tempfile 
     14import traceback 
     15import exceptions 
    1416 
    1517class ITest(unittest.TestCase): 
    … …  
    3234 
    3335    def tearDown(self): 
    34         self.client.closeSession() 
     36        failure = False 
     37        try: 
     38            self.client.closeSession() 
     39        except: 
     40            traceback.print_exc() 
     41            failure = True 
    3542        if self.root: 
    36             self.root.closeSession() 
     43            try: 
     44                self.root.closeSession() 
     45            except: 
     46                traceback.print_exc() 
     47                failure = True 
    3748        for tmpfile in self.tmpfiles: 
    3849            try: 
    … …  
    4051            except: 
    4152                print "Error closing:"+tmpfile 
     53        if failure: 
     54           raise exceptions.Exception("Exception on client.closeSession") 

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/