AsyncJob.java 2.94 KB
Newer Older
bruse's avatar
bruse committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package eu.simstadt.nf4j.async;

import eu.simstadt.nf4j.FailedTransmissionException;

/**
 * An asynchronous job will be sent in a non-blocking fashion, so that the main thread can proceed after calling
 * the send() operation. It queries the status of its remote nF counterpart frequently in a separate thread, so that
 * the job operations don't have to wait. Every asynchronous job should maintain a list of job status listeners.
 * Every registered job status listener should be notified upon significant and new job status changes. 
 * 
 * @author Marcel Bruse
 */
public interface AsyncJob {

	/**
	 * Frequently queries the remote status of the nF export job and updates the local status accordingly.
	 * The queries will be performed asynchronously in a separate thread. Job status listener will be notified
	 * upon every new status change.
19
20
21
	 * 
	 * @param interval Amount of seconds to wait before the next status update request will be sent to the
	 * nF server.
bruse's avatar
bruse committed
22
23
24
	 *  
	 * @throws FailedTransmissionException If your job has not been sent yet, then you will get some of this. 
	 */
25
	public void poll(int interval) throws FailedTransmissionException;
bruse's avatar
bruse committed
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
	
	/**
	 * Cancels all ongoing asynchronous operations of this job as soon as possible. Operations to be canceled
	 * might be send, poll and download operations. 
	 */
	public void cancel();
	
	/**
	 * Registers a job status listener at this job. The listener will then be notified upon job status changes.
	 *   
	 * @param jobListener The job status listener to be registered at this job.
	 */
	public void addJobStatusListener(JobStatusListener jobListener);
	
	/**
	 * Unregisters a job status listener for this job. The listener will not be notified about job status changes
	 * anymore.
	 * 
	 * @param jobListener The job status listener to be unregistered.
	 */
	public void removeJobStatusListener(JobStatusListener jobListener);
	
	/**
	 * Once the status of this job changes, all registered job status listeners will be notified.
	 */
	public void notifyJobStatusListeners();
	
	/**
	 * Convenience method.
	 * 
	 * @return Returns true, if the job is definitely done.
	 */
	public boolean hasFinished();
	
	/**
	 * Convenience method.
	 * 
	 * @return Returns true, if the job was unable to recover from a serious problem.
	 */
	public boolean hasFailed();

	/**
	 * Asynchronous polling tasks may query this flag frequently in order to decide to proceed or not.
	 * 
	 * @return Returns true, if the polling task should continue polling for status updates.
	 */
	public boolean keepPolling();
	
	/**
	 * Calls updateStatus() for you, since updateStatus() is a protected method. This method is used by the
	 * asynchronous PollJobStatusTask class.
	 * 
	 * @throws FailedTransmissionException If something goes wrong during the update process, you will get some
	 * of this.  
	 */
	public void triggerStatusUpdate() throws FailedTransmissionException;
	
}