KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > body > message > MessageEventProducerImpl


1 /*
2 * ################################################################
3 *
4 * ProActive: The Java(TM) library for Parallel, Distributed,
5 * Concurrent computing with Security and Mobility
6 *
7 * Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
8 * Contact: proactive-support@inria.fr
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
24 *
25 * Initial developer(s): The ProActive Team
26 * http://www.inria.fr/oasis/ProActive/contacts.html
27 * Contributor(s):
28 *
29 * ################################################################
30 */

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 JavaDoc {
41   
42   public MessageEventProducerImpl() {}
43   
44   //
45
// -- PUBLIC METHODS -----------------------------------------------
46
//
47

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   //
60
// -- implements MessageEventProducer -----------------------------------------------
61
//
62

63   public void addMessageEventListener(MessageEventListener listener) {
64     addListener(listener);
65   }
66
67   public void removeMessageEventListener(MessageEventListener listener) {
68     removeListener(listener);
69   }
70
71
72   //
73
// -- PROTECTED METHODS -----------------------------------------------
74
//
75

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         // WARNING: we don't generate an event in the following case:
82
// - The listener is an active object AND
83
// - The destination of the request is the listener
84
// This is done to avoid recursive generation of events
85
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 } // end inner class MessageEventProducer
116
Popular Tags