1 28 29 30 package org.objectweb.ccm.runtime; 31 32 import org.objectweb.corba.runtime.*; 33 34 37 public class EventConsumerBaseStubI 38 extends org.omg.Components._EventConsumerBaseStub 39 { 40 static private String _class_name = "EventConsumerBaseStubI"; 42 private ORBService _orb_service; 43 private ServicesSet _services_set; 44 private String _uuid; 45 private ClientCallContextImpl _call_ctx; 46 private java.util.Hashtable _informations; 47 private org.omg.Components.EventConsumerBase _delegate; 48 private String _scoped_name; 49 50 public 52 EventConsumerBaseStubI(ORBService orbs, ServicesSet sset, 53 String uuid, org.omg.CORBA.Object del, 54 String sname) 55 { 56 _orb_service = orbs; 58 _services_set = sset; 59 _uuid = uuid; 60 _delegate = org.omg.Components.EventConsumerBaseHelper.narrow(del); 61 _informations = new java.util.Hashtable (); 62 _scoped_name = sname; 63 64 _call_ctx = new ClientCallContextImpl(_orb_service, _services_set, del); 66 } 67 68 72 private CallInformation 73 _getCallInformation(String name) 74 { 75 CallInformation info = (CallInformation)_informations.get(name); 77 78 if (info==null) { 79 info = new CallInformation(); 81 _informations.put(name, info); 83 } 84 85 if (info.policies==null) { 88 info.policies = _services_set.get_policies(_uuid, name); 89 } 90 91 93 return info; 94 } 95 96 private short 97 _preinvoke(org.coach.ECA.ClientCallController[] ctrls) 98 { 99 final String opname = "_preinvoke"; 100 org.omg.CORBA.Any curr_exc = null; 101 org.omg.CORBA.Any curr_res = null; 102 103 short fstate = FlowState.SEND_REQUEST; 105 int ctrl_idx = 0; 106 boolean finished = false; 107 org.coach.ECA.ClientCallController ctrl = null; 108 109 while ((!finished) && (ctrl_idx<ctrls.length)){ 110 curr_exc = _call_ctx.system_exception(); 112 if (curr_exc!=null) { 113 fstate = FlowState.RECEIVE_SYSTEM_EXCEPTION; 115 } 116 117 curr_exc = _call_ctx.user_exception(); 119 if (curr_exc!=null) { 120 fstate = FlowState.RECEIVE_USER_EXCEPTION; 122 } 123 124 curr_res = _call_ctx.result(); 126 if (curr_res!=null) { 127 final String msg = "FAILED (unexpected state in preinvoke: RECEIVE_REPLY)"; 129 TheLogger.error(_class_name, opname, msg); 130 } 131 132 if (fstate==FlowState.SEND_REQUEST) { 134 ctrl = ctrls[ctrl_idx++]; 136 ctrl.send_request(_call_ctx); 137 138 _call_ctx.pushController(ctrl); 140 } 141 else if (_call_ctx.isEmpty()) { 143 finished = true; 144 } 145 else if (fstate==FlowState.RECEIVE_SYSTEM_EXCEPTION) { 147 ctrl = _call_ctx.popController(); 149 ctrl.receive_system_exception(_call_ctx); 150 } 151 else if (fstate==FlowState.RECEIVE_SYSTEM_EXCEPTION) { 153 ctrl = _call_ctx.popController(); 155 ctrl.receive_user_exception(_call_ctx); 156 } 157 else { 159 final String msg = "FAILED (unexpected state in preinvoke: RECEIVE_REPLY)"; 161 TheLogger.error(_class_name, opname, msg); 162 } 163 } 164 165 return fstate; 167 } 168 169 172 private short 173 _postinvoke(short fstate) 174 { 175 org.omg.CORBA.Any curr_exc = null; 176 org.omg.CORBA.Any curr_res = null; 177 boolean finished = false; 178 org.coach.ECA.ClientCallController ctrl = null; 179 180 183 curr_exc = _call_ctx.system_exception(); 185 curr_exc = _call_ctx.user_exception(); 186 if (curr_exc!=null) { 187 fstate = FlowState.RECEIVE_SYSTEM_EXCEPTION; 189 } 190 else if (curr_exc!=null) { 192 fstate = FlowState.RECEIVE_USER_EXCEPTION; 194 } 195 else { 196 fstate = FlowState.RECEIVE_REPLY; 198 } 199 200 while (!finished) { 201 if (_call_ctx.isEmpty()) { 203 finished = true; 204 } 205 else if (fstate==FlowState.RECEIVE_SYSTEM_EXCEPTION) { 207 ctrl = _call_ctx.popController(); 209 ctrl.receive_system_exception(_call_ctx); 210 } 211 else if (fstate==FlowState.RECEIVE_SYSTEM_EXCEPTION) { 213 ctrl = _call_ctx.popController(); 215 ctrl.receive_user_exception(_call_ctx); 216 } 217 else { 219 ctrl = _call_ctx.popController(); 221 ctrl.receive_reply(_call_ctx); 222 } 223 224 curr_exc = _call_ctx.system_exception(); 226 if (curr_exc!=null) { 227 fstate = FlowState.RECEIVE_SYSTEM_EXCEPTION; 229 } 230 231 curr_exc = _call_ctx.user_exception(); 233 if (curr_exc!=null) { 234 fstate = FlowState.RECEIVE_USER_EXCEPTION; 236 } 237 238 curr_res = _call_ctx.result(); 240 if (curr_res!=null) { 241 fstate = FlowState.RECEIVE_REPLY; 243 } 244 } 245 246 return fstate; 248 } 249 250 254 final public void 255 push_event(org.omg.Components.EventBase evt) 256 throws org.omg.Components.BadEventType 257 { 258 final String opname = "push_event"; 259 org.omg.CORBA.Any anyexc = null; 260 261 CallInformation callinfo = _getCallInformation(_scoped_name); 263 264 _call_ctx.addEntry(callinfo, opname); 266 267 short fstate = _preinvoke(callinfo.getClientCallControllers()); 269 270 if (fstate==FlowState.RECEIVE_SYSTEM_EXCEPTION) { 272 anyexc = _call_ctx.system_exception(); 273 _call_ctx.removeEntry(); 274 throw org.omg.CORBA.SystemExceptionHelper.extract(anyexc); 275 } 276 else if (fstate==FlowState.RECEIVE_USER_EXCEPTION) { 277 anyexc = _call_ctx.user_exception(); 278 _call_ctx.removeEntry(); 279 if (anyexc.type()==org.omg.Components.BadEventTypeHelper.type()) { 281 throw org.omg.Components.BadEventTypeHelper.extract(anyexc); 282 } 283 else { 284 TheLogger.error(_class_name, opname, "unknown user exception was raised"); 285 } 286 } 287 else if (fstate==FlowState.RECEIVE_REPLY) { 288 TheLogger.error(_class_name, opname, "unexpected state after preinvoke: RECEIVE_REPLY"); 290 } 291 292 try { 293 _delegate.push_event(evt); 295 } 296 catch (org.omg.CORBA.SystemException ex) { 297 anyexc = _call_ctx.create_any(); 298 org.omg.CORBA.SystemExceptionHelper.insert(anyexc, ex); 299 _call_ctx.send_system_exception(anyexc); 300 } 301 catch (org.omg.Components.BadEventType ex) { 302 anyexc = _orb_service.create_any(); 304 org.omg.Components.BadEventTypeHelper.insert(anyexc, ex); 305 _call_ctx.send_user_exception(anyexc); 306 } 307 fstate = _postinvoke(fstate); 309 310 if (fstate==FlowState.RECEIVE_SYSTEM_EXCEPTION) { 312 anyexc = _call_ctx.system_exception(); 313 _call_ctx.removeEntry(); 314 throw org.omg.CORBA.SystemExceptionHelper.extract(anyexc); 315 } 316 else if (fstate==FlowState.RECEIVE_USER_EXCEPTION) { 317 anyexc = _call_ctx.user_exception(); 318 _call_ctx.removeEntry(); 319 if (anyexc.type()==org.omg.Components.BadEventTypeHelper.type()) { 321 throw org.omg.Components.BadEventTypeHelper.extract(anyexc); 322 } 323 else { 324 TheLogger.error(_class_name, opname, "unknown user exception was raised"); 325 } 326 } 327 else if (fstate==FlowState.RECEIVE_REPLY) { 328 _call_ctx.removeEntry(); 329 } 330 } 331 } 332 | Popular Tags |