Changeset 2598 for trunk/components/blitz/src/omero/client.java
- Timestamp:
- 07/05/08 22:16:07 (5 months ago)
- 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 10 10 import java.util.Collections; 11 11 import java.util.HashSet; 12 import java.util.List; 12 13 import java.util.Properties; 13 14 import java.util.Set; 14 15 import java.util.UUID; 16 17 import omero.api.IAdminPrx; 18 import omero.api.ISessionPrx; 15 19 import omero.api.ServiceFactoryPrx; 16 20 import omero.api.ServiceFactoryPrxHelper; … … 57 61 ServiceFactoryPrx sf; 58 62 59 boolean close_on_destroy = false;60 61 63 boolean closed = false; 62 64 … … 106 108 throw new ClientError("No communicator."); 107 109 } 110 // Register Object Factory 108 111 ObjectFactoryRegistrar.registerObjectFactory(ic, 109 112 ObjectFactoryRegistrar.INSTANCE); 113 // Define our unique identifer (used during close/detach) 114 ic.getImplicitContext().put(omero.constants.CLIENTUUID.value, 115 UUID.randomUUID().toString()); 110 116 CLIENTS.add(this); 111 117 } … … 114 120 // ========================================================================= 115 121 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 */ 120 125 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; 137 133 } 138 134 } … … 143 139 144 140 public ServiceFactoryPrx getServiceFactory() { 141 if (sf == null) { 142 throw new ClientError("Call createSession() to login."); 143 } 145 144 return sf; 146 145 } … … 161 160 public ServiceFactoryPrx createSession(String username, String password) 162 161 throws CannotCreateSessionException, PermissionDeniedException { 162 163 // Check the required properties 163 164 if (username == null) { 164 165 username = getProperty("omero.user"); … … 174 175 } 175 176 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 176 180 Glacier2.SessionPrx prx = getRouter().createSession(username, password); 177 181 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())); 180 186 sf = ServiceFactoryPrxHelper.checkedCast(prx); 181 187 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 184 192 return this.sf; 185 193 } … … 199 207 200 208 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! 210 221 } 211 222 … … 216 227 } catch (Ice.ConnectionLostException cle) { 217 228 // 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()); 235 259 } 236 260 … … 249 273 } 250 274 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 } 251 297 }
