1 31 package org.objectweb.proactive.ic2d.data; 32 33 import org.objectweb.proactive.ic2d.event.CommunicationEventListener; 34 import org.objectweb.proactive.ic2d.event.IC2DObjectListener; 35 import org.objectweb.proactive.ic2d.spy.SpyEvent; 36 import org.objectweb.proactive.ic2d.util.IC2DMessageLogger; 37 38 41 public class IC2DObject extends AbstractDataObject { 42 43 protected IC2DObjectListener listener; 44 protected WorldObject worldObject; 45 protected IC2DMessageLogger logger; 46 protected CommunicationEventListener communicationEventListener; 47 48 52 public IC2DObject() { 53 super(); 54 controller = new MyController(); 55 communicationEventListener = new MyCommunicationEventListener(); 56 worldObject = new WorldObject(this); 57 putChild(worldObject, worldObject); 58 } 59 60 61 65 66 70 public void registerListener(IC2DObjectListener listener) { 71 this.listener = listener; 72 } 73 74 75 79 public void registerLogger(IC2DMessageLogger logger) { 80 this.logger = logger; 81 } 82 83 84 85 89 public WorldObject getWorldObject() { 90 return worldObject; 91 } 92 93 94 public void destroyObject() { 95 worldObject.destroyObject(); 96 } 97 98 99 103 protected void activeObjectAdded(ActiveObject activeObject) { 104 if (listener != null) listener.activeObjectAdded(activeObject); 105 } 106 107 108 protected void activeObjectRemoved(ActiveObject activeObject) { 109 if (listener != null) listener.activeObjectRemoved(activeObject); 110 } 111 112 protected CommunicationEventListener getCommunicationEventListener() { 113 return communicationEventListener; 114 } 115 116 117 121 125 private class MyCommunicationEventListener implements CommunicationEventListener { 126 127 129 public void objectWaitingForRequest(ActiveObject object, SpyEvent spyEvent) { 130 if (listener != null) { 131 listener.objectWaitingByNecessity(object, spyEvent); 132 } 133 } 134 135 public void objectWaitingByNecessity(ActiveObject object, SpyEvent spyEvent) { 136 if (listener != null) { 137 listener.objectWaitingByNecessity(object, spyEvent); 138 } 139 } 140 141 public void requestMessageSent(ActiveObject object, SpyEvent spyEvent) { 142 if (listener != null) { 143 listener.requestMessageSent(object, spyEvent); 145 } 146 } 147 148 public void requestMessageReceived(ActiveObject object, SpyEvent spyEvent) { 149 if (listener != null) { 150 listener.requestMessageReceived(object, spyEvent); 152 } 153 } 154 155 public void replyMessageSent(ActiveObject object, SpyEvent spyEvent) { 156 if (listener != null) { 157 listener.replyMessageSent(object, spyEvent); 159 } 160 } 161 162 public void replyMessageReceived(ActiveObject object, SpyEvent spyEvent) { 163 if (listener != null) { 164 listener.replyMessageReceived(object, spyEvent); 166 } 167 } 168 169 public void voidRequestServed(ActiveObject object, SpyEvent spyEvent) { 170 if (listener != null) { 171 listener.voidRequestServed(object, spyEvent); 173 } 174 } 175 176 public void allEventsProcessed() { 177 if (listener != null) { 178 listener.allEventsProcessed(); 179 } 180 } 181 } 182 183 184 185 private class MyController implements DataObjectController { 186 187 private boolean isMonitoring = true; 188 189 public MyController() { 190 } 191 192 public boolean isMonitoring() { 193 return isMonitoring; 194 } 195 196 public void setMonitoring(boolean b) { 197 isMonitoring = b; 198 } 199 200 public void warn(String message) { 201 if (logger != null) logger.warn(message); 202 } 203 204 public void log(String message) { 205 if (logger != null) logger.log(message); 206 } 207 208 public void log(String message, Throwable e) { 209 if (logger != null) logger.log(message, e); 210 } 211 212 public void log(Throwable e) { 213 if (logger != null) logger.log(e); 214 } 215 216 } 217 218 } 219 | Popular Tags |