KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > descriptor > data > VirtualNodeLookup


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.descriptor.data;
32
33 import java.security.cert.X509Certificate JavaDoc;
34
35 import org.objectweb.proactive.ProActive;
36 import org.objectweb.proactive.core.ProActiveException;
37 import org.objectweb.proactive.core.node.Node;
38 import org.objectweb.proactive.core.node.NodeException;
39 import org.objectweb.proactive.core.runtime.ProActiveRuntime;
40 import org.objectweb.proactive.core.runtime.ProActiveRuntimeImpl;
41 import org.objectweb.proactive.core.util.UrlBuilder;
42 import org.objectweb.proactive.ext.security.PolicyServer;
43
44
45 /**
46  * A <code>VirtualNode</code> represents a conceptual entity. After activation
47  * a <code>VirtualNode</code> represents one or several nodes.
48  *
49  * This class represents a remote VirtualNode resulting from a lookup in some registry such as RMIRegistry
50  * or JINI Lookup service.
51  * Objects of this class will be created when in an XML descriptor a VirtualNode is declared
52  * in the virtualNodesAcquisition tag and defined with
53  * <pre>
54  * lookup virtualNode="Dispatcher" host="hostname" protocol="rmi or jini"
55  * </pre>
56  * @author ProActive Team
57  * @version 1.0, 2003/04/01
58  * @since ProActive 1.0.2
59  */

