• 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 2596 for trunk/components/blitz/src/ome/services/blitz/fire/SessionManagerI.java

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

ticket:1018 - Working solution (needs concurrency testing)

Each ServiceFactory instance now keeps track of its clientId.

This solution uses a managed map in SessionManagerI to
make up for the missing ObjectAdapter.findAll() method.

Files:
1 modified

  • trunk/components/blitz/src/ome/services/blitz/fire/SessionManagerI.java (modified) (7 diffs)

Legend:

Unmodified
Added
Removed
  • trunk/components/blitz/src/ome/services/blitz/fire/SessionManagerI.java

    r2382 r2596  
    1111import java.util.HashSet; 
    1212import java.util.List; 
     13import java.util.Map; 
    1314import java.util.Set; 
     15import java.util.concurrent.ConcurrentHashMap; 
    1416 
    1517import ome.conditions.InternalException; 
    … …  
    2527import ome.system.Principal; 
    2628import ome.system.Roles; 
     29import omero.ApiUsageException; 
    2730import omero.constants.EVENT; 
    2831import omero.constants.GROUP; 
    … …  
    7174    protected final Set<String> sessionsForReaping = new HashSet<String>(); 
    7275 
     76    /** 
     77     * An internal mapping to all {@link ServiceFactoryI} instances for a given 
     78     * session since there is no method on {@link Ice.ObjectAdapter} to retrieve 
     79     * all servants. 
     80     */ 
     81    protected final Map<String, Set<String>> sessionToClientIds = new ConcurrentHashMap<String, Set<String>>(); 
     82 
    7383    public SessionManagerI(SecuritySystem secSys, 
    7484            SessionManager sessionManager, Executor executor) { 
    … …  
    102112 
    103113        try { 
    104             Ice.ObjectPrx _prx; 
     114 
     115            // Create the session for this ServiceFactory 
    105116            Principal p = new Principal(userId, group, event); 
    106117            ome.model.meta.Session s = sessionManager.create(p); 
    107118            Principal sp = new Principal(s.getUuid(), group, event); 
    108119 
    109             Ice.Identity id = ServiceFactoryI.sessionId(s.getUuid()); 
    110             Ice.Object servant = current.adapter.find(id); 
    111             if (servant == null) { 
    112                 ServiceFactoryI session = new ServiceFactoryI(context, 
    113                         sessionManager, executor, sp, CPTORS); 
    114  
    115                 _prx = current.adapter.add(session, id); 
    116                 if (log.isDebugEnabled()) { 
    117                     log.debug(String.format("Created session %s for user %s", 
    118                             id.name, userId)); 
    119                 } 
     120            // Create the ServiceFactory 
     121            ServiceFactoryI session = new ServiceFactoryI(current, context, 
     122                    sessionManager, executor, sp, CPTORS); 
     123 
     124            Ice.Identity id = session.sessionId(s.getUuid()); 
     125            Ice.ObjectPrx _prx = current.adapter.add(session, id); 
     126            if (!sessionToClientIds.containsKey(s.getUuid())) { 
     127                sessionToClientIds.put(s.getUuid(), new HashSet<String>()); 
     128                log.debug(String.format("Created session %s for user %s", 
     129                        id.name, userId)); 
    120130            } else { 
     131                sessionToClientIds.get(s.getUuid()).add(session.clientId); 
    121132                if (log.isDebugEnabled()) { 
    122133                    log.debug(String.format("Rejoined session %s for user %s", 
    123134                            id.name, userId)); 
    124135                } 
    125                 _prx = current.adapter.createProxy(id); 
     136 
    126137            } 
    127138            return Glacier2.SessionPrxHelper.uncheckedCast(_prx); 
    128139 
    129         } catch (RuntimeException t) { 
     140        } catch (Exception t) { 
    130141            ConvertToBlitzExceptionMessage convert = new ConvertToBlitzExceptionMessage( 
    131142                    this, t); 
    … …  
    139150            if (convert.to instanceof CannotCreateSessionException) { 
    140151                throw (CannotCreateSessionException) convert.to; 
     152            } else if (convert.to instanceof ApiUsageException) { 
     153                ApiUsageException aue = (ApiUsageException) convert.to; 
     154                throw new CannotCreateSessionException(aue.message); 
    141155            } 
    142156 
    … …  
    158172 
    159173            // And unregister the service if possible 
    160             Ice.Identity id = ServiceFactoryI.sessionId(curr.id.category); 
     174            Ice.Identity id; 
     175            try { 
     176                id = ServiceFactoryI.sessionId(curr, curr.id.category); 
     177            } catch (ApiUsageException e) { 
     178                throw new RuntimeException( 
     179                        "Could not unregister servant: could not create session id"); 
     180            } 
    161181            Ice.Object obj = curr.adapter.find(id); 
    162182            if (obj instanceof ServiceFactoryI) { 
    163183                ServiceFactoryI sf = (ServiceFactoryI) obj; 
    164                 sf.unregisterServant(Ice.Util.stringToIdentity(key), curr); 
     184                sf.unregisterServant(Ice.Util.stringToIdentity(key), 
     185                        curr.adapter); 
    165186            } 
    166187        } else if (event instanceof DestroySessionMessage) { 
    … …  
    180201     * Unfortunately, that message does not have an {@link Ice.Current} instance 
    181202     * and so reaping must happen asynchronously. 
     203     *  
     204     * @param cantUseThisCurrent 
     205     *            a current from another method invocation which is not usable 
     206     *            for reaping the given sessions except to get the current 
     207     *            {@link Ice.ObjectAdapter} 
    182208     */ 
    183     private void reapSessions(Ice.Current current) { 
     209    private void reapSessions(Ice.Current cantUseThisCurrent) { 
     210        Ice.ObjectAdapter adapter = cantUseThisCurrent.adapter; 
    184211        synchronized (sessionsForReaping) { 
    185212            List<String> ids = new ArrayList<String>(sessionsForReaping); 
    186213            for (String id : ids) { 
    187                 try { 
    188                     Ice.Identity iid = ServiceFactoryI.sessionId(id); 
    189                     Ice.Object obj = current.adapter.find(iid); 
    190                     if (obj == null) { 
    191                         log.debug(id + " already removed."); 
    192                     } else { 
    193                         ServiceFactoryI sf = (ServiceFactoryI) obj; 
    194                         sf.close(current); 
     214                for (String clientId : sessionToClientIds.get(id)) { 
     215                    try { 
     216                        Ice.Identity iid = ServiceFactoryI.sessionId(clientId, 
     217                                id); 
     218                        Ice.Object obj = adapter.find(iid); 
     219                        if (obj == null) { 
     220                            log.debug(id + " already removed."); 
     221                        } else { 
     222                            ServiceFactoryI sf = (ServiceFactoryI) obj; 
     223                            sf.doDestroy(adapter); 
     224                        } 
     225                        sessionsForReaping.remove(id); 
     226                    } catch (Exception e) { 
     227                        log.error("Error reaping session " + id 
     228                                + " from client " + clientId, e); 
    195229                    } 
    196                     sessionsForReaping.remove(id); 
    197                 } catch (Exception e) { 
    198                     log.error("Error reaping session " + id, e); 
    199230                } 
    200231            } 

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/