JobStatusEvent.java 2.33 KB
Newer Older
bruse's avatar
bruse committed
1
2
3
4
5
6
7
8
9
10
package eu.simstadt.nf4j.async;

import java.util.EventObject;
import java.util.Optional;

import eu.simstadt.nf4j.Job;
import eu.simstadt.nf4j.JobStatus;

/**
 * Every time when the status of a job progresses, one of this events will be created and sent
11
 * to all of the job status listeners registered at the job. Job status listeners implement
bruse's avatar
bruse committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
 * the jobStatusChanged() method which takes this JobStatusEvent as its argument. This event will
 * contain the job status as the event source and listener can read the source and decide how to
 * deal with the new status of its observed job.
 * 
 * Note, the job status, job and additional event messages will be referenced in extra object members of this event,
 * because the status of referenced job may change during the notification of the listeners. Therefore, obtaining
 * the job status directly from the job is not reliable, if the listener wants to know the actual source of this
 * event.   
 * 
 * @author Marcel Bruse
 */
public class JobStatusEvent extends EventObject {

	private static final long serialVersionUID = -1800246486543538087L;
	
	/** The job for which this event will be sent to the job status listeners. */
	private Job job;
	
	/** There might be an additional (error) message provided with the new job status. */
	private Optional<String> message;

	/**
	 * Constructor with job status as event source. The source can be read by the job status listeners.
	 * 
	 * @param source The new job status, which triggers this event.
	 */
	public JobStatusEvent(JobStatus source, Job job) {
		this(source, job, null);
	}
	
	/**
	 * Constructor with job status as event source and an additional (error) message. The source can be read
	 * by the job status listeners.
	 * 
	 * @param source The new job status, which triggers this event.
	 * @param message an additional (error) message for this event and job status.
	 */
	public JobStatusEvent(JobStatus source, Job job, Optional<String> message) {
		super(source);
		this.job = job;
		this.message = message;
	}
	
	/**
	 * @return Returns the job for which this event will be sent to the job status listeners.
	 */
	public Job getJob() {
		return job;
	}
	
	/**
	 * @return Returns an additional (error) message, if present.
	 */
	public Optional<String> getMessage() {
		return message;
	}

}