import jalview.workers.ConsensusThread;
import jalview.workers.InformationThread;
import jalview.workers.StrucConsensusThread;
-import jalview.ws2.WebServiceExecutor;
+import jalview.ws2.PollingTaskExecutor;
import java.awt.Color;
import java.beans.PropertyChangeSupport;
return false;
}
- private WebServiceExecutor wsExecutor = new WebServiceExecutor();
+ private PollingTaskExecutor wsExecutor = new PollingTaskExecutor();
- public WebServiceExecutor getWSExecutor()
+ public PollingTaskExecutor getWSExecutor()
{
return wsExecutor;
}
--- /dev/null
+package jalview.ws2;
+
+public interface PollableTaskI
+{
+ void start() throws Exception;
+
+ boolean poll() throws Exception;
+
+ boolean isDone();
+
+ void done();
+}
--- /dev/null
+package jalview.ws2;
+
+public interface PollableTaskListenerI
+{
+ public void submitted(PollableTaskI task);
+
+ public void submissionFailed(PollableTaskI task, Exception e);
+
+ public void pollFailed(PollableTaskI task, Exception e);
+
+ public void cancelled(PollableTaskI task);
+
+ public void done(PollableTaskI task);
+}
--- /dev/null
+package jalview.ws2;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import jalview.bin.Cache;
+
+public class PollingTaskExecutor
+{
+ private ScheduledExecutorService executor = Executors
+ .newSingleThreadScheduledExecutor();
+
+ public void submit(final PollableTaskI task)
+ {
+ executor.submit(() -> {
+ try
+ {
+ task.start();
+ wsThreadSupport.submitted(task);
+ } catch (Exception e)
+ {
+ Cache.log.error("Failed to submit web service jobs.", e);
+ wsThreadSupport.submissionFailed(task, e);
+ return;
+ }
+ executor.schedule(() -> poll(task), 1, TimeUnit.SECONDS);
+ });
+ }
+
+ private void poll(PollableTaskI task)
+ {
+ boolean done;
+ try
+ {
+ done = task.poll();
+ } catch (Exception e)
+ {
+ Cache.log.error("Failed to poll task.", e);
+ wsThreadSupport.pollFailed(task, e);
+ return;
+ }
+ if (!done)
+ {
+ executor.schedule(() -> poll(task), 1, TimeUnit.SECONDS);
+ }
+ else
+ {
+ task.done();
+ wsThreadSupport.done(task);
+ }
+ }
+
+ private WebServiceThreadSupport wsThreadSupport = new WebServiceThreadSupport();
+
+ public void addThreadListener(PollableTaskListenerI listener)
+ {
+ wsThreadSupport.addListener(listener);
+ }
+
+ public void removeThreadListener(PollableTaskListenerI listener)
+ {
+ wsThreadSupport.removeListener(listener);
+ }
+
+ public void shutdown()
+ {
+ executor.shutdownNow();
+ }
+
+}
+
+class WebServiceThreadSupport implements PollableTaskListenerI
+{
+ List<PollableTaskListenerI> listeners = new CopyOnWriteArrayList<>();
+
+ @Override
+ public void submitted(PollableTaskI task)
+ {
+ for (var listener : listeners)
+ listener.submitted(task);
+ }
+
+ @Override
+ public void submissionFailed(PollableTaskI task, Exception e)
+ {
+ for (var listener : listeners)
+ listener.submissionFailed(task, e);
+ }
+
+ @Override
+ public void pollFailed(PollableTaskI task, Exception e)
+ {
+ for (var listener : listeners)
+ listener.pollFailed(task, e);
+ }
+
+ @Override
+ public void cancelled(PollableTaskI task)
+ {
+ for (var listener : listeners)
+ listener.cancelled(task);
+ }
+
+ @Override
+ public void done(PollableTaskI task)
+ {
+ for (var listener : listeners)
+ listener.done(task);
+ }
+
+ public void addListener(PollableTaskListenerI listener)
+ {
+ if (!listeners.contains(listener))
+ {
+ listeners.add(listener);
+ }
+ }
+
+ public void removeListener(PollableTaskListenerI listener)
+ {
+ listeners.remove(listener);
+ }
+}
+++ /dev/null
-package jalview.ws2;
-
-import java.io.IOException;
-import java.util.EventObject;
-import java.util.List;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-
-import jalview.bin.Cache;
-
-public class WebServiceExecutor
-{
- private ScheduledExecutorService executor = Executors
- .newSingleThreadScheduledExecutor();
-
- public void submit(final WebServiceWorkerI worker)
- {
- executor.submit(() -> {
- try
- {
- worker.startJobs();
- wsThreadSupport.submitted(worker);
- } catch (Exception e)
- {
- Cache.log.error("Failed to submit web service jobs.", e);
- wsThreadSupport.submissionFailed(worker, e);
- return;
- }
- executor.schedule(() -> pollJobs(worker), 1, TimeUnit.SECONDS);
- });
- }
-
- private void pollJobs(WebServiceWorkerI worker)
- {
- boolean done;
- try
- {
- done = worker.pollJobs();
- } catch (Exception e)
- {
- Cache.log.error("Failed to poll web service jobs.", e);
- for (WSJob job : worker.getJobs())
- {
- job.setStatus(WSJobStatus.SERVER_ERROR);
- }
- wsThreadSupport.pollFailed(worker, e);
- return;
- }
- if (!done)
- {
- executor.schedule(() -> pollJobs(worker), 1, TimeUnit.SECONDS);
- }
- else
- {
- worker.done();
- wsThreadSupport.done(worker);
- }
- }
-
- private WebServiceThreadSupport wsThreadSupport = new WebServiceThreadSupport();
-
- public void addThreadListener(WebServiceThreadListenerI listener)
- {
- wsThreadSupport.addListener(listener);
- }
-
- public void removeThreadListener(WebServiceThreadListenerI listener)
- {
- wsThreadSupport.removeListener(listener);
- }
-
- public void shutdown()
- {
- executor.shutdownNow();
- }
-
-}
-
-class WebServiceThreadSupport implements WebServiceThreadListenerI
-{
- List<WebServiceThreadListenerI> listeners = new CopyOnWriteArrayList<>();
-
- @Override
- public void submitted(WebServiceWorkerI thread)
- {
- for (var listener : listeners)
- listener.submitted(thread);
- }
-
- @Override
- public void submissionFailed(WebServiceWorkerI thread, Exception e)
- {
- for (var listener : listeners)
- listener.submissionFailed(thread, e);
- }
-
- @Override
- public void pollFailed(WebServiceWorkerI thread, Exception e)
- {
- for (var listener : listeners)
- listener.pollFailed(thread, e);
- }
-
- @Override
- public void cancelled(WebServiceWorkerI thread)
- {
- for (var listener : listeners)
- listener.cancelled(thread);
- }
-
- @Override
- public void done(WebServiceWorkerI thread)
- {
- for (var listener : listeners)
- listener.done(thread);
- }
-
- public void addListener(WebServiceThreadListenerI listener)
- {
- if (!listeners.contains(listener))
- {
- listeners.add(listener);
- }
- }
-
- public void removeListener(WebServiceThreadListenerI listener)
- {
- listeners.remove(listener);
- }
-}
+++ /dev/null
-package jalview.ws2;
-
-public interface WebServiceThreadListenerI
-{
- public void submitted(WebServiceWorkerI thread);
-
- public void submissionFailed(WebServiceWorkerI thread, Exception e);
-
- public void pollFailed(WebServiceWorkerI thread, Exception e);
-
- public void cancelled(WebServiceWorkerI thread);
-
- public void done(WebServiceWorkerI thread);
-}
\ No newline at end of file
import java.io.IOException;
import java.util.List;
-import javax.print.attribute.standard.JobState;
-
-import jalview.util.MathUtils;
-
-public interface WebServiceWorkerI
+public interface WebServiceWorkerI extends PollableTaskI
{
long getUID();
List<WSJob> getJobs();
- void startJobs() throws IOException;
+ void start() throws IOException;
- boolean pollJobs() throws IOException;
+ boolean poll() throws IOException;
WebServiceI getWebService();
import jalview.ws2.ResultSupplier;
import jalview.ws2.WSJob;
import jalview.ws2.WSJobStatus;
-import jalview.ws2.WebServiceExecutor;
+import jalview.ws2.PollingTaskExecutor;
import jalview.ws2.WebServiceI;
import jalview.ws2.WebServiceInfoUpdater;
import jalview.ws2.WebServiceWorkerI;
final var calcName = service.getName();
String title = frame.getTitle();
- WebServiceExecutor executor = frame.getViewport().getWSExecutor();
+ PollingTaskExecutor executor = frame.getViewport().getWSExecutor();
{
var item = new JMenuItem(MessageManager.formatMessage(
"label.calcname_with_default_settings", calcName));
}
@Override
- public void startJobs() throws IOException
+ public void start() throws IOException
{
Cache.log.info(format("Starting new %s job.", service.getName()));
String outputHeader = String.format("%s of %s%nJob details%n",
}
@Override
- public boolean pollJobs()
+ public boolean poll()
{
boolean done = true;
for (WSJob job : getJobs())
import jalview.ws2.ResultSupplier;
import jalview.ws2.WSJob;
import jalview.ws2.WSJobStatus;
-import jalview.ws2.WebServiceExecutor;
+import jalview.ws2.PollingTaskExecutor;
import jalview.ws2.WebServiceI;
import jalview.ws2.WebServiceWorkerI;
import jalview.ws2.utils.WSJobList;
protected void buildMenu(JMenu parent, AlignFrame frame)
{
final var calcName = service.getName();
- WebServiceExecutor wsExecutor = frame.getViewport().getWSExecutor();
+ PollingTaskExecutor wsExecutor = frame.getViewport().getWSExecutor();
{
var item = new JMenuItem(MessageManager.formatMessage(
"label.calcname_with_default_settings", calcName));
}
@Override
- public void startJobs() throws IOException
+ public void start() throws IOException
{
}
@Override
- public boolean pollJobs() throws IOException
+ public boolean poll() throws IOException
{
boolean done = true;
for (WSJob job : getJobs())