• 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/server/src/ome/services/sessions/SessionManagerImpl.java

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/server/src/ome/services/sessions/SessionManagerImpl.java (modified) (8 diffs)

Legend:

Unmodified
Added
Removed
  • trunk/components/server/src/ome/services/sessions/SessionManagerImpl.java

    r2388 r2592  
    7373 
    7474    // Injected 
    75     OmeroContext context; 
    76     Roles roles; 
    77     SessionCache cache; 
    78     Executor executor; 
    79     long defaultTimeToIdle; 
    80     long defaultTimeToLive; 
     75    protected OmeroContext context; 
     76    protected Roles roles; 
     77    protected SessionCache cache; 
     78    protected Executor executor; 
     79    protected long defaultTimeToIdle; 
     80    protected long defaultTimeToLive; 
    8181 
    8282    /** 
    … …  
    8484     * {@link Executor} 
    8585     */ 
    86     Principal asroot; 
    87     SessionContext sc; 
     86    protected Principal asroot; 
     87    protected SessionContext sc; 
    8888 
    8989    // ~ Injectors 
    … …  
    155155            SessionContext context = cache.getSessionContext(credentials); 
    156156            if (context != null) { 
     157                context.increment(); 
    157158                return context.getSession(); // EARLY EXIT! 
    158159            } 
    … …  
    161162        } 
    162163 
    163         boolean ok = executeCheckPassword(_principal, credentials); 
     164        // Though trusted values, if we receive a null principal, not ok; 
     165        boolean ok = _principal == null ? false : executeCheckPassword( 
     166                _principal, credentials); 
    164167 
    165168        if (!ok) { 
    … …  
    179182                    .getName()); 
    180183            if (context != null) { 
     184                context.increment(); 
    181185                return context.getSession(); // EARLY EXIT! 
    182186            } 
    … …  
    205209            throw re; 
    206210        } 
     211 
     212        // All successful, increment and return. 
     213        ctx.increment(); 
    207214        return session; 
    208215    } 
    … …  
    294301    } 
    295302 
     303    public int getReferenceCount(String uuid) { 
     304        SessionContext ctx = cache.getSessionContext(uuid); 
     305        return ctx.refCount(); 
     306    } 
     307 
     308    public int detach(String uuid) { 
     309        SessionContext ctx = cache.getSessionContext(uuid); 
     310        return ctx.decrement(); 
     311    } 
     312 
    296313    /* 
    297314     */ 
    … …  
    302319            ctx = cache.getSessionContext(uuid); 
    303320        } catch (SessionException se) { 
    304             ctx = null; 
    305         } 
    306  
    307         if (ctx == null) { 
    308             return; 
    309         } 
    310  
    311         Session s = ctx.getSession(); 
    312         s.setClosed(new Timestamp(System.currentTimeMillis())); 
    313         update(s); 
    314  
    315         try { 
    316             context.publishEvent(new DestroySessionMessage(this, s.getUuid())); 
    317         } catch (RuntimeException re) { 
    318             log.warn("Session destruction cancelled by event listener", re); 
    319             throw re; 
    320         } 
    321         // This the publishEvent returns successfully, then we update our cache 
    322         // since ehcache is not tx-friendly. 
    323         cache.removeSession(uuid); 
     321            return; // EARLY EXIT! 
     322        } 
     323 
     324        int refCount = ctx.decrement(); 
     325        if (refCount < 1) { 
     326 
     327            Session s = ctx.getSession(); 
     328            s.setClosed(new Timestamp(System.currentTimeMillis())); 
     329            update(s); 
     330 
     331            try { 
     332                context.publishEvent(new DestroySessionMessage(this, s 
     333                        .getUuid())); 
     334            } catch (RuntimeException re) { 
     335                log.warn("Session destruction cancelled by event listener", re); 
     336                throw re; 
     337            } 
     338            // This the publishEvent returns successfully, then we update our 
     339            // cache 
     340            // since ehcache is not tx-friendly. 
     341            cache.removeSession(uuid); 
     342        } 
    324343    } 
    325344 

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/