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 * to all of the job status listeners registered at the job. Job status listeners implement * 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 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 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 getMessage() { return message; } }