KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > ic2d > data > SpyListenerImpl


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.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   //
46
// -- CONSTRUCTORS -----------------------------------------------
47
//
48

49   public SpyListenerImpl() {
50   }
51   
52
53   public SpyListenerImpl(SpyEventListener spyEventListener) {
54     this.spyEventListener = spyEventListener;
55   }
56   
57   
58   //
59
// -- PUBLIC METHODS -----------------------------------------------
60
//
61

62   public void terminate() {
63     Body body = ProActive.getBodyOnThis();
64     if (body != null)
65       body.terminate();
66   }
67   
68   
69   //
70
// -- implements SpyListener -----------------------------------------------
71
//
72

73   /**
74    * Receives a message from a spy
75    */

76   public void observationPerformed(SpyEvent spyEvent) {
77     fireSpyEventInternal(spyEvent);
78     spyEventListener.allEventsProcessed();
79   }
80
81
82   /**
83    * Receives multiples messages in a buffer
84    */

85   public void observationsPerformed(SpyEvent[] spyEvents) {
86     if (spyEvents.length > 0)
87     //System.out.println("=> received spyEvents n="+spyEvents.length);
88
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   //
97
// -- PRIVATE METHODS -----------------------------------------------
98
//
99

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