1 28 29 30 package org.objectweb.ccm.runtime; 31 32 import org.objectweb.corba.runtime.*; 33 34 39 class ComponentServantActivatorImpl 40 extends org.omg.CORBA.LocalObject 41 implements org.omg.PortableServer.ServantActivator 42 { 43 static final private String _class_name = "ComponentServantActivatorImpl"; 45 private ORBService _orb_service; 46 private ServicesSet _services_set; 47 private java.util.HashMap _id2home; private java.util.HashMap _component_ids; private java.util.HashMap _id2pcomp; private java.util.HashMap _id2acomp; 52 private MonolithicIdCodec _midcodec; 53 private SegmentedIdCodec _sidcodec; 54 55 public 56 ComponentServantActivatorImpl() 57 { 58 _orb_service = null; 60 _services_set = null; 61 _id2home = new java.util.HashMap (); 62 _component_ids = new java.util.HashMap (); 63 _id2pcomp = new java.util.HashMap (); 64 _id2acomp = new java.util.HashMap (); 65 66 _midcodec = null; 67 _sidcodec = null; 68 } 69 70 74 private org.omg.Components.ExecutorSegmentBase 75 lookupPassivated(byte[] id) 76 { 77 final String opname = "lookupPassivated"; 78 79 String pcomp = (String )_id2pcomp.remove(new String (id)); 81 if (pcomp!=null) { 82 try { 84 java.io.ByteArrayInputStream bin= new java.io.ByteArrayInputStream (pcomp.getBytes()); 85 java.io.ObjectInputStream oin = new java.io.ObjectInputStream (bin); 86 Object obj = oin.readObject(); 87 88 if (obj instanceof org.omg.Components.ExecutorSegmentBase) { 89 return (org.omg.Components.ExecutorSegmentBase)obj; 90 } else { 91 TheLogger.error(_class_name, opname, "FAILED (not a executor segment: "+obj.getClass()+""); 93 return null; 94 } 95 } catch (Exception ex) { 96 TheLogger.error(_class_name, opname, "FAILED", ex); 98 return null; 99 } 100 } 101 102 return null; 103 } 104 105 109 final protected void 110 setConfiguration(ORBService orbs, ServicesSet sset) 111 { 112 _orb_service = orbs; 113 _services_set = sset; 114 115 _midcodec = new MonolithicIdCodec(_orb_service); 117 _sidcodec = new SegmentedIdCodec(_orb_service); 118 } 119 120 synchronized final protected void 121 registerHome(byte[] id, String uuid, 122 org.omg.Components.HomeExecutor hexe, 123 CallInterceptorFactory ifact, 124 org.omg.Components.CCM2Context ctx) 125 { 126 CSAStorage storage = null; 127 if (ifact!=null) { 128 storage = new CSAStorage(hexe, ctx, ifact); 129 } else { 130 storage = new CSAStorage(hexe, ctx); 131 } 132 133 _id2home.put(new String (id), storage); 135 } 136 137 synchronized final protected void 138 registerComponent(byte[] id) 139 { 140 _component_ids.put(new String (id), null); 142 } 143 144 synchronized final protected void 145 unregisterComponent(byte[] id) 146 { 147 _component_ids.remove(new String (id)); 149 } 150 151 155 159 final public org.omg.PortableServer.Servant 162 incarnate(byte[] id, org.omg.PortableServer.POA poa) 163 throws org.omg.PortableServer.ForwardRequest 164 { 165 final String opname = "incarnate"; 166 try { 167 return unsafe_incarnate(id, poa); 168 } catch (org.omg.PortableServer.ForwardRequest ex) { 169 throw ex; 171 } catch (Throwable ex) { 172 TheLogger.debug(_class_name, opname, "FAILED", ex); 173 return null; 174 } 175 } 176 177 final public org.omg.PortableServer.Servant 178 unsafe_incarnate(byte[] id, org.omg.PortableServer.POA poa) 179 throws org.omg.PortableServer.ForwardRequest 180 { 181 final String opname = "unsafe_incarnate"; 182 183 if (!_component_ids.containsKey(new String (id))) { 185 final String msg = "FAILED (unknown id)"; 188 TheLogger.debug(_class_name, opname, msg); 189 return null; 190 } 191 192 org.omg.Components.ExecutorSegmentBase cexe = null; 194 CSAStorage storage = null; 195 196 MonolithicId mid = _midcodec.decode(id); 199 if (mid!=null) { 200 storage = (CSAStorage)_id2home.get(new String (mid.home_id)); 202 org.omg.Components.HomeExecutor hexe = storage.home_executor; 203 204 cexe = lookupPassivated(id); 206 207 if (cexe==null) { 208 cexe = hexe.create_component_segment(org.omg.Components.COMPONENT_ID.value); 210 } 211 } 212 213 SegmentedId sid = null; 215 if (mid==null) { 216 sid = _sidcodec.decode(id); 218 219 storage = (CSAStorage)_id2home.get(new String (sid.home_id)); 221 org.omg.Components.HomeExecutor hexe = storage.home_executor; 222 223 cexe = lookupPassivated(id); 225 226 if (cexe==null) { 227 cexe = hexe.create_component_segment(sid.segment_id); 229 } 230 } 231 232 if (cexe instanceof org.omg.Components.SessionComponent) { 234 org.omg.Components.SessionComponent scomp = (org.omg.Components.SessionComponent)cexe; 235 org.omg.Components.SessionContext sessionctx = null; 236 237 if (mid!=null) { 239 HomeSession2ContextImpl hctx = (HomeSession2ContextImpl)storage.ccm2context; 241 Session2ContextImpl segctx = new Session2ContextImpl(hctx, mid.component_id); 242 sessionctx = segctx; 243 } else { 244 org.omg.Components.SegmentDescr[] descrs = sid.segment_descrs; 246 byte[] mainsegid = null; 247 for (int i=0;i<descrs.length;i++) { 248 if (descrs[i].segment_id==org.omg.Components.COMPONENT_ID.value) { 249 mainsegid = descrs[i].object_id; 250 break; 251 } 252 } 253 254 HomeSegmentedSession2ContextImpl hctx = (HomeSegmentedSession2ContextImpl)storage.ccm2context; 256 SegmentedSession2ContextImpl segctx = new SegmentedSession2ContextImpl(hctx, mainsegid); 257 sessionctx = segctx; 258 } 259 260 try { 261 scomp.set_session_context(sessionctx); 262 scomp.ccm_activate(); 263 } catch (org.omg.Components.CCMException ex) { 264 TheLogger.debug(_class_name, opname, "FAILED", ex); 266 } 267 } else { 268 final String msg = "IGNORE (SessionComponent not supported)"; 270 TheLogger.debug(_class_name, opname, msg); 271 } 272 273 _id2acomp.put(new String (id), cexe); 275 276 if (storage.interceptor_factory!=null) { 278 org.omg.PortableServer.Servant poaserv = null; 279 CallInterceptorFactory ifact = storage.interceptor_factory; 281 if (sid!=null) { 282 poaserv = ifact.createSkeletonInterceptor(sid.segment_id, cexe); 283 } else { 284 poaserv = ifact.createSkeletonInterceptor(org.omg.Components.COMPONENT_ID.value, cexe); 285 } 286 287 return poaserv; 288 } else { 289 TheLogger.debug(_class_name, opname, "IGNORE (no interceptor factory)"); 291 } 292 293 if (cexe instanceof org.omg.Components.Servant) { 294 org.omg.Components.Servant servant = (org.omg.Components.Servant)cexe; 295 return servant.as_native_servant(); 296 } else { 297 TheLogger.error(_class_name, opname, "FAILED (not a CCM servant)"); 298 return null; 299 } 300 } 301 302 final public void 305 etherealize(byte[] id, 306 org.omg.PortableServer.POA poa, 307 org.omg.PortableServer.Servant servant, 308 boolean cleanup_in_progress, 309 boolean remaining_activations) 310 { 311 final String opname = "etherealize"; 313 final boolean removed = _component_ids.containsKey(new String (id))? false : true; 314 315 317 final Object obj = _id2acomp.remove(new String (id)); 319 320 if (obj instanceof org.omg.Components.SessionComponent) { 321 org.omg.Components.SessionComponent scomp = (org.omg.Components.SessionComponent)obj; 322 323 if (removed) { 324 try { 326 scomp.ccm_passivate(); 328 scomp.ccm_remove(); 329 } catch (org.omg.Components.CCMException ex) { 330 TheLogger.debug(_class_name, opname, "FAILED", ex); 332 } 333 } else { 334 try { 336 scomp.ccm_passivate(); 337 } catch (org.omg.Components.CCMException ex) { 338 TheLogger.debug(_class_name, opname, "FAILED", ex); 340 } 341 342 try { 343 final java.io.ByteArrayOutputStream bout= new java.io.ByteArrayOutputStream (); 344 final java.io.ObjectOutputStream oout = new java.io.ObjectOutputStream (bout); 345 oout.writeObject(scomp); 346 oout.flush(); 347 bout.flush(); 348 final byte[] pcomp = bout.toByteArray(); 350 oout.close(); 351 352 _id2pcomp.put(new String (id), new String (pcomp)); 354 } catch (Exception ex) { 355 TheLogger.error(_class_name, opname, "FAILED", ex); 357 } 358 } 359 } else { 360 final String msg = "IGNORE (SessionComponent not supported)"; 362 TheLogger.debug(_class_name, opname, msg); 363 } 364 } 365 } 366 367 class CSAStorage 371 { 372 public org.omg.Components.HomeExecutor home_executor; 374 public org.omg.Components.CCM2Context ccm2context; 375 public CallInterceptorFactory interceptor_factory; 376 377 public 379 CSAStorage(org.omg.Components.HomeExecutor hexe, 380 org.omg.Components.CCM2Context ctx) 381 { 382 home_executor = hexe; 384 ccm2context = ctx; 385 interceptor_factory = null; 386 } 387 388 public 390 CSAStorage(org.omg.Components.HomeExecutor hexe, 391 org.omg.Components.CCM2Context ctx, 392 CallInterceptorFactory ifact) 393 { 394 home_executor = hexe; 396 ccm2context = ctx; 397 interceptor_factory = ifact; 398 } 399 } 400 401 | Popular Tags |