import jalview.bin.Cache;
+/**
+ * An object that executes submitted {@link PollableTaskI} tasks using
+ * {@link SchedulekExecutorservice}. The task is first started using its
+ * {@link PollableTaskI#start} method and then repeatedly polled every second
+ * with {@link PollableTaskI#poll}.
+ *
+ * The {@link PollingTaskExecutor} automates the process of running tasks and
+ * provides convenient interface to listen to events associated with task
+ * execution.
+ *
+ * @author mmwarowny
+ *
+ */
public class PollingTaskExecutor
{
private ScheduledExecutorService executor = Executors
- .newSingleThreadScheduledExecutor();
-
+ .newSingleThreadScheduledExecutor();
+
+ /**
+ * Submit the task for execution. Calls task's {@code start} method and, if
+ * started successfully, schedules next poll after one second.
+ *
+ * @param task
+ * task to submit
+ */
public void submit(final PollableTaskI task)
{
executor.submit(() -> {
});
}
+ /**
+ * Poll the task by calling it's {@code poll} method. If not finished, the
+ * next poll is scheduled to happen after one second, otherwise task's
+ * {@code done} method is called immediately.
+ *
+ * @param task
+ * task to poll
+ */
private void poll(PollableTaskI task)
{
boolean done;
private WebServiceThreadSupport wsThreadSupport = new WebServiceThreadSupport();
+ /**
+ * Add listener of the task related events.
+ *
+ * @param listener
+ * listener to add
+ */
public void addThreadListener(PollableTaskListenerI listener)
{
wsThreadSupport.addListener(listener);
}
+ /**
+ * @param listener
+ * listener to be removed
+ */
public void removeThreadListener(PollableTaskListenerI listener)
{
wsThreadSupport.removeListener(listener);