Job.java 3.97 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
 */
8
public abstract class Job<D extends JobDescriptor> {
9
10
	
	/** The status of the job. There are different states for export and import jobs. */
11
12
13
14
	protected JobStatus status;
	
	/** Every job should have a (valid) job descriptor. */
	protected D descriptor;
15
16
	
	/** The id of the job. */
17
	protected int id;
18
	
19
	/** The connection to the nF. */
20
	protected NFConnector connector;
21
	
22
	/**
23
	 * This constructor forces the job to have a description and a connector instance.
24
	 * 
25
26
	 * @param connector The job will use this connector to synchronize itself with the nF.
	 * @param descriptor The description of this job.
27
	 */
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
	public Job(D descriptor, NFConnector connector) {
		this.descriptor = descriptor;
		this.connector = connector;
	}
	
	/**
	 * This constructor forces the job to have a id and a connector instance.
	 * 
	 * @param id The job id. If you call updateStatus() and the nF "knows" the job id, then the job status
	 * will be updated. If you call updateStatus() and the job id is "unkown" on the server side, then     
	 * @param connector The job will use this connector to synchronize itself with the nF.
	 */
	public Job(int id, NFConnector connector) {
		this.id = id;
		this.connector = connector;
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
	}
	
	/**
	 * 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;
	}
	
63
64
65
66
67
68
69
	/**
	 * @return Returns the description of this job.
	 */
	public D getDescriptor() {
		return descriptor;
	}
	
70
71
72
	/**
	 * @return Returns the id of this job.
	 */
73
74
	public int getId() {
		return id;
75
76
77
78
79
80
81
	}
	
	/**
	 * Sets the id of this job.
	 * 
	 * @param jobId The job id about to be set.
	 */
82
83
	public void setId(int jobId) {
		this.id = jobId;
84
85
	}
	
86
87
88
	/**
	 * @return Returns the nF connector of this job.
	 */
89
90
	public NFConnector getNFConnector() {
		return connector;
91
92
93
94
95
96
97
	}

	/**
	 * Sets the nF connector of this job.
	 * 
	 * @param nFConnector The connector of this job.
	 */
98
99
	public void setNFConnector(NFConnector nFConnector) {
		this.connector = nFConnector;
100
101
102
	}
	
	/**
103
104
105
106
107
108
109
110
111
112
113
114
115
116
	 * 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.
117
118
119
120
121
	 * 
	 * @throws FailedTransmissionException If the connection to the nF is broken you will get some of this. 
	 */
	public abstract void updateStatus() throws FailedTransmissionException;
	
122
123
124
125
126
127
128
129
130
131
	/**
	 * 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);
	
}