View Javadoc

1   package org.ogf.saga.job;
2   
3   import org.ogf.saga.error.*;
4   
5   
6   public class StartJob extends Thread {
7   
8   	private JobService service ;
9   	private SagaException threadException;
10  	private int index ;
11  	private  boolean isLong;
12  		
13  	public StartJob(JobService m_jobservice, int i, boolean isLong) throws Exception {
14  		this.service = m_jobservice;
15  		this.index = i;
16  		this.isLong = isLong;
17  	}
18  	
19  	/**
20       * Executes the process.
21       */
22      public void run() {
23      	
24          try {
25          	// prepare
26  	    	JobDescription desc = JobFactory.createJobDescription();
27  	    	if(isLong) {
28  	    		desc.setAttribute(JobDescription.EXECUTABLE, "/bin/sleep");
29  	    		desc.setVectorAttribute(JobDescription.ARGUMENTS, new String[]{"30"});
30  	    	}
31  	    	else {
32  	    		desc.setAttribute(JobDescription.EXECUTABLE, "/bin/date");
33  	    	}
34  	        desc.setAttribute(JobDescription.OUTPUT, index+"-stdout.txt");
35  	        desc.setAttribute(JobDescription.ERROR, index+"-stderr.txt");
36  	        
37  	        // submit
38  	        Job job = service.createJob(desc);
39  	        job.run();
40  	        
41  	        // wait the end 
42  	        job.waitFor();
43  	        
44  	        if(!job.getState().toString().equals("DONE")) {
45                  job.rethrow();
46                  throw new NoSuccessException("The job number '"+index+"' is not DONE :"+job.getState().toString());
47  	        }
48  		} catch (SagaException e) {
49  			threadException = e; 
50  		}
51      }
52      
53      public SagaException getException () {
54      	return threadException ;
55      }
56  }