org/objectweb/proactive/core/body/message/MessageEventProducerImpl.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
00028  * 
00029  * ################################################################
00030  */ 
00031 package org.objectweb.proactive.core.body.message;
00032 
00033 import org.objectweb.proactive.core.UniqueID;
00034 import org.objectweb.proactive.core.event.AbstractEventProducer;
00035 import org.objectweb.proactive.core.event.MessageEvent;
00036 import org.objectweb.proactive.core.event.MessageEventListener;
00037 import org.objectweb.proactive.core.event.ProActiveEvent;
00038 import org.objectweb.proactive.core.event.ProActiveListener;
00039 
00040 
00041 public class MessageEventProducerImpl extends AbstractEventProducer
00042     implements MessageEventProducer, java.io.Serializable {
00043     public MessageEventProducerImpl() {
00044     }
00045 
00046     //
00047     // -- PUBLIC METHODS -----------------------------------------------
00048     //
00049     public void notifyListeners(Message message, int type, UniqueID bodyID,
00050         int requestQueueLength) {
00051         if (hasListeners()) {
00052             notifyAllListeners(new MessageEvent(message, type, bodyID,
00053                     requestQueueLength));
00054         }
00055     }
00056 
00057     public void notifyListeners(Message message, int type, UniqueID bodyID) {
00058         if (hasListeners()) {
00059             notifyAllListeners(new MessageEvent(message, type, bodyID, -1));
00060         }
00061     }
00062 
00063     //
00064     // -- implements MessageEventProducer -----------------------------------------------
00065     //
00066     public void addMessageEventListener(MessageEventListener listener) {
00067         addListener(listener);
00068     }
00069 
00070     public void removeMessageEventListener(MessageEventListener listener) {
00071         removeListener(listener);
00072     }
00073 
00074     //
00075     // -- PROTECTED METHODS -----------------------------------------------
00076     //
00077     protected void notifyOneListener(ProActiveListener listener,
00078         ProActiveEvent event) {
00079         MessageEvent messageEvent = (MessageEvent) event;
00080         MessageEventListener messageEventListener = (MessageEventListener) listener;
00081         switch (messageEvent.getType()) {
00082         case MessageEvent.REQUEST_SENT:
00083             // WARNING: we don't generate an event in the following case:
00084             //   - The listener is an active object  AND
00085             //   - The destination of the request is the listener
00086             // This is done to avoid recursive generation of events
00087             if (listener instanceof org.objectweb.proactive.core.mop.StubObject) {
00088                 org.objectweb.proactive.core.mop.StubObject so = (org.objectweb.proactive.core.mop.StubObject) listener;
00089                 UniqueID id = ((org.objectweb.proactive.core.body.proxy.BodyProxy) so.getProxy()).getBodyID();
00090                 if (id.equals(messageEvent.getDestinationBodyID())) {
00091                     break;
00092                 }
00093             }
00094             messageEventListener.requestSent(messageEvent);
00095             break;
00096         case MessageEvent.REQUEST_RECEIVED:
00097             messageEventListener.requestReceived(messageEvent);
00098             break;
00099         case MessageEvent.REPLY_SENT:
00100             messageEventListener.replySent(messageEvent);
00101             break;
00102         case MessageEvent.REPLY_RECEIVED:
00103             messageEventListener.replyReceived(messageEvent);
00104             break;
00105         case MessageEvent.VOID_REQUEST_SERVED:
00106             messageEventListener.voidRequestServed(messageEvent);
00107             break;
00108         case MessageEvent.SERVING_STARTED:
00109             messageEventListener.servingStarted(messageEvent);
00110             break;
00111         }
00112     }
00113 } // end inner class MessageEventProducer

Generated on Mon Jan 22 15:16:05 2007 for ProActive by  doxygen 1.5.1