Job.java 2.91 KB
Newer Older
1
package eu.simstadt.nf4j;
2
3
4
5
6
7

/**
 * This job class bundles the three attributes of every nF job: Id, status and last job related nF (error) message.  
 * 
 * @author Marcel Bruse
 */
bruse's avatar
bruse committed
8
public abstract class Job {
9
10
	
	/** The status of the job. There are different states for export and import jobs. */
11
12
	protected JobStatus status;
	
13
	/** The id of the job. */
14
	protected int id;
15
	
16
	/** The connection to the nF. */
bruse's avatar
bruse committed
17
	protected Connector<?, ?> connector;
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
	
	/**
	 * Every job has it's status. Look up the different possible values in the JobStatus enumeration.
	 * 
	 * @return Returns the status of this job.
	 */
	public JobStatus getStatus() {
		return status;
	}
	
	/**
	 * Lets you set the status of this job.
	 * 
	 * @param status The status of this job.
	 */
	protected void setStatus(JobStatus status) {
		this.status = status;
	}
	
	/**
	 * @return Returns the id of this job.
	 */
40
41
	public int getId() {
		return id;
42
43
44
45
46
47
48
	}
	
	/**
	 * Sets the id of this job.
	 * 
	 * @param jobId The job id about to be set.
	 */
49
50
	public void setId(int jobId) {
		this.id = jobId;
51
52
	}
	
53
54
55
	/**
	 * @return Returns the nF connector of this job.
	 */
bruse's avatar
bruse committed
56
	public Connector<?, ?> getConnector() {
57
		return connector;
58
59
60
61
62
63
64
	}

	/**
	 * Sets the nF connector of this job.
	 * 
	 * @param nFConnector The connector of this job.
	 */
bruse's avatar
bruse committed
65
66
	public void setConnector(Connector<?, ?> connector) {
		this.connector = connector;
67
68
69
	}
	
	/**
70
71
72
73
74
75
76
77
78
79
80
81
82
83
	 * This method reads the job description, builds a job file from it and uses the connector to send the
	 * job file to nF. You may want to implement the file building and file sending parts in the 
	 * connector in order to reuse them here.
	 * 
	 * This method is a object oriented convenience method for NFConnector.sendXXXJobFile(). It is sensible
	 * to have this convenience method, because it offers the API user centralized controls over the jobs
	 * status chain without switching between job instances and connector instances. In the end, the user is
	 * not interested in the connection to the nF, but in the job itself.
	 */
	public abstract void send() throws InvalidJobDescriptorException, FailedTransmissionException;
	
	/**
	 * Connects to the nF and refreshes the status of this job. If there is no nF connector set, or the job id
	 * is unkown by the nF, then this operation will throw a FailedTransmissionException.
84
85
86
87
88
	 * 
	 * @throws FailedTransmissionException If the connection to the nF is broken you will get some of this. 
	 */
	public abstract void updateStatus() throws FailedTransmissionException;
	
89
90
91
92
93
94
95
96
97
98
	/**
	 * Sets the status of this job depending on the given nF status code. nF status codes will be sent
	 * to you in http responses. Export jobs and import jobs have different states. Consider this fact
	 * in your implementation.
	 *  
	 * @param statusCode The nF status code for this job.
	 */
	public abstract void setStatusForCode(int statusCode);
	
}