⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jobfilereader.java

📁 这是一个基于计算网格的web service。它用java编写。一旦安装完成
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * JobFileReader.java * * Created on April 18, 2005, 4:50 PM */package jwsgrid.jobclient.priv;import jwsgrid.xsd.*;import jwsgrid.util.GlobalDefs;import net.hyperic.sigar.*;import net.hyperic.sigar.cmd.*;import java.io.*;import java.util.*;/** * * @author sean */public class JobFileReader {/*        public final static String FILE_SEP = System.getProperty( "file.separator" );    public final static String COMMENT = "#";    public final static String TYPE = "TYPE";    public final static String EXEC = "EXEC";    public final static String INPUT_ARG = "INPUT_ARG";    public final static String INPUT_FILE = "INPUT_FILE";    public final static String ENV_VAR = "ENV_VAR";    public final static String CONSTRAINTS = "CONSTRAINTS";    public final static String MAX_DEPLOYMENTS = "MAX_DEPLOYMENTS";    public final static String MIN_DEPLOYMENTS = "MIN_DEPLOYMENTS";    public final static String NOTIFY_EMAIL = "NOTIFY_EMAIL";        ////////////////////////////////////////////////////////////////////////////    // JobFileReader    //        private Vector jobList = new Vector();    private File jobFile = null;        public JobFileReader( String jobFilePath ) throws FileNotFoundException {        File jobFile = new File( jobFilePath );                if ( !jobFile.exists() ) {            throw new FileNotFoundException(                     "file '" + jobFilePath + "' does not exist" );        }                this.jobFile = jobFile;    }        public JobFileReader( File jobFile ) throws FileNotFoundException {                if ( !jobFile.exists() ) {            throw new FileNotFoundException(                     "file '" + jobFile.getPath().toString() +                     "' does not exist" );        }                this.jobFile = jobFile;    }         public List<JobDescr> getJobs() {        return jobList;    }        /**     * read job description file     *    public void read() throws InvalidJobFileException, IOException, Exception {        FileReader fileReader = null;        BufferedReader bufReader = null;        String data = null;        String dataCopy = null;        String[] results = null;        boolean jobOpen = false;        boolean typeFound = false;        boolean execFound = false;        boolean constraintsFound = false;        boolean maxDeploymentsFound = false;        boolean minDeploymentsFound = false;        boolean found = false;        JobDescr currJob = null;        int lineNum = 0;                try {            bufReader = new BufferedReader( new FileReader( jobFile ) );                        while ( ( data = bufReader.readLine()) != null ) {                lineNum++;                                        data = data.trim();                                 // skip comment lines                if ( data.length() == 0 || data.startsWith( COMMENT ) ) {                    continue;                }                                                // begin job                else if ( data.compareTo( "[" ) == 0 ) {                    currJob = new JobDescr();                    jobOpen = true;                      continue;                }                                 // end job                else if ( data.compareTo( "]" ) == 0 ) {                    if ( !typeFound ) {                        throw new InvalidJobFileException(                                "line " + lineNum + ": previous job " +                                "description did not contain a " + TYPE +                                 " directive" );                                            }                                        if ( !execFound ) {                        throw new InvalidJobFileException(                                "line " + lineNum + ": previous job " +                                "description did not contain an " + EXEC +                                 " directive" );                                            }                                          if ( !constraintsFound ) {                        throw new InvalidJobFileException(                                "line " + lineNum + ": previous job " +                                "description did not contain a " + CONSTRAINTS +                                 " directive" );                                            }                                           if ( !maxDeploymentsFound ) {                        throw new InvalidJobFileException(                                "line " + lineNum + ": previous job " +                                "description did not contain a " + MAX_DEPLOYMENTS +                                 " directive" );                                            }                                         if ( !minDeploymentsFound ) {                        throw new InvalidJobFileException(                                "line " + lineNum + ": previous job " +                                "description did not contain a " + MIN_DEPLOYMENTS +                                 " directive" );                                               }                                        jobList.add( currJob );                                        jobOpen = false;                    typeFound = false;                    execFound = false;                    constraintsFound = false;                    maxDeploymentsFound = false;                      minDeploymentsFound = false;                    continue;                }                                 // out-of place data                else if ( !jobOpen ) {                    throw new InvalidJobFileException(                            "line " + lineNum + ": job description must " +                            "be contained in square brackets" );                }                                checkDoubleQuotes( data, lineNum );                dataCopy = data.toUpperCase();                                                // handle TYPE directive                if ( dataCopy.startsWith( TYPE ) ) {                                        if ( typeFound ) {                        throw new InvalidJobFileException(                                "line " + lineNum + ": a previous " + TYPE +                                 " directive was found; only one is allowed" +                                "per job description" );                                                }                                         data = data.substring( TYPE.length(), data.length() );                     results = getLineValues( data.trim(), lineNum );                                        if ( results == null ) {                        throw new InvalidJobFileException(                                "line " + lineNum + ": invalid value for " +                                TYPE + " directive" );                                            }                                        if ( results.length > 1 ) {                        throw new InvalidJobFileException(                                "line " + lineNum + ": " + TYPE + " directive " +                                "can only have one value" );                                               }                                        found = false;                    for( int i = 0; i < GlobalDefs.JOBTYPES.length; i++ ) {                        if ( GlobalDefs.JOBTYPES[ i ].compareTo( results[ 0 ] ) == 0 ) {                            found = true;                            break;                        }                    }                                            if ( !found ) {                        String msg;                         msg  = "line " + lineNum + ": invalid job type; ";                        msg += "valid types are\n";                                                for( int i = 0; i < GlobalDefs.JOBTYPES.length; i++ ) {                            msg += "\t" + GlobalDefs.JOBTYPES[ i ] + "\n";                        }                                                                        throw new InvalidJobFileException( msg );                                                  }                                        currJob.setType( results[ 0 ] );                    typeFound = true;                }                                 // handle EXEC directive                else if ( dataCopy.startsWith( EXEC ) ) {                                        if ( execFound ) {                        throw new InvalidJobFileException(                                "line " + lineNum + ": a previous " + EXEC +                                 " directive was found; only one is allowed " +                                "per job description ");                                               }                                                            data = data.substring( EXEC.length(), data.length() );                     results = getLineValues( data.trim(), lineNum );                                        if ( results == null ||                             results.length == 0 ||                            results.length > 2 )                     {                        throw new InvalidJobFileException(                                "line " + lineNum + ": file '" + results[ 0 ] +                                "' is a directory" );                                          }                                          File file = new File( results[ 0 ] );                    if ( !file.exists() )                     {                        throw new InvalidJobFileException(                                "line " + lineNum + ": file '" + results[ 0 ] +                                "' does not exist" );                    }                                        if ( file.isDirectory() )                     {                        throw new InvalidJobFileException(                                "line " + lineNum + ": file '" + results[ 0 ] +                                "' is a directory" );                    }                                                             if ( results.length == 1 ) {                        currJob.setExec( results[ 0 ] );                        currJob.setExecDeployPath( FILE_SEP + file.getName() );                    }                                         else                     {                        if ( results[ 1 ].startsWith( FILE_SEP ) )                         {                            results[ 1 ] =                                    results[ 1 ].substring( 1, results[ 1 ].length() );                                                    }                         if ( results[ 1 ].length() > 0 &&                                !results[ 1 ].endsWith( FILE_SEP ) )                         {                            results[ 1 ] += FILE_SEP;                        }                                                 results[ 1 ] += file.getName();                                                currJob.setExec( results[ 0 ] );                        currJob.setExecDeployPath( results[ 1 ] );                                        }                                         execFound = true;                }                                 // handle INPUT_ARG directive                else if ( dataCopy.startsWith( INPUT_ARG ) ) {                    data = data.substring( INPUT_ARG.length(), data.length() );                     results = getLineValues( data.trim(), lineNum );                                        for( int i = 0; i < results.length; i++ ) {                        currJob.addInputArg( results[ i ] );                    }                  }                                 // handle INPUT_FILE directive                else if ( dataCopy.startsWith( INPUT_FILE ) ) {                    data = data.substring( INPUT_FILE.length(), data.length() );                     results = getLineValues( data.trim(), lineNum );                                        if ( results == null ||                             results.length == 0 ||                             results.length > 2 )                     {                        throw new InvalidJobFileException(                                "line " + lineNum + ": " + INPUT_FILE +                                 " directive must have the form \"path to file\"" +                                " [\"desired deployment path\"]" );                      }                                                             File file = new File( results[ 0 ] );                    if ( !file.exists() )                     {                        throw new InvalidJobFileException(                                "line " + lineNum + ": file '" + results[ 0 ] +                                "' does not exist" );                    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -