• 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 2594

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

ticket:1018 - Changed reference counting logic

  • No longer using AtomicInteger
  • Count is not allowed to go below 0
  • Rather, SessionManager? uses sub-zero values
Location:
trunk/components/server/src/ome/services/sessions
Files:
3 modified

  • SessionContextImpl.java (modified) (3 diffs)
  • SessionManager.java (modified) (1 diff)
  • SessionManagerImpl.java (modified) (3 diffs)

Legend:

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

    r2592 r2594  
    1111import java.util.Collections; 
    1212import java.util.List; 
    13 import java.util.concurrent.atomic.AtomicInteger; 
    1413 
    1514import ome.model.meta.Session; 
    … …  
    1716public class SessionContextImpl implements SessionContext { 
    1817 
    19     private final AtomicInteger refCount = new AtomicInteger(0); 
     18    private int ref = 0; 
     19    private final Object refLock = new Object(); 
    2020    private final Session session; 
    2121    private final List<Long> leaderOfGroups; 
    … …  
    3434 
    3535    public int refCount() { 
    36         return refCount.get(); 
     36        synchronized (refLock) { 
     37            return ref; 
     38        } 
    3739    } 
    3840 
    3941    public int increment() { 
    40         return refCount.incrementAndGet(); 
     42        synchronized (refLock) { 
     43            if (ref < 0) { 
     44                ref = 1; 
     45            } else { 
     46                ref = ref + 1; 
     47            } 
     48            return ref; 
     49        } 
    4150    } 
    4251 
    4352    public int decrement() { 
    44         return refCount.decrementAndGet(); 
     53        synchronized (refLock) { 
     54            if (ref < 1) { 
     55                ref = 0; 
     56            } else { 
     57                ref = ref - 1; 
     58            } 
     59            return ref; 
     60        } 
    4561    } 
    4662 
  • trunk/components/server/src/ome/services/sessions/SessionManager.java

    r2592 r2594  
    7575    Session find(String uuid); 
    7676 
    77     void close(String uuid); 
     77    /** 
     78     * If reference count for the session is less than 1, close the session. 
     79     * Otherwise decrement the reference count. The current reference count is 
     80     * returned. If -1, then no such session existed. If -2, then the session 
     81     * was removed. 
     82     */ 
     83    int close(String uuid); 
    7884 
    7985    // Security methods 
  • trunk/components/server/src/ome/services/sessions/SessionManagerImpl.java

    r2592 r2594  
    313313    /* 
    314314     */ 
    315     public void close(String uuid) { 
     315    public int close(String uuid) { 
    316316 
    317317        SessionContext ctx; 
    … …  
    319319            ctx = cache.getSessionContext(uuid); 
    320320        } catch (SessionException se) { 
    321             return; // EARLY EXIT! 
     321            return -1; // EARLY EXIT! 
    322322        } 
    323323 
    … …  
    340340            // since ehcache is not tx-friendly. 
    341341            cache.removeSession(uuid); 
     342            return -2; 
     343        } else { 
     344            return refCount; 
    342345        } 
    343346    } 

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/