1 31 package org.objectweb.proactive.ic2d.data; 32 33 import org.objectweb.proactive.Body; 34 import org.objectweb.proactive.ProActive; 35 import org.objectweb.proactive.ic2d.event.SpyEventListener; 36 import org.objectweb.proactive.ic2d.spy.BodyCreationSpyEvent; 37 import org.objectweb.proactive.ic2d.spy.BodySpyEvent; 38 import org.objectweb.proactive.ic2d.spy.SpyEvent; 39 import org.objectweb.proactive.ic2d.spy.SpyListener; 40 41 public class SpyListenerImpl implements SpyListener { 42 43 protected SpyEventListener spyEventListener; 44 45 49 public SpyListenerImpl() { 50 } 51 52 53 public SpyListenerImpl(SpyEventListener spyEventListener) { 54 this.spyEventListener = spyEventListener; 55 } 56 57 58 62 public void terminate() { 63 Body body = ProActive.getBodyOnThis(); 64 if (body != null) 65 body.terminate(); 66 } 67 68 69 73 76 public void observationPerformed(SpyEvent spyEvent) { 77 fireSpyEventInternal(spyEvent); 78 spyEventListener.allEventsProcessed(); 79 } 80 81 82 85 public void observationsPerformed(SpyEvent[] spyEvents) { 86 if (spyEvents.length > 0) 87 for (int i=0; i<spyEvents.length; i++) { 89 fireSpyEventInternal(spyEvents[i]); 90 } 91 if (spyEvents.length > 0) 92 spyEventListener.allEventsProcessed(); 93 } 94 95 96 100 private void fireSpyEventInternal(SpyEvent spyEvent) { 101 switch (spyEvent.getType()) { 102 case SpyEvent.BODY_CREATION_EVENT_TYPE: 103 BodyCreationSpyEvent event = (BodyCreationSpyEvent) spyEvent; 104 spyEventListener.activeObjectAdded(spyEvent.getBodyID(), event.getNodeURL(), event.getClassName(), event.isActive()); 105 break; 106 107 case SpyEvent.BODY_EVENT_TYPE: 108 BodySpyEvent bse = (BodySpyEvent) spyEvent; 109 spyEventListener.activeObjectChanged(spyEvent.getBodyID(), bse.isActive(), bse.isAlive()); 110 break; 111 112 case SpyEvent.OBJECT_WAIT_BY_NECESSITY_TYPE: 113 spyEventListener.objectWaitingByNecessity(spyEvent.getBodyID(), spyEvent); 114 break; 115 116 case SpyEvent.OBJECT_RECEIVED_FUTURE_RESULT_TYPE: 117 spyEventListener.objectReceivedFutureResult(spyEvent.getBodyID(), spyEvent); 118 break; 119 120 case SpyEvent.OBJECT_WAIT_FOR_REQUEST_TYPE: 121 spyEventListener.objectWaitingForRequest(spyEvent.getBodyID(), spyEvent); 122 break; 123 124 case SpyEvent.REQUEST_SENT_MESSAGE_TYPE: 125 spyEventListener.requestMessageSent(spyEvent.getBodyID(), spyEvent); 126 break; 127 128 case SpyEvent.REPLY_SENT_MESSAGE_TYPE: 129 spyEventListener.replyMessageSent(spyEvent.getBodyID(), spyEvent); 130 break; 131 132 case SpyEvent.REQUEST_RECEIVED_MESSAGE_TYPE: 133 spyEventListener.requestMessageReceived(spyEvent.getBodyID(), spyEvent); 134 break; 135 136 case SpyEvent.REPLY_RECEIVED_MESSAGE_TYPE: 137 spyEventListener.replyMessageReceived(spyEvent.getBodyID(), spyEvent); 138 break; 139 140 case SpyEvent.VOID_REQUEST_SERVED_TYPE: 141 spyEventListener.voidRequestServed(spyEvent.getBodyID(), spyEvent); 142 break; 143 144 case SpyEvent.SERVING_STARTED_TYPE: 145 spyEventListener.servingStarted(spyEvent.getBodyID(), spyEvent); 146 break; 147 148 } 149 } 150 151 152 } | Popular Tags |