60 public class VirtualNodeLookup extends RuntimeDeploymentProperties
61     implements VirtualNode {
62     private VirtualNode virtualNode;
63     private ProActiveRuntime remoteProActiveRuntime;
64     private String JavaDoc name;
65     private String JavaDoc urlForLookup;
66     private String JavaDoc lookupProtocol;
67     private boolean isActivated = false;
68
69     //we use 1099 as default port
70
private int portForLookup = 1099;
71     private String JavaDoc message = "########## Calling this method on a VirtualNodeLookup has no sense, since such VirtualNode object references a remote VirtualNode ##########";
72     protected String JavaDoc runtimeHostForLookup = "LOOKUP_HOST";
73
74     public VirtualNodeLookup(String JavaDoc name) {
75         this.name = name;
76         ProActiveRuntimeImpl proActiveRuntimeImpl = (ProActiveRuntimeImpl) ProActiveRuntimeImpl.getProActiveRuntime();
77         proActiveRuntimeImpl.registerLocalVirtualNode(this, this.name);
78     }
79
80     /**
81      * @see org.objectweb.proactive.core.descriptor.data.VirtualNode#setProperty(String)
82      */

83     public void setProperty(String JavaDoc property) {
84         logger.warn(message);
85     }
86
87     /**
88      * @see org.objectweb.proactive.core.descriptor.data.VirtualNode#getProperty()
89      */

90     public String JavaDoc getProperty() {
91         return virtualNode.getProperty();
92     }
93
94     public void setTimeout(String JavaDoc timeout, boolean waitForTimeout) {
95         logger.warn(message);
96     }
97
98     /**
99      * @see org.objectweb.proactive.core.descriptor.data.VirtualNode#setName(String)
100      */

101     public void setName(String JavaDoc s) {
102         logger.warn(message);
103     }
104
105     /**
106      * @see org.objectweb.proactive.core.descriptor.data.VirtualNode#getName()
107      */

108     public String JavaDoc getName() {
109         return virtualNode.getName();
110     }
111
112     /**
113      * @see org.objectweb.proactive.core.descriptor.data.VirtualNode#addVirtualMachine(VirtualMachine)
114      */

115     public void addVirtualMachine(VirtualMachine virtualMachine) {
116         logger.warn(message);
117     }
118
119     /**
120      * @see org.objectweb.proactive.core.descriptor.data.VirtualNode#getVirtualMachine()
121      */

122     public VirtualMachine getVirtualMachine() {
123         return virtualNode.getVirtualMachine();
124     }
125
126     /**
127      * @see org.objectweb.proactive.core.descriptor.data.VirtualNode#activate()
128      */

129     public void activate() {
130         if (!isActivated) {
131             if (isWaitingForProperties()) {
132                 return;
133             }
134             try {
135                 // this.remoteProActiveRuntime = RuntimeFactory.getRuntime(urlForLookup,lookupProtocol);
136
// this.virtualNode = remoteProActiveRuntime.getVirtualNode(this.name);
137
this.virtualNode = ProActive.lookupVirtualNode(urlForLookup,
138                         lookupProtocol);
139                 isActivated = true;
140             } catch (ProActiveException e) {
141                 e.printStackTrace();
142             }
143         } else {
144             logger.info("VirtualNode " + this.name + " already activated !!!");
145         }
146     }
147
148     /**
149      * @see org.objectweb.proactive.core.descriptor.data.VirtualNode#getNodeCount()
150      */

151     public int getNodeCount() {
152         return virtualNode.getNodeCount();
153     }
154
155     /**
156      * @see org.objectweb.proactive.core.descriptor.data.VirtualNode#createdNodeCount()
157      */

158     public int createdNodeCount() {
159         return virtualNode.createdNodeCount();
160     }
161
162     /**
163      * @see org.objectweb.proactive.core.descriptor.data.VirtualNode#getNode()
164      */

165     public Node getNode() throws NodeException {
166         try {
167             checkActivation();
168         } catch (ProActiveException pae) {
169             throw new NodeException(pae);
170         }
171         return virtualNode.getNode();
172     }
173
174     /**
175      * @see org.objectweb.proactive.core.descriptor.data.VirtualNode#getNode(int)
176      */

177     public Node getNode(int index) throws NodeException {
178         try {
179             checkActivation();
180         } catch (ProActiveException pae) {
181             throw new NodeException(pae);
182         }
183         return virtualNode.getNode(index);
184     }
185
186     /**
187      * @see org.objectweb.proactive.core.descriptor.data.VirtualNode#getNodesURL()
188      */

189     public String JavaDoc[] getNodesURL() throws NodeException {
190         try {
191             checkActivation();
192         } catch (ProActiveException pae) {
193             throw new NodeException(pae);
194         }
195         return virtualNode.getNodesURL();
196     }
197
198     /**
199      * @see org.objectweb.proactive.core.descriptor.data.VirtualNode#getNodes()
200      */

201     public Node[] getNodes() throws NodeException {
202         try {
203             checkActivation();
204         } catch (ProActiveException pae) {
205             throw new NodeException(pae);
206         }
207         return virtualNode.getNodes();
208     }
209
210     /**
211      * @see org.objectweb.proactive.core.descriptor.data.VirtualNode#getNode(String)
212      */

213     public Node getNode(String JavaDoc url) throws NodeException {
214         try {
215             checkActivation();
216         } catch (ProActiveException pae) {
217             throw new NodeException(pae);
218         }
219         return virtualNode.getNode(url);
220     }
221
222     public void killAll(boolean softly) {
223         logger.warn(message);
224     }
225
226     /**
227      * @see org.objectweb.proactive.core.descriptor.data.VirtualNode#createNodeOnCurrentJvm(String)
228      */

229     public void createNodeOnCurrentJvm(String JavaDoc protocol) {
230         logger.warn(message);
231     }
232
233     public Object JavaDoc getUniqueAO() throws ProActiveException {
234         checkActivation();
235         return virtualNode.getUniqueAO();
236     }
237
238     public boolean isActivated() {
239         return isActivated;
240     }
241     
242 //
243
//-------------------IMPLEMENTS Job-----------------------------------
244
//
245
public String JavaDoc getJobID(){
246         return virtualNode.getJobID();
247     }
248
249     /**
250      * @see org.objectweb.proactive.core.descriptor.data.VirtualNode#setRuntimeInformations(String,String)
251      * At the moment the only property that can be set at runtime is LOOKUP_HOST.
252      */

253     public void setRuntimeInformations(String JavaDoc information, String JavaDoc value)
254         throws ProActiveException {
255         try {
256             checkProperty(information);
257         } catch (ProActiveException e) {
258             throw new ProActiveException("only " + runtimeHostForLookup +
259                 " property can be set at runtime", e);
260         }
261         performTask(information, value);
262     }
263
264     // //
265
// //-----------------------implements DeploymentPropertiesEventListener ----------
266
// //
267
//
268
// public void lookForProperty(DeploymentPropertiesEvent event){
269
//
270
// }
271
public void setLookupInformations(String JavaDoc url, String JavaDoc protocol, int port) {
272         this.urlForLookup = url;
273
274         if (urlForLookup.indexOf("*") > -1) {
275             runtimeProperties.add(runtimeHostForLookup);
276         }
277
278         this.lookupProtocol = protocol;
279         this.portForLookup = port;
280     }
281
282     private boolean isWaitingForProperties() {
283         return (runtimeProperties.size() >= 1);
284     }
285
286     private void performTask(String JavaDoc information, String JavaDoc value) {
287         if (information.equals(runtimeHostForLookup)) {
288             urlForLookup = UrlBuilder.buildUrl(value, this.name,
289                     this.lookupProtocol, this.portForLookup);
290             runtimeProperties.remove(runtimeHostForLookup);
291             activate();
292         }
293     }
294
295     private void checkActivation() throws ProActiveException {
296         if (isWaitingForProperties()) {
297             String JavaDoc exceptionMessage = "This VirtualNode has not yet been activated since, it is waiting for runtime properties ";
298             for (int i = 0; i < runtimeProperties.size(); i++) {
299                 exceptionMessage = exceptionMessage.concat((String JavaDoc) runtimeProperties.get(
300                             i) + " ");
301             }
302             throw new ProActiveException(exceptionMessage);
303         }
304     }
305     
306     // SECURITY
307
/* (non-Javadoc)
308      * @see org.objectweb.proactive.core.descriptor.data.VirtualNode#getCreatorCertificate()
309      */

310     public X509Certificate JavaDoc getCreatorCertificate() throws ProActiveException {
311         return virtualNode.getCreatorCertificate();
312     }
313
314     /* (non-Javadoc)
315      * @see org.objectweb.proactive.core.descriptor.data.VirtualNode#getPolicyServer()
316      */

317     public PolicyServer getPolicyServer() {
318         return virtualNode.getPolicyServer();
319     }
320
321     /* (non-Javadoc)
322              * @see org.objectweb.proactive.core.descriptor.data.VirtualNode#setPolicyServer()
323              */

324     public void setPolicyServer(PolicyServer ps) {
325         System.out.println(message);
326     // virtualNode.setPolicyServer(ps);
327
}
328
329
330     /* (non-Javadoc)
331      * @see org.objectweb.proactive.core.descriptor.data.VirtualNode#setPolicyFile(java.lang.String)
332      */

333     public void setPolicyFile(String JavaDoc file) {
334         
335     }
336     
337 }
338
Popular Tags