• 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 2598 for trunk/components/blitz/src/omero/client.java

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

ticket:1018 - Propagating changes to OmeroJava and OmeroCpp

Also add environment methods which have been in OmeroPy for
some time.

Files:
1 modified

  • trunk/components/blitz/src/omero/client.java (modified) (10 diffs)

Legend:

Unmodified
Added
Removed
  • trunk/components/blitz/src/omero/client.java

    r2256 r2598  
    1010import java.util.Collections; 
    1111import java.util.HashSet; 
     12import java.util.List; 
    1213import java.util.Properties; 
    1314import java.util.Set; 
    14  
     15import java.util.UUID; 
     16 
     17import omero.api.IAdminPrx; 
     18import omero.api.ISessionPrx; 
    1519import omero.api.ServiceFactoryPrx; 
    1620import omero.api.ServiceFactoryPrxHelper; 
    … …  
    5761    ServiceFactoryPrx sf; 
    5862 
    59     boolean close_on_destroy = false; 
    60  
    6163    boolean closed = false; 
    6264 
    … …  
    106108            throw new ClientError("No communicator."); 
    107109        } 
     110        // Register Object Factory 
    108111        ObjectFactoryRegistrar.registerObjectFactory(ic, 
    109112                ObjectFactoryRegistrar.INSTANCE); 
     113        // Define our unique identifer (used during close/detach) 
     114        ic.getImplicitContext().put(omero.constants.CLIENTUUID.value, 
     115                UUID.randomUUID().toString()); 
    110116        CLIENTS.add(this); 
    111117    } 
    … …  
    114120    // ========================================================================= 
    115121 
    116     public void closeOnDestroy() { 
    117         close_on_destroy = true; 
    118     } 
    119  
     122    /** 
     123     * Equivalent to OmeroPy's __del__ or OmeroCpp's omero::client::~client() 
     124     */ 
    120125    public void close() { 
    121         if (close_on_destroy) { 
    122             try { 
    123                 closeSession(); 
    124             } catch (Exception e) { 
    125                 // ok. 
    126             } 
    127         } 
    128         if (ic != null) { 
    129             try { 
    130                 ic.getLogger() 
    131                         .trace("omero.client.destroy", "Destroying " + ic); 
    132                 ic.destroy(); 
    133                 ic = null; 
    134             } catch (Exception e) { 
    135                 // ok 
    136             } 
     126        try { 
     127            closeSession(); 
     128        } catch (Exception e) { 
     129            System.out.println("Ignoring error in client.close()"); 
     130            e.printStackTrace(); 
     131        } finally { 
     132            closed = true; 
    137133        } 
    138134    } 
    … …  
    143139 
    144140    public ServiceFactoryPrx getServiceFactory() { 
     141        if (sf == null) { 
     142            throw new ClientError("Call createSession() to login."); 
     143        } 
    145144        return sf; 
    146145    } 
    … …  
    161160    public ServiceFactoryPrx createSession(String username, String password) 
    162161            throws CannotCreateSessionException, PermissionDeniedException { 
     162 
     163        // Check the required properties 
    163164        if (username == null) { 
    164165            username = getProperty("omero.user"); 
    … …  
    174175        } 
    175176 
     177        // Acquire router and get the proxy 
     178        // For whatever reason, we have to se the context 
     179        // on the router context here as well 
    176180        Glacier2.SessionPrx prx = getRouter().createSession(username, password); 
    177181        if (null == prx) { 
    178             throw new ClientError("No session obtained"); 
    179         } 
     182            throw new ClientError("Obtained null object proxy"); 
     183        } 
     184        prx = Glacier2.SessionPrxHelper.uncheckedCast(prx.ice_context(ic 
     185                .getImplicitContext().getContext())); 
    180186        sf = ServiceFactoryPrxHelper.checkedCast(prx); 
    181187        if (sf == null) { 
    182             throw new ClientError("No session obtained"); 
    183         } 
     188            throw new ClientError( 
     189                    "Obtained object proxy is not a ServiceFactory"); 
     190        } 
     191 
    184192        return this.sf; 
    185193    } 
    … …  
    199207 
    200208    public void closeSession() { 
    201         if (this.sf == null) { 
    202             return; // EARLY EXIT 
    203         } 
    204  
    205         try { 
    206             sf.close(); 
    207             sf = null; 
    208         } catch (Exception e) { 
    209             // what can we do 
     209 
     210        ServiceFactoryPrx old = this.sf; 
     211        if (this.sf != null) { 
     212            this.sf = null; 
     213        } 
     214 
     215        if (ic == null && sf != null) { 
     216            ic = sf.ice_getCommunicator(); 
     217        } 
     218 
     219        if (ic == null) { 
     220            return; // EARLY EXIT! 
    210221        } 
    211222 
    … …  
    216227        } catch (Ice.ConnectionLostException cle) { 
    217228            // ok. Exception will always be thrown 
    218         } 
    219     } 
    220  
    221     public Object getInput(String key) { 
    222         throw new UnsupportedOperationException(); 
    223     } 
    224  
    225     public Object getOutput(String key) { 
    226         throw new UnsupportedOperationException(); 
    227     } 
    228  
    229     public void setInput(String key, Object value) { 
    230         throw new UnsupportedOperationException(); 
    231     } 
    232  
    233     public void setOutput(String key, Object value) { 
    234         throw new UnsupportedOperationException(); 
     229        } finally { 
     230            ic = null; 
     231        } 
     232    } 
     233 
     234    // Environment methods 
     235    // ========================================================================= 
     236 
     237    public RType getInput(String key) throws ServerError { 
     238        return env().getInput(sess(), key); 
     239    } 
     240 
     241    public RType getOutput(String key) throws ServerError { 
     242        return env().getOutput(sess(), key); 
     243    } 
     244 
     245    public void setInput(String key, RType value) throws ServerError { 
     246        env().setInput(sess(), key, value); 
     247    } 
     248 
     249    public void setOutput(String key, RType value) throws ServerError { 
     250        env().setOutput(sess(), key, value); 
     251    } 
     252 
     253    public List<String> getInputKeys() throws ServerError { 
     254        return env().getInputKeys(sess()); 
     255    } 
     256 
     257    public List<String> getOutputKeys() throws ServerError { 
     258        return env().getOutputKeys(sess()); 
    235259    } 
    236260 
    … …  
    249273    } 
    250274 
     275    /** 
     276     * Helper method to access session environment 
     277     */ 
     278    protected ISessionPrx env() throws ServerError { 
     279        if (sf == null) { 
     280            throw new ClientError("No session active"); 
     281        } 
     282        ISessionPrx s = sf.getSessionService(); 
     283        return s; 
     284    } 
     285 
     286    /** 
     287     * Helper method to access session id 
     288     */ 
     289    protected String sess() throws ServerError { 
     290        if (sf == null) { 
     291            throw new ClientError("No session active"); 
     292        } 
     293        IAdminPrx a = sf.getAdminService(); 
     294        String u = a.getEventContext().sessionUuid; 
     295        return u; 
     296    } 
    251297} 

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/