1 31 package org.objectweb.proactive.core.body.message; 32 33 import org.objectweb.proactive.core.UniqueID; 34 import org.objectweb.proactive.core.event.AbstractEventProducer; 35 import org.objectweb.proactive.core.event.MessageEvent; 36 import org.objectweb.proactive.core.event.MessageEventListener; 37 import org.objectweb.proactive.core.event.ProActiveEvent; 38 import org.objectweb.proactive.core.event.ProActiveListener; 39 40 public class MessageEventProducerImpl extends AbstractEventProducer implements MessageEventProducer, java.io.Serializable { 41 42 public MessageEventProducerImpl() {} 43 44 48 public void notifyListeners(Message message, int type, UniqueID bodyID, int requestQueueLength) { 49 if (hasListeners()) 50 notifyAllListeners(new MessageEvent(message, type, bodyID, requestQueueLength)); 51 } 52 53 public void notifyListeners(Message message, int type, UniqueID bodyID) { 54 if (hasListeners()) 55 notifyAllListeners(new MessageEvent(message, type, bodyID, -1)); 56 } 57 58 59 63 public void addMessageEventListener(MessageEventListener listener) { 64 addListener(listener); 65 } 66 67 public void removeMessageEventListener(MessageEventListener listener) { 68 removeListener(listener); 69 } 70 71 72 76 protected void notifyOneListener(ProActiveListener listener, ProActiveEvent event) { 77 MessageEvent messageEvent = (MessageEvent) event; 78 MessageEventListener messageEventListener = (MessageEventListener) listener; 79 switch (messageEvent.getType()) { 80 case MessageEvent.REQUEST_SENT : 81 if (listener instanceof org.objectweb.proactive.core.mop.StubObject) { 86 org.objectweb.proactive.core.mop.StubObject so = (org.objectweb.proactive.core.mop.StubObject) listener; 87 UniqueID id = ((org.objectweb.proactive.core.body.proxy.BodyProxy) so.getProxy()).getBodyID(); 88 if (id.equals(messageEvent.getDestinationBodyID())) { 89 break; 90 } 91 } 92 messageEventListener.requestSent(messageEvent); 93 break; 94 95 case MessageEvent.REQUEST_RECEIVED : 96 messageEventListener.requestReceived(messageEvent); 97 break; 98 99 case MessageEvent.REPLY_SENT : 100 messageEventListener.replySent(messageEvent); 101 break; 102 103 case MessageEvent.REPLY_RECEIVED : 104 messageEventListener.replyReceived(messageEvent); 105 break; 106 case MessageEvent.VOID_REQUEST_SERVED : 107 messageEventListener.voidRequestServed(messageEvent); 108 break; 109 case MessageEvent.SERVING_STARTED : 110 messageEventListener.servingStarted(messageEvent); 111 break; 112 } 113 } 114 115 } | Popular Tags |