Author: mes
Date: 2011-01-21 10:31:57 -0800 (Fri, 21 Jan 2011)
New Revision: 23540
Modified:
core3/work-swing-impl/trunk/impl/src/main/java/org/cytoscape/work/internal/task/SwingTaskManager.java
core3/work-swing-impl/trunk/impl/src/main/java/org/cytoscape/work/internal/task/SwingTaskMonitor.java
Log:
cleaned things up and removed executeAndWait concept
Modified:
core3/work-swing-impl/trunk/impl/src/main/java/org/cytoscape/work/internal/task/SwingTaskManager.java
===================================================================
---
core3/work-swing-impl/trunk/impl/src/main/java/org/cytoscape/work/internal/task/SwingTaskManager.java
2011-01-21 18:31:28 UTC (rev 23539)
+++
core3/work-swing-impl/trunk/impl/src/main/java/org/cytoscape/work/internal/task/SwingTaskManager.java
2011-01-21 18:31:57 UTC (rev 23540)
@@ -10,6 +10,7 @@
import java.util.concurrent.TimeUnit;
import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
import org.cytoscape.work.AbstractTaskManager;
import org.cytoscape.work.Task;
@@ -123,7 +124,7 @@
}
@Override
- protected void execute(final TaskFactory factory, boolean wait) {
+ public void execute(final TaskFactory factory) {
final SwingTaskMonitor taskMonitor = new
SwingTaskMonitor(cancelExecutorService, parent);
TaskIterator taskIterator;
@@ -135,7 +136,7 @@
throw new IllegalArgumentException("Tunables
are not valid");
taskIterator = factory.getTaskIterator();
-
+
// Get the first task and display its tunables. This
is a bit of a hack.
// We do this outside of the thread so that the task
monitor only gets
// displayed AFTER the first tunables dialog gets
displayed.
@@ -153,41 +154,25 @@
// create the task thread
final Runnable tasks = new TaskThread(first, taskMonitor,
taskIterator);
- long startTime = System.currentTimeMillis();
// submit the task thread for execution
final Future<?> executorFuture =
taskExecutorService.submit(tasks);
openTaskMonitorOnDelay(taskMonitor, executorFuture);
-
- if(wait) {
- try {
- executorFuture.get();
- long endTime = System.currentTimeMillis();
- double sec = (endTime - startTime) / (1000.0);
- System.out.println("Wait Task Finished in " +
sec + " sec.");
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- executorFuture.cancel(true);
- taskExecutorService.shutdown();
- timedDialogExecutorService.shutdown();
- taskMonitor.close();
- }
- }
- }
+ }
// This creates a thread on delay that conditionally displays the task
monitor gui
// if the task thread has not yet finished.
- private void openTaskMonitorOnDelay(final SwingTaskMonitor taskMonitor,
final Future<?> executorFuture) {
+ private void openTaskMonitorOnDelay(final SwingTaskMonitor taskMonitor,
+ final Future<?> executorFuture) {
final Runnable timedOpen = new Runnable() {
-
public void run() {
if (!(executorFuture.isDone() ||
executorFuture.isCancelled())) {
+ taskMonitor.setFuture(executorFuture);
taskMonitor.open();
}
}
};
-
+
timedDialogExecutorService.schedule(timedOpen,
DELAY_BEFORE_SHOWING_DIALOG, DELAY_TIMEUNIT);
}
@@ -196,7 +181,7 @@
private final SwingTaskMonitor taskMonitor;
private final TaskIterator taskIterator;
private final Task first;
-
+
TaskThread(final Task first, final SwingTaskMonitor tm, final
TaskIterator ti) {
this.first = first;
this.taskMonitor = tm;
@@ -207,6 +192,7 @@
try {
// actually run the first task
// don't dispaly the tunables here - they were
handled above.
+ taskMonitor.setTask(first);
first.run(taskMonitor);
if (taskMonitor.cancelled())
@@ -215,6 +201,7 @@
// now execute all subsequent tasks
while (taskIterator.hasNext()) {
final Task task = taskIterator.next();
+ taskMonitor.setTask(task);
if (!displayTunables(task))
return;
@@ -223,20 +210,20 @@
if (taskMonitor.cancelled())
break;
- }
+ }
} catch (Exception exception) {
- logger.warn("Caught exception executing task.
", exception);
+ logger.warn("Caught exception executing task.
", exception);
taskMonitor.showException(exception);
}
-
+
// clean up the task monitor
if (taskMonitor.isOpened() &&
!taskMonitor.isShowingException())
taskMonitor.close();
-
+
}
}
- private boolean displayTunables(final Task task) {
+ private boolean displayTunables(final Task task) throws Exception {
if (tunableInterceptor == null)
return true;
@@ -250,7 +237,7 @@
@Override
public JPanel getConfigurationPanel(final TaskFactory taskFactory) {
tunableInterceptor.loadTunables(taskFactory);
- return
((GUITunableInterceptor)tunableInterceptor).getUI(taskFactory);
+ return
((GUITunableInterceptor)tunableInterceptor).getUI(taskFactory);
}
}
Modified:
core3/work-swing-impl/trunk/impl/src/main/java/org/cytoscape/work/internal/task/SwingTaskMonitor.java
===================================================================
---
core3/work-swing-impl/trunk/impl/src/main/java/org/cytoscape/work/internal/task/SwingTaskMonitor.java
2011-01-21 18:31:28 UTC (rev 23539)
+++
core3/work-swing-impl/trunk/impl/src/main/java/org/cytoscape/work/internal/task/SwingTaskMonitor.java
2011-01-21 18:31:57 UTC (rev 23540)
@@ -3,6 +3,7 @@
import java.awt.Window;
import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
import org.cytoscape.work.Task;
import org.cytoscape.work.TaskMonitor;
@@ -19,6 +20,7 @@
private String title = null;
private String statusMessage = null;
private int progress = 0;
+ private Future<?> future = null;
public SwingTaskMonitor(final ExecutorService cancelExecutorService,
final Window parent) {
this.cancelExecutorService = cancelExecutorService;
@@ -29,6 +31,10 @@
this.task = newTask;
}
+ public void setFuture(final Future<?> future) {
+ this.future = future;
+ }
+
public synchronized void open() {
if (dialog != null)
return;
@@ -61,6 +67,9 @@
Runnable cancel = new Runnable() {
public void run() {
task.cancel();
+ try { Thread.sleep(1000); } catch (Exception e)
{}
+ if ( future != null && !future.isDone() &&
!future.isCancelled() )
+ future.cancel(true);
}
};
cancelExecutorService.submit(cancel);
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.