1 package jalview.ws2.actions.api;
5 import jalview.bin.Console;
6 import jalview.ws2.api.JobStatus;
7 import jalview.ws2.api.WebServiceJobHandle;
10 * The listener interface for receiving relevant job progress and state change
11 * events on the task. The listener object is registered with the task on its
12 * creation in {@link ActionI#perform} method. An event is generated when the
13 * task is started, restarted, completed, fails with an exception or its global
14 * status changes. Additional, sub-job related, events are emitted when the
15 * sub-job status, log or error log changes.
21 public interface TaskEventListener<T>
24 * Invoked when the task has been started. The {@code subJobs} parameter
25 * contains a complete list of sub-jobs for that run. Note that restartable
26 * tasks may invoke this method multiple times with different set of sub-jobs.
29 * task this event originates from
31 * list of sub-jobs for this run
33 default void taskStarted(TaskI<T> source, List<? extends JobI> subJobs) {};
36 * Invoked when the global task status has changed.
39 * task this event originates from
43 default void taskStatusChanged(TaskI<T> source, JobStatus status) {};
46 * Invoked when the task has completed. If the task completed with a result,
47 * that result is passed in the call argument, otherwise, a {@code null} value
51 * task this event originates from
53 * computation result or null if result not present
55 default void taskCompleted(TaskI<T> source, T result) {};
58 * Invoked when an unhandled exception has occurred during task execution.
61 * task this event originates from
65 default void taskException(TaskI<T> source, Exception e) {};
68 * Invoked when the status of a sub-job has changed.
71 * task this event originates form
73 * sub-job that has been updated
77 default void subJobStatusChanged(TaskI<T> source, JobI job, JobStatus status) {};
80 * Invoked when a log string of the sub-job has changed.
83 * task this event originates form
85 * sub-job that has been updated
89 default void subJobLogChanged(TaskI<T> source, JobI job, String log) {};
92 * Invoked when an error log string of the sub-job has changed.
95 * task this event originates form
97 * sub-job that has been updated
101 default void subJobErrorLogChanged(TaskI<T> source, JobI job, String log) {};
103 @SuppressWarnings("rawtypes")
104 static final TaskEventListener NULL_LISTENER = new TaskEventListener()
107 public void taskStarted(TaskI source, List subJobs)
109 Console.info("task started with " + subJobs.size() + " jobs");
113 public void taskStatusChanged(TaskI source, JobStatus status)
115 Console.info("task status " + status);
119 public void taskCompleted(TaskI source, Object result)
121 Console.info("task completed");
125 public void taskException(TaskI source, Exception e)
127 Console.info("task failed", e);
131 public void subJobStatusChanged(TaskI source, JobI job,
134 Console.info("sub-job " + job.getInternalId() + " status " + status);
138 public void subJobLogChanged(TaskI source, JobI job, String log)
143 public void subJobErrorLogChanged(TaskI source, JobI job, String log)
148 @SuppressWarnings("unchecked")
149 static <T> TaskEventListener<T> nullListener()
151 return (TaskEventListener<T>) NULL_LISTENER;