1 31 package org.objectweb.proactive.ic2d.data; 32 33 import org.objectweb.proactive.core.UniqueID; 34 import org.objectweb.proactive.ic2d.event.MessageMonitoringListener; 35 36 39 public abstract class AbstractDataObject implements MessageMonitoringController { 40 41 protected DataObjectController controller; 42 43 protected AbstractDataObject parent; 44 45 private java.util.HashMap childs; 46 47 protected String abstractDataObjectName; 48 protected boolean isDestroyed; 49 50 protected boolean monitoringRequestReceiver; 51 protected boolean monitoringRequestSender; 52 protected boolean monitoringReplyReceiver; 53 protected boolean monitoringReplySender; 54 protected boolean viewingInEventList; 55 protected MessageMonitoringListener messageMonitoringListener; 56 57 61 protected AbstractDataObject(AbstractDataObject parent, String abstractDataObjectName) { 62 this(); 63 this.parent = parent; 64 this.abstractDataObjectName = abstractDataObjectName; 65 if (abstractDataObjectName == null) 66 this.abstractDataObjectName = this.getClass().getName(); 67 else this.abstractDataObjectName = abstractDataObjectName; 68 this.controller = parent.getController(); 69 initializeMonitoring(parent); 70 childs = new java.util.HashMap (); 71 } 72 73 74 protected AbstractDataObject(AbstractDataObject parent) { 75 this(parent, null); 76 } 77 78 79 protected AbstractDataObject() { 80 initializeMonitoring(null); 81 childs = new java.util.HashMap (); 82 } 83 84 85 89 public String toString() { 90 return "DataObject "+abstractDataObjectName+"\n"+childs.toString(); 91 } 92 93 94 public DataObjectController getController() { 95 return controller; 96 } 97 98 99 public AbstractDataObject getParent() { 100 return parent; 101 } 102 103 104 107 public AbstractDataObject getTopLevelParent() { 108 if (parent == null) { 109 return this; 110 } else { 111 return parent.getTopLevelParent(); 112 } 113 } 114 115 116 public java.util.Iterator childsIterator() { 117 return childs.values().iterator(); 118 } 119 120 121 public int getChildObjectsCount() { 122 return childs.size(); 123 } 124 125 126 public synchronized ActiveObject findActiveObjectById(UniqueID id) { 127 java.util.Iterator iterator = childsIterator(); 128 while (iterator.hasNext()) { 129 AbstractDataObject o = (AbstractDataObject) iterator.next(); 130 ActiveObject activeObject = o.findActiveObjectById(id); 131 if (activeObject != null) return activeObject; 132 } 133 return null; 134 } 135 136 137 public abstract void destroyObject(); 138 139 140 141 145 public void viewInEventList(boolean shouldView) { 146 if (isDestroyed) return; 147 if (viewingInEventList != shouldView) { 148 viewingInEventList = shouldView; 149 if (messageMonitoringListener != null) messageMonitoringListener.viewingInEventListChanged(shouldView); 150 } 151 viewInEventListCollection(shouldView, childsIterator()); 152 } 153 154 155 public void monitorRequestReceiver(boolean shouldMonitor) { 156 if (isDestroyed) return; 157 if (monitoringRequestReceiver != shouldMonitor) { 158 monitoringRequestReceiver = shouldMonitor; 159 if (messageMonitoringListener != null) messageMonitoringListener.monitoringRequestReceiverChanged(shouldMonitor); 160 } 161 monitorRequestReceiverCollection(shouldMonitor, childsIterator()); 162 } 163 164 165 public void monitorRequestSender(boolean shouldMonitor) { 166 if (isDestroyed) return; 167 if (monitoringRequestSender != shouldMonitor) { 168 monitoringRequestSender = shouldMonitor; 169 if (messageMonitoringListener != null) messageMonitoringListener.monitoringRequestSenderChanged(shouldMonitor); 170 } 171 monitorRequestSenderCollection(shouldMonitor, childsIterator()); 172 } 173 174 175 public void monitorReplyReceiver(boolean shouldMonitor) { 176 if (isDestroyed) return; 177 if (monitoringReplyReceiver != shouldMonitor) { 178 monitoringReplyReceiver = shouldMonitor; 179 if (messageMonitoringListener != null) messageMonitoringListener.monitoringReplyReceiverChanged(shouldMonitor); 180 } 181 monitorReplyReceiverCollection(shouldMonitor, childsIterator()); 182 } 183 184 185 public void monitorReplySender(boolean shouldMonitor) { 186 if (isDestroyed) return; 187 if (monitoringReplySender != shouldMonitor) { 188 monitoringReplySender = shouldMonitor; 189 if (messageMonitoringListener != null) messageMonitoringListener.monitoringReplySenderChanged(shouldMonitor); 190 } 191 monitorReplySenderCollection(shouldMonitor, childsIterator()); 192 } 193 194 195 public void monitorAll(boolean shouldMonitor) { 196 monitorRequestReceiver(shouldMonitor); 197 monitorRequestSender(shouldMonitor); 198 monitorReplyReceiver(shouldMonitor); 199 monitorReplySender(shouldMonitor); 200 } 201 202 public boolean isMonitoring() { 203 return monitoringRequestReceiver || monitoringRequestSender || monitoringReplyReceiver || monitoringReplySender; 204 } 205 206 207 public boolean isMonitoringRequestReceiver() { 208 return monitoringRequestReceiver; 209 } 210 211 212 public boolean isMonitoringRequestSender() { 213 return monitoringRequestSender; 214 } 215 216 217 public boolean isMonitoringReplyReceiver() { 218 return monitoringReplyReceiver; 219 } 220 221 222 public boolean isMonitoringReplySender() { 223 return monitoringReplySender; 224 } 225 226 227 public boolean isViewedInEventList() { 228 return viewingInEventList; 229 } 230 231 232 236 239 protected synchronized boolean destroy() { 240 if (isDestroyed) return false; 241 isDestroyed = true; 243 destroyCollection(childsIterator()); 244 childs.clear(); 245 parent = null; 246 controller = null; 247 return true; 248 } 249 250 251 254 protected synchronized void clearChilds() { 255 childs.clear(); 256 } 257 258 259 262 public synchronized void putChild(Object key, AbstractDataObject child) { 263 if (isDestroyed) return; 264 childs.put(key, child); 266 } 267 268 269 272 protected synchronized AbstractDataObject removeChild(Object key) { 273 AbstractDataObject o; 274 if (isDestroyed) { 275 o = (AbstractDataObject) childs.get(key); 279 } else { 280 o = (AbstractDataObject) childs.remove(key); 282 } 283 if (o == null) return null; 284 o.destroy(); 286 return o; 287 } 288 289 290 293 protected synchronized AbstractDataObject getChild(Object key) { 294 return (AbstractDataObject) childs.get(key); 295 } 296 297 298 301 protected synchronized void destroyCollection(java.util.Iterator iterator) { 302 while (iterator.hasNext()) { 304 AbstractDataObject o = (AbstractDataObject) iterator.next(); 305 o.destroyObject(); 306 } 307 } 308 309 310 315 protected synchronized void viewInEventListCollection(boolean shouldView, java.util.Iterator iterator) { 316 while (iterator.hasNext() && ! isDestroyed) { 317 MessageMonitoringController o = (MessageMonitoringController) iterator.next(); 318 o.viewInEventList(shouldView); 319 } 320 } 321 322 323 328 protected synchronized void monitorRequestReceiverCollection(boolean shouldMonitor, java.util.Iterator iterator) { 329 while (iterator.hasNext() && ! isDestroyed) { 330 MessageMonitoringController o = (MessageMonitoringController) iterator.next(); 331 o.monitorRequestReceiver(shouldMonitor); 332 } 333 } 334 335 336 341 protected synchronized void monitorRequestSenderCollection(boolean shouldMonitor, java.util.Iterator iterator) { 342 while (iterator.hasNext() && ! isDestroyed) { 343 MessageMonitoringController o = (MessageMonitoringController) iterator.next(); 344 o.monitorRequestSender(shouldMonitor); 345 } 346 } 347 348 349 354 protected synchronized void monitorReplyReceiverCollection(boolean shouldMonitor, java.util.Iterator iterator) { 355 while (iterator.hasNext() && ! isDestroyed) { 356 MessageMonitoringController o = (MessageMonitoringController) iterator.next(); 357 o.monitorReplyReceiver(shouldMonitor); 358 } 359 } 360 361 362 367 protected synchronized void monitorReplySenderCollection(boolean shouldMonitor, java.util.Iterator iterator) { 368 while (iterator.hasNext() && ! isDestroyed) { 369 MessageMonitoringController o = (MessageMonitoringController) iterator.next(); 370 o.monitorReplySender(shouldMonitor); 371 } 372 } 373 374 375 380 protected synchronized void monitorAllCollection(boolean shouldMonitor, java.util.Iterator iterator) { 381 while (iterator.hasNext() && ! isDestroyed) { 382 MessageMonitoringController o = (MessageMonitoringController) iterator.next(); 383 o.monitorAll(shouldMonitor); 384 } 385 } 386 387 388 390 protected void monitoringMessageEventChanged(ActiveObject object, boolean value) { 391 if (parent != null && ! isDestroyed) parent.monitoringMessageEventChanged(object, value); 392 } 393 394 395 396 400 401 private void initializeMonitoring(AbstractDataObject parent) { 402 if (parent != null) { 403 monitoringRequestReceiver = parent.monitoringRequestReceiver; 404 monitoringRequestSender = parent.monitoringRequestSender; 405 monitoringReplyReceiver = parent.monitoringReplyReceiver; 406 monitoringReplySender = parent.monitoringReplySender; 407 viewingInEventList = parent.viewingInEventList; 408 } else { 409 monitoringRequestReceiver = true; 411 monitoringRequestSender = true; 412 monitoringReplyReceiver = true; 413 monitoringReplySender = true; 414 viewingInEventList = false; 416 } 417 } 418 419 } 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | Popular Tags |