org/objectweb/proactive/scheduler/RessourceListener.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
00028  * 
00029  * ################################################################
00030  */ 
00031 package org.objectweb.proactive.scheduler;
00032 
00033 import java.util.Vector;
00034 
00035 import org.apache.log4j.Logger;
00036 import org.objectweb.proactive.ProActive;
00037 import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor;
00038 import org.objectweb.proactive.core.descriptor.data.VirtualNode;
00039 import org.objectweb.proactive.core.descriptor.data.VirtualNodeImpl;
00040 import org.objectweb.proactive.core.event.NodeCreationEvent;
00041 import org.objectweb.proactive.core.event.NodeCreationEventListener;
00042 import org.objectweb.proactive.core.node.Node;
00043 import org.objectweb.proactive.core.util.log.Loggers;
00044 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00045 
00046 
00055 public class RessourceListener implements NodeCreationEventListener {
00056     private static Logger logger = ProActiveLogger.getLogger(Loggers.RESSOURCE_LISTENER);
00057 
00058     // must implement:   public void nodeCreated(NodeCreationEvent event);
00059     private Vector unusedNodes;
00060 
00061     public RessourceListener(Vector unusedNodes, String xmlURL, Vector vnNames) {
00062         ProActiveDescriptor pad = null;
00063         this.unusedNodes = unusedNodes;
00064 
00065         try {
00066             pad = ProActive.getProactiveDescriptor(xmlURL);
00067         } catch (Exception e) {
00068             logger.error("error starting ressource listener");
00069             throw new RuntimeException(e);
00070         }
00071 
00072         for (int i = 0; i < vnNames.size(); ++i) {
00073             // getting the next virtual node defined in the ProActive Deployement Descriptor
00074             VirtualNode vn = pad.getVirtualNode((String) vnNames.get(i));
00075 
00076             // adding 'this' or anyother class has a listener of the 'NodeCreationEvent'
00077             ((VirtualNodeImpl) vn).addNodeCreationEventListener(this);
00078             //activate that virtual node
00079             vn.activate();
00080         }
00081         logger.debug("starting ressource listener");
00082     }
00083 
00087     public void nodeCreated(NodeCreationEvent event) {
00088         // get the node
00089         Node newNode = event.getNode();
00090         // now you can create an active object on your node.
00091         newNode.getNodeInformation().setJobID("-");
00092         this.unusedNodes.add(newNode);
00093         logger.debug("new node acquired " +
00094             newNode.getNodeInformation().getURL());
00095     }
00096 }

Generated on Mon Jan 22 15:16:12 2007 for ProActive by  doxygen 1.5.1