GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members  

ResourceBroker.java

Go to the documentation of this file.
00001 package org.gridlab.gat.resources;
00002 
00003 import java.io.IOException;
00004 import java.util.List;
00005 
00006 import org.gridlab.gat.GATContext;
00007 import org.gridlab.gat.Preferences;
00008 import org.gridlab.gat.engine.GATEngine;
00009 import org.gridlab.gat.net.RemoteException;
00010 import org.gridlab.gat.resources.cpi.ResourceBrokerCpi;
00011 import org.gridlab.gat.util.TimePeriod;
00012 
00013 /**
00014  * An instance of this class is used to reserve resources.
00015  * <p>
00016  * A resource can either be a hardware resource or a software resource. A
00017  * software resource is simply an executable it makes little sense to reserve
00018  * such. Thus an instance of this class can currently only reserve a hardware
00019  * resource.
00020  * <p>
00021  * If one wishes to reserve a hardware resource, one must first describe the
00022  * hardware resource that one wishes to reserve. This is accomplished by
00023  * creating an instance of the class HardwareResourceDescription which describes
00024  * the hardware resource that one wishes to reserve. After creating such an
00025  * instance of the class HardwareResourceDescription that describes the hardware
00026  * resource one wishes to reserve, one must specify the time period for which
00027  * one wishes to reserve the hardware resource. This is accomplished by creating
00028  * an instance of the class TimePeriod which specifies the time period for which
00029  * one wishes to reserve the hardware resource. Finally, one must obtain a
00030  * reservation for the desired hardware resource for the desired time period.
00031  * This is accomplished by calling the method ReserveHardwareResource() on an
00032  * instance of the class ResourceBroker with the appropriate instance of
00033  * HardwareResourceDescription and the appropriate instance of TimePeriod.
00034  * <p>
00035  * In addition an instance of this class can be used to find hardware resources.
00036  * This is accomplished using the method FindHardwareResources(). This is
00037  * accomplished by creating an instance of the class HardwareResourceDescription
00038  * which describes the hardware resource that one wishes to find. After creating
00039  * such an instance of the class HardwareResourceDescription that describes the
00040  * hardware resource one wishes to find, one must find the corresponding
00041  * hardware resource. This is accomplished by calling the method
00042  * FindHardwareResources() on an instance of the class ResourceBroker with the
00043  * appropriate instance of HardwareResourceDescription.
00044  */
00045 public abstract class ResourceBroker {
00046 
00047     protected GATContext gatContext;
00048 
00049     protected Preferences preferences;
00050 
00051     /**
00052      * This method constructs a ResourceBroker instance corresponding to the
00053      * passed GATContext.
00054      * 
00055      * @param gatContext
00056      *            A GATContext which will be used to broker resources
00057      * @param preferences
00058      *            The Preferences for this instance
00059      * @throws java.lang.Exception
00060      *             Thrown upon creation problems
00061      */
00062     protected ResourceBroker(GATContext gatContext, Preferences preferences)
00063             throws Exception {
00064         this.gatContext = gatContext;
00065         this.preferences = preferences;
00066     }
00067 
00068     /**
00069      * This method constructs a ResourceBroker instance corresponding to the
00070      * passed GATContext.
00071      * 
00072      * @param gatContext
00073      *            A GATContext which will be used to broker resources
00074      * @param preferences
00075      *            The Preferences for this instance
00076      * @throws java.lang.Exception
00077      *             Thrown upon creation problems
00078      */
00079     public ResourceBroker create(GATContext gatContext, Preferences preferences)
00080             throws Exception {
00081         GATEngine gatEngine = GATEngine.getGATEngine();
00082 
00083         ResourceBrokerCpi r = (ResourceBrokerCpi) gatEngine.getAdaptor(
00084                 ResourceBrokerCpi.class, gatContext, preferences, null);
00085 
00086         return r;
00087     }
00088 
00089     /**
00090      * Tests this ResourceBroker for equality with the passed Object.
00091      * <p>
00092      * If the given object is not a ResourceBroker, then this method immediately
00093      * returns false.
00094      * <p>
00095      * If the passed object is a ResourceBroker, then it is deemed equal if it
00096      * has an equivalent GATContext, as determined by the Equals method on
00097      * GATContext.
00098      * 
00099      * @param object
00100      *            The Object to test for equality
00101      * @return A boolean indicating equality
00102      */
00103     public boolean equals(Object object) {
00104         if (false == (object instanceof ResourceBroker)) return false;
00105 
00106         return gatContext.equals(((ResourceBroker) object).gatContext);
00107     }
00108 
00109     /**
00110      * This method attempts to reserve the specified resource for the specified
00111      * time period. Upon reserving the specified resource this method returns a
00112      * Reservation. Upon failing to reserve the specified resource this method
00113      * returns an error.
00114      * 
00115      * @param resourceDescription
00116      *            A description, a ResourceDescription, of the hardware resource
00117      *            to reserve
00118      * @param timePeriod
00119      *            The time period, a TimePeriod , for which to reserve the
00120      *            hardware resource
00121      * @throws RemoteException
00122      *             Thrown upon problems accessing the remote instance
00123      * @throws java.io.IOException
00124      *             Upon non-remote IO problem
00125      */
00126     public abstract Reservation reserveResource(
00127             ResourceDescription resourceDescription, TimePeriod timePeriod)
00128             throws RemoteException, IOException;
00129 
00130     /**
00131      * This method attempts to reserve the specified resource for the specified
00132      * time period. Upon reserving the specified resource this method returns a
00133      * Reservation. Upon failing to reserve the specified resource this method
00134      * returns an error.
00135      * 
00136      * @param resource
00137      *            The resource to reserve.
00138      * @param timePeriod
00139      *            The time period, a TimePeriod , for which to reserve the
00140      *            hardware resource
00141      * @throws RemoteException
00142      *             Thrown upon problems accessing the remote instance
00143      * @throws java.io.IOException
00144      *             Upon non-remote IO problem
00145      */
00146     public abstract Reservation reserveResource(Resource resource,
00147             TimePeriod timePeriod) throws RemoteException, IOException;
00148 
00149     /**
00150      * This method attempts to find one or more matching hardware resources.
00151      * Upon finding the specified hardware resource(s) this method returns a
00152      * java.util.List of HardwareResource instances. Upon failing to find the
00153      * specified hardware resource this method returns an error.
00154      * 
00155      * @param resourceDescription
00156      *            A description, a ResoucreDescription, of the resource(s) to
00157      *            find
00158      * @return java.util.List of Resources upon success
00159      * @throws RemoteException
00160      *             Thrown upon problems accessing the remote instance
00161      * @throws java.io.IOException
00162      *             Upon non-remote IO problem
00163      */
00164     public abstract List findResources(ResourceDescription resourceDescription)
00165             throws RemoteException, IOException;
00166 
00167     /**
00168      * This operation takes a JobDescription, and submits the specified job to
00169      * some underlying resource management or allocation system. On success, a
00170      * GATJob instance is returned, which represents the job. Upon failing to
00171      * submit the job, an error is issued.
00172      * 
00173      * @param description
00174      *            The job description.
00175      * @return @throws
00176      *         RemoteException Thrown upon problems accessing the remote
00177      *         instance
00178      * @throws IOException
00179      *             Upon non-remote IO problem
00180      */
00181     public abstract Job submitJob(JobDescription description)
00182             throws RemoteException, IOException;
00183 }