1 28 29 30 package org.objectweb.ccm.runtime; 31 32 import org.objectweb.corba.runtime.*; 33 34 37 public class HomeLocalEventsImpl 38 { 39 static private String _class_name = "HomeLocalEventsImpl"; 41 private java.util.Hashtable _id2channel; 42 private java.util.Hashtable _id2inter; 43 private java.util.Hashtable _name2id; 44 private int _id_count; 45 private CallInterceptorFactory _factory; 46 47 public 49 HomeLocalEventsImpl() 50 { 51 _id2channel = null; 53 _id2inter = null; 54 _name2id = null; 55 _id_count = 0; 56 _factory = null; 57 } 58 59 public 61 HomeLocalEventsImpl(CallInterceptorFactory ifact) 62 { 63 _id2channel = new java.util.Hashtable (); 65 _id2inter = new java.util.Hashtable (); 66 _name2id = new java.util.Hashtable (); 67 _id_count = 0; 68 _factory = ifact; 69 } 70 71 75 final public int 76 get_channel(byte[] cid, String name) 77 throws org.omg.Components.ChannelUnavailable 78 { 79 String rname = new String (cid)+":"+name; 81 Integer chid = (Integer )_name2id.get(rname); 82 if (chid!=null) { 83 return chid.intValue(); 84 } 85 86 int nchid = _id_count++; 88 89 HomeFakeEventChannel channel = new HomeFakeEventChannel(nchid); 91 92 if (_factory!=null) { 94 org.omg.CORBA.Object inter = _factory.createUntypedStubInterceptor(name, channel); 97 _id2inter.put(new Integer (nchid), inter); 98 } 99 100 _name2id.put(rname, new Integer (nchid)); 102 _id2channel.put(new Integer (nchid), channel); 103 104 return nchid; 105 } 106 107 final public org.omg.Components.Cookie 108 subscribe(byte[] cid, org.omg.Components.EventConsumerBase consumer, int chid) 109 throws org.omg.Components.InvalidChannel 110 { 111 HomeFakeEventChannel channel = (HomeFakeEventChannel)_id2channel.get(new Integer (chid)); 113 114 if (channel==null) { 115 throw new org.omg.Components.InvalidChannel(); 116 } 117 118 return channel.subscribe(consumer); 119 } 120 121 final public org.omg.Components.EventConsumerBase 122 unsubscribe(byte[] cid, org.omg.Components.Cookie ck) 123 throws org.omg.Components.InvalidSubscription 124 { 125 if (!(ck instanceof CookieImpl)) { 127 throw new org.omg.Components.InvalidSubscription(); 129 } 130 131 CookieImpl lck = (CookieImpl)ck; 133 int chid = lck.getChannelId(); 134 135 HomeFakeEventChannel channel = (HomeFakeEventChannel)_id2channel.get(new Integer (chid)); 137 138 if (channel==null) { 139 throw new org.omg.Components.InvalidSubscription(); 140 } 141 142 return channel.unsubscribe(ck); 143 } 144 145 final public void 146 push(byte[] cid, org.omg.Components.EventBase evt, int chid) 147 throws org.omg.Components.InvalidChannel 148 { 149 org.omg.Components.EventConsumerBase cons = null; 150 if (_factory!=null) { 151 cons = (org.omg.Components.EventConsumerBase)_id2inter.get(new Integer (chid)); 153 } else { 154 cons = (org.omg.Components.EventConsumerBase)_id2channel.get(new Integer (chid)); 156 } 157 158 if (cons==null) { 159 throw new org.omg.Components.InvalidChannel(); 160 } 161 162 try { 163 cons.push_event(evt); 164 } catch (org.omg.Components.BadEventType ex) { 165 } 167 } 168 } 169 170 171 class HomeFakeEventChannel 173 extends org.omg.Components._EventConsumerBaseStub 174 { 175 private String _class_name = "ECMFakeEventChannel"; 177 private int _channel_id; 178 private java.util.Hashtable _ck2consumers; 179 180 public 182 HomeFakeEventChannel(int chid) 183 { 184 _channel_id = chid; 186 _ck2consumers = new java.util.Hashtable (); 187 } 188 189 193 final public org.omg.Components.Cookie 194 subscribe(org.omg.Components.EventConsumerBase consumer) 195 { 196 org.omg.Components.Cookie lck = new CookieImpl(_channel_id); 198 199 _ck2consumers.put(lck, consumer); 201 202 return lck; 203 } 204 205 final public org.omg.Components.EventConsumerBase 206 unsubscribe(org.omg.Components.Cookie ck) 207 throws org.omg.Components.InvalidSubscription 208 { 209 org.omg.Components.EventConsumerBase cons = (org.omg.Components.EventConsumerBase)_ck2consumers.remove(ck); 211 212 if (cons==null) { 214 throw new org.omg.Components.InvalidSubscription(); 215 } 216 217 return cons; 219 } 220 221 225 final public void 226 push_event(org.omg.Components.EventBase evt) 227 throws org.omg.Components.BadEventType 228 { 229 org.omg.Components.EventConsumerBase[] consumers = null; 230 consumers = (org.omg.Components.EventConsumerBase[])_ck2consumers.values().toArray(new org.omg.Components.EventConsumerBase[0]); 231 232 236 for (int i=0;i<consumers.length;i++) { 238 new HomePushEventWorker(consumers[i], evt).start(); 239 } 240 } 241 } 242 243 class HomePushEventWorker 245 extends java.lang.Thread 246 { 247 private String _class_name = "ECMPushEventWorker"; 249 private org.omg.Components.EventConsumerBase _consumer; 250 private org.omg.Components.EventBase _event; 251 252 public 254 HomePushEventWorker(org.omg.Components.EventConsumerBase cons, 255 org.omg.Components.EventBase evt) 256 { 257 _consumer = cons; 259 _event = evt; 260 } 261 262 266 final public void 267 run() 268 { 269 try { 270 _consumer.push_event(_event); 271 } catch (org.omg.Components.BadEventType ex) { 272 String opname = "run"; 274 TheLogger.debug(_class_name, opname, "IGNORE (bad event type)"); 275 } 276 } 277 } | Popular Tags |