KickJava   Java API By Example, From Geeks To Geeks.

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


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.ic2d.event.CommunicationEventListener;
34 import org.objectweb.proactive.ic2d.event.IC2DObjectListener;
35 import org.objectweb.proactive.ic2d.spy.SpyEvent;
36 import org.objectweb.proactive.ic2d.util.IC2DMessageLogger;
37
38 /**
39  * Holder class for all hosts
40  */

41 public class IC2DObject extends AbstractDataObject {
42
43   protected IC2DObjectListener listener;
44   protected WorldObject worldObject;
45   protected IC2DMessageLogger logger;
46   protected CommunicationEventListener communicationEventListener;
47
48   //
49
// -- CONSTRUCTORS -----------------------------------------------
50
//
51

52   public IC2DObject() {
53     super();
54     controller = new MyController();
55     communicationEventListener = new MyCommunicationEventListener();
56     worldObject = new WorldObject(this);
57     putChild(worldObject, worldObject);
58   }
59
60
61   //
62
// -- PUBLIC METHOD -----------------------------------------------
63
//
64

65   
66   //
67
// Event Listener
68
//
69

70   public void registerListener(IC2DObjectListener listener) {
71     this.listener = listener;
72   }
73   
74   
75   //
76
// IC2DMessageLogger
77
//
78

79   public void registerLogger(IC2DMessageLogger logger) {
80     this.logger = logger;
81   }
82   
83
84   
85   //
86
// World related method
87
//
88

89   public WorldObject getWorldObject() {
90     return worldObject;
91   }
92
93
94   public void destroyObject() {
95     worldObject.destroyObject();
96   }
97
98
99   //
100
// -- PROTECTED METHOD -----------------------------------------------
101
//
102

103   protected void activeObjectAdded(ActiveObject activeObject) {
104     if (listener != null) listener.activeObjectAdded(activeObject);
105   }
106   
107   
108   protected void activeObjectRemoved(ActiveObject activeObject) {
109     if (listener != null) listener.activeObjectRemoved(activeObject);
110   }
111
112   protected CommunicationEventListener getCommunicationEventListener() {
113     return communicationEventListener;
114   }
115
116
117   //
118
// -- PRIVATE METHODS -----------------------------------------------
119
//
120

121   //
122
// -- INNER CLASSES -----------------------------------------------
123
//
124

125   private class MyCommunicationEventListener implements CommunicationEventListener {
126   
127     // -- implements CommunicationEventListener -----------------------------------------------
128

129     public void objectWaitingForRequest(ActiveObject object, SpyEvent spyEvent) {
130       if (listener != null) {
131         listener.objectWaitingByNecessity(object, spyEvent);
132       }
133     }
134   
135     public void objectWaitingByNecessity(ActiveObject object, SpyEvent spyEvent) {
136       if (listener != null) {
137         listener.objectWaitingByNecessity(object, spyEvent);
138       }
139     }
140   
141     public void requestMessageSent(ActiveObject object, SpyEvent spyEvent) {
142        if (listener != null) {
143          //System.out.println("requestMessageSent method="+((org.objectweb.proactive.ic2d.spy.SpyMessageEvent)spyEvent).getMethodName());
144
listener.requestMessageSent(object, spyEvent);
145        }
146     }
147   
148     public void requestMessageReceived(ActiveObject object, SpyEvent spyEvent) {
149        if (listener != null) {
150          //System.out.println("requestMessageReceived method="+((org.objectweb.proactive.ic2d.spy.SpyMessageEvent)spyEvent).getMethodName());
151
listener.requestMessageReceived(object, spyEvent);
152        }
153     }
154   
155     public void replyMessageSent(ActiveObject object, SpyEvent spyEvent) {
156        if (listener != null) {
157          //System.out.println("replyMessageSent method="+((org.objectweb.proactive.ic2d.spy.SpyMessageEvent)spyEvent).getMethodName());
158
listener.replyMessageSent(object, spyEvent);
159        }
160     }
161
162     public void replyMessageReceived(ActiveObject object, SpyEvent spyEvent) {
163        if (listener != null) {
164          // System.out.println("replyMessageReceived method="+((org.objectweb.proactive.ic2d.spy.SpyMessageEvent)spyEvent).getMethodName());
165
listener.replyMessageReceived(object, spyEvent);
166        }
167     }
168
169     public void voidRequestServed(ActiveObject object, SpyEvent spyEvent) {
170        if (listener != null) {
171          // System.out.println("voidRequestServed method="+((org.objectweb.proactive.ic2d.spy.SpyMessageEvent)spyEvent).getMethodName());
172
listener.voidRequestServed(object, spyEvent);
173        }
174     }
175
176     public void allEventsProcessed() {
177       if (listener != null) {
178         listener.allEventsProcessed();
179       }
180     }
181   }
182
183
184   
185   private class MyController implements DataObjectController {
186   
187     private boolean isMonitoring = true;
188
189     public MyController() {
190     }
191     
192     public boolean isMonitoring() {
193       return isMonitoring;
194     }
195
196     public void setMonitoring(boolean b) {
197       isMonitoring = b;
198     }
199
200     public void warn(String JavaDoc message) {
201       if (logger != null) logger.warn(message);
202     }
203
204     public void log(String JavaDoc message) {
205       if (logger != null) logger.log(message);
206     }
207
208     public void log(String JavaDoc message, Throwable JavaDoc e) {
209       if (logger != null) logger.log(message, e);
210     }
211
212     public void log(Throwable JavaDoc e) {
213       if (logger != null) logger.log(e);
214     }
215
216   }
217
218 }
219
Popular Tags