KickJava   Java API By Example, From Geeks To Geeks.

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


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.core.util.UrlBuilder;
34 import org.objectweb.proactive.ic2d.event.WorldObjectListener;
35 import org.objectweb.proactive.ic2d.util.CreateJiniNodeTask;
36 import org.objectweb.proactive.ic2d.util.RunnableProcessor;
37
38 /**
39  * Holder class for all hosts
40  */

41 public class WorldObject extends AbstractDataObject {
42
43   protected WorldObjectListener listener;
44
45   //
46
// -- CONSTRUCTORS -----------------------------------------------
47
//
48

49   public WorldObject(IC2DObject parent) {
50     super(parent);
51     controller.log("WorldObject created");
52   }
53
54
55   //
56
// -- PUBLIC METHOD -----------------------------------------------
57
//
58

59
60   //
61
// Event Listener
62
//
63

64   public void registerListener(WorldObjectListener listener) {
65     this.messageMonitoringListener = listener;
66     this.listener = listener;
67   }
68   
69
70   
71   //
72
// Host related methods
73
//
74

75   public HostObject addHostObject(String JavaDoc hostname, String JavaDoc protocol) throws java.rmi.RemoteException JavaDoc {
76     return addHostObject(hostname, null, protocol);
77   }
78   
79
80   public HostObject addHostObject(String JavaDoc hostname, String JavaDoc nodeName, String JavaDoc protocol) throws java.rmi.RemoteException JavaDoc {
81     String JavaDoc shortHostname = null;
82     try {
83         shortHostname = java.net.InetAddress.getByName(UrlBuilder.removePortFromHost(hostname)).getHostName();
84     } catch (java.net.UnknownHostException JavaDoc e) {
85       controller.warn("Hostname "+shortHostname+ " failed reverse lookup.");
86       return null;
87     }
88     HostObject host = getHostObject(hostname);
89     if (host == null) {
90       host = new HostObject(this, hostname, protocol);
91       putChild(hostname, host);
92       if (listener != null) listener.hostObjectAdded(host);
93     } else {
94       controller.log("Hostname "+hostname+ " already monitored, check for new nodes.");
95     }
96     if (nodeName == null) {
97       host.createAllNodes();
98     } else {
99       host.createOneNode(nodeName);
100     }
101     return host;
102   }
103   
104   public void addHosts(){
105     RunnableProcessor.getInstance().processRunnable("Create Jini nodes", new CreateJiniNodeTask(this), controller);
106   }
107   
108   public void addHosts(String JavaDoc host){
109     RunnableProcessor.getInstance().processRunnable("Create Jini nodes", new CreateJiniNodeTask(this, host), controller);
110   }
111
112   public void addHostsObject(HostObject host){
113     if (listener != null) listener.hostObjectAdded(host);
114   }
115   
116
117   public void removeHostObject(String JavaDoc hostname) {
118     HostObject host = (HostObject) removeChild(hostname);
119     if (host != null) {
120       if (listener != null) listener.hostObjectRemoved(host);
121     }
122   }
123
124
125   public HostObject getHostObject(String JavaDoc hostname) {
126     return (HostObject) getChild(hostname);
127   }
128   
129   
130   public void destroyObject() {
131     destroy();
132   }
133   
134
135   //
136
// -- PROTECTED METHOD -----------------------------------------------
137
//
138

139   protected IC2DObject getTypedParent() {
140     return (IC2DObject)parent;
141   }
142
143
144   /**
145    * destroy this object
146    */

147    protected synchronized boolean destroy() {
148      if (super.destroy()) {
149        listener = null;
150        return true;
151      } else {
152       return false;
153      }
154    }
155
156   
157   //
158
// -- PRIVATE METHODS -----------------------------------------------
159
//
160

161 }
162
163
164
Popular Tags