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  

LogicalFile.java

Go to the documentation of this file.
00001 package org.gridlab.gat.io;
00002 
00003 import java.io.IOException;
00004 import java.net.URI;
00005 import java.util.List;
00006 
00007 import org.gridlab.gat.GATContext;
00008 import org.gridlab.gat.Preferences;
00009 import org.gridlab.gat.engine.GATEngine;
00010 import org.gridlab.gat.io.cpi.LogicalFileCpi;
00011 import org.gridlab.gat.monitoring.Metric;
00012 import org.gridlab.gat.monitoring.MetricListener;
00013 import org.gridlab.gat.monitoring.Monitorable;
00014 import org.gridlab.gat.net.RemoteException;
00015 
00016 /**
00017  * An abstract representation of a set of identical physical files.
00018  * <p>
00019  * A LogicalFile is an abstract representation of a set of identical physical
00020  * files. This abstraction is useful for a number of reasons. For example, if
00021  * one wishes to replicate a physical file which is at one URI to a second URI.
00022  * Normally, one takes all the data at the first URI and replicates it to the
00023  * second URI even though the "network distance," between the first and second
00024  * URI may be great. A better solution to this problem is to have a set of
00025  * identical physical files distributed at different locations in "network
00026  * space." If one then wishes to replicate a physical file from one URI to a
00027  * second URI, GAT can then first determine which physical file is closest in
00028  * "network space" to the second URI, chose that physical file as the source
00029  * file, and copy it to the destination URI. Similarly, the construct of a
00030  * LogicalFile allows for migrating programs to, while at a given point in
00031  * "network space," use the closest physical file in "network space" to its
00032  * physical location.
00033  */
00034 public abstract class LogicalFile implements Monitorable {
00035 
00036     protected URI location;
00037 
00038     protected GATContext gatContext;
00039 
00040     protected Preferences preferences;
00041 
00042     /**
00043      * This constructor creates a LogicalFile corresponding to the passed URI
00044      * instance and uses the passed GATContext to broker resources.
00045      * 
00046      * @param location
00047      *            The URI of one physical file in this LogicalFile
00048      * @param gatContext
00049      *            The GATContext used to broker resources
00050      * @param preferences
00051      *            The Preferences for this instance
00052      * @throws java.lang.Exception
00053      *             Thrown upon creation problems
00054      */
00055     protected LogicalFile(GATContext gatContext, Preferences preferences,
00056             URI location) throws IOException {
00057         this.location = location;
00058         this.gatContext = gatContext;
00059         this.preferences = preferences;
00060     }
00061 
00062     /**
00063      * This method creates a LogicalFile corresponding to the passed URI
00064      * instance and uses the passed GATContext to broker resources.
00065      * 
00066      * @param location
00067      *            The URI of one physical file in this LogicalFile
00068      * @param gatContext
00069      *            The GATContext used to broker resources
00070      * @param preferences
00071      *            The Preferences for this instance
00072      * @throws java.lang.Exception
00073      *             Thrown upon creation problems
00074      */
00075     public LogicalFile create(GATContext gatContext, URI location)
00076             throws Exception {
00077         return create(gatContext, null, location);
00078     }
00079 
00080     /**
00081      * This method creates a LogicalFile corresponding to the passed URI
00082      * instance and uses the passed GATContext to broker resources.
00083      * 
00084      * @param location
00085      *            The URI of one physical file in this LogicalFile
00086      * @param gatContext
00087      *            The GATContext used to broker resources
00088      * @param preferences
00089      *            The Preferences for this instance
00090      * @throws java.lang.Exception
00091      *             Thrown upon creation problems
00092      */
00093     public LogicalFile create(GATContext gatContext, Preferences preferences,
00094             URI location) throws Exception {
00095         GATEngine gatEngine = GATEngine.getGATEngine();
00096 
00097         Object[] array = new Object[1];
00098         array[0] = location;
00099 
00100         LogicalFileCpi f = (LogicalFileCpi) gatEngine.getAdaptor(
00101                 LogicalFileCpi.class, gatContext, preferences, array);
00102 
00103         return f;
00104     }
00105 
00106     /**
00107      * Adds the passed File instance to the set of physical files represented by
00108      * this LogicalFile instance.
00109      * 
00110      * @param file
00111      *            A File instance to add to the set of physical files
00112      *            represented by this LogicalFile instance.
00113      * @throws java.rmi.RemoteException
00114      *             Thrown upon problems accessing the remote instance
00115      */
00116     public abstract void addFile(File file) throws RemoteException;
00117 
00118     /**
00119      * Adds the physical file at the passed URI to the set of physical files
00120      * represented by this LogicalFile instance.
00121      * 
00122      * @param location
00123      *            The URI of a physical file to add to the set of physical files
00124      *            represented by this LogicalFile instance.
00125      * @throws java.rmi.RemoteException
00126      *             Thrown upon problems accessing the remote instance
00127      */
00128     public abstract void addURI(URI location) throws RemoteException;
00129 
00130     /**
00131      * Removes the passed File instance from the set of physical files
00132      * represented by this LogicalFile instance.
00133      * 
00134      * @param file
00135      *            A File instance to remove from the set of physical files
00136      *            represented by this LogicalFile instance.
00137      * @throws java.rmi.RemoteException
00138      *             Thrown upon problems accessing the remote instance
00139      */
00140     public abstract void removeFile(File file) throws RemoteException;
00141 
00142     /**
00143      * Removes the physical file at the passed URI from the set of physical
00144      * files represented by this LogicalFile instance.
00145      * 
00146      * @param location
00147      *            The URI of a physical file to remove from the set of physical
00148      *            files represented by this LogicalFile instance.
00149      * @throws java.rmi.RemoteException
00150      *             Thrown upon problems accessing the remote instance
00151      */
00152     public abstract void removeURI(URI location) throws RemoteException;
00153 
00154     /**
00155      * Replicates the logical file represented by this instance to the physical
00156      * file specified by the passed URI.
00157      * 
00158      * @param location
00159      *            The URI of the new physical file
00160      * @throws java.rmi.RemoteException
00161      *             Thrown upon problems accessing the remote instance
00162      * @throws java.io.IOException
00163      *             Upon non-remote IO problem
00164      */
00165     public abstract void replicate(URI location) throws RemoteException,
00166             IOException;
00167 
00168     /**
00169      * Returns a java.util.List of URI instances each of which is the URI of a
00170      * physical file represented by this instance.
00171      * 
00172      * @return The java.util.List of URIs
00173      * @throws java.rmi.RemoteException
00174      *             Thrown upon problems accessing the remote instance
00175      */
00176     public abstract List getURIs() throws RemoteException;
00177 
00178     /**
00179      * Returns a java.util.List of File instances each of which is a File
00180      * corresponding to a physical file represented by this instance.
00181      * 
00182      * @return The java.util.List of URIs
00183      * @throws java.rmi.RemoteException
00184      *             Thrown upon problems accessing the remote instance
00185      */
00186     public abstract List getFiles() throws RemoteException;
00187 
00188     /**
00189      * This method adds the passed instance of a MetricListener to the
00190      * java.util.List of MetricListeners which are notified of MetricEvents by
00191      * an instance of this class. The passed MetricListener is only notified of
00192      * MetricEvents which correspond to Metric instance passed to this method.
00193      * 
00194      * @param metricListener
00195      *            The MetricListener to notify of MetricEvents
00196      * @param metric
00197      *            The Metric corresponding to the MetricEvents for which the
00198      *            passed MetricListener will be notified
00199      * @throws java.rmi.RemoteException
00200      *             Thrown upon problems accessing the remote instance
00201      */
00202     public abstract void addMetricListener(MetricListener metricListener,
00203             Metric metric) throws RemoteException;
00204 
00205     /**
00206      * Removes the passed MetricListener from the java.util.List of
00207      * MetricListeners which are notified of MetricEvents corresponding to the
00208      * passed Metric instance.
00209      * 
00210      * @param metricListener
00211      *            The MetricListener to notify of MetricEvents
00212      * @param metric
00213      *            The Metric corresponding to the MetricEvents for which the
00214      *            passed MetricListener will be notified
00215      * @throws java.rmi.RemoteException
00216      *             Thrown upon problems accessing the remote instance
00217      */
00218     public abstract void removeMetricListener(MetricListener metricListener,
00219             Metric metric) throws RemoteException;
00220 
00221     /**
00222      * This method returns a java.util.List of Metric instances. Each Metric
00223      * instance in this java.util.List is a Metric which can be monitored on
00224      * this instance.
00225      * 
00226      * @return An java.util.List of Metric instances. Each Metric instance in
00227      *         this java.util.List is a Metric which can be monitored on this
00228      *         instance.
00229      * @throws java.rmi.RemoteException
00230      *             Thrown upon problems accessing the remote instance
00231      */
00232     public abstract List getMetrics() throws RemoteException;
00233 }