org/objectweb/proactive/scheduler/ProActiveJobHandler.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.ArrayList;
00034 
00035 import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor;
00036 import org.objectweb.proactive.core.descriptor.data.VirtualMachine;
00037 import org.objectweb.proactive.core.descriptor.data.VirtualNode;
00038 import org.objectweb.proactive.core.descriptor.data.VirtualNodeImpl;
00039 import org.objectweb.proactive.core.descriptor.services.SchedulerLookupService;
00040 import org.objectweb.proactive.core.descriptor.services.UniversalService;
00041 import org.objectweb.proactive.core.descriptor.xml.ProActiveDescriptorConstants;
00042 import org.objectweb.proactive.core.descriptor.xml.ProActiveDescriptorHandler;
00043 import org.objectweb.proactive.core.xml.handler.AbstractUnmarshallerDecorator;
00044 import org.objectweb.proactive.core.xml.handler.UnmarshallerHandler;
00045 import org.objectweb.proactive.core.xml.io.Attributes;
00046 
00047 
00055 public class ProActiveJobHandler extends AbstractUnmarshallerDecorator
00056     implements ProActiveDescriptorConstants {
00057     private ProActiveDescriptorHandler proActiveDescriptorHandler;
00058     private String jobId;
00059     private Scheduler scheduler;
00060 
00061     public ProActiveJobHandler(Scheduler scheduler, String jobId,
00062         String xmlDescriptorUrl) {
00063         super();
00064         this.scheduler = scheduler;
00065         this.jobId = jobId;
00066         proActiveDescriptorHandler = new ProActiveDescriptorHandler(scheduler,
00067                 jobId, xmlDescriptorUrl);
00068         this.addHandler(PROACTIVE_DESCRIPTOR_TAG, proActiveDescriptorHandler);
00069     }
00070 
00071     public Object getResultObject() throws org.xml.sax.SAXException {
00072         return null;
00073     }
00074 
00075     public void startContextElement(String name, Attributes attributes)
00076         throws org.xml.sax.SAXException {
00077     }
00078 
00084     protected void notifyEndActiveHandler(String name,
00085         UnmarshallerHandler activeHandler) throws org.xml.sax.SAXException {
00086         ProActiveDescriptor pad = (ProActiveDescriptor) activeHandler.getResultObject();
00087 
00088         int nodeNb = 0;
00089         int minNodeNb = 0;
00090 
00091         VirtualNode[] vns = pad.getVirtualNodes();
00092         for (int i = 0; i < vns.length; ++i) {
00093             VirtualNode vn = vns[i];
00094             ArrayList vms = ((VirtualNodeImpl) vn).getVirtualMachines();
00095             for (int j = 0; j < vms.size(); ++j) {
00096                 VirtualMachine vm = (VirtualMachine) vms.get(j);
00097 
00098                 UniversalService service = vm.getService();
00099                 if (service.getServiceName()
00100                                .equals(SchedulerConstants.SCHEDULER_NODE_NAME)) {
00101                     SchedulerLookupService schedulerLookupService = ((SchedulerLookupService) service);
00102                     nodeNb += schedulerLookupService.getNodeNumber();
00103                     minNodeNb += schedulerLookupService.getMinNodeNumber();
00104                 }
00105             }
00106         }
00107         GenericJob job = scheduler.getTmpJob(jobId);
00108         job.setRessourceNb(nodeNb);
00109         job.setMinNbOfNodes(minNodeNb);
00110         scheduler.commit(jobId);
00111     }
00112 }

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