Author: mes
Date: 2011-11-01 17:19:51 -0700 (Tue, 01 Nov 2011)
New Revision: 27372
Removed:
core3/api/trunk/work-api/src/main/java/org/cytoscape/work/ValuedTask.java
core3/api/trunk/work-api/src/main/java/org/cytoscape/work/ValuedTaskExecutor.java
core3/api/trunk/work-api/src/test/java/org/cytoscape/work/ValuedTaskExecutorTest.java
core3/support/trunk/task-testing-impl/src/main/java/org/cytoscape/internal/test/WaitValueAction.java
Modified:
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/creation/NewEmptyNetworkTaskFactory.java
Log:
Removed ValuedTask and ValuedTaskExecutor. We could add it back in the future,
but for now it seems easier to use SynchronousTaskManager.
Deleted:
core3/api/trunk/work-api/src/main/java/org/cytoscape/work/ValuedTask.java
===================================================================
--- core3/api/trunk/work-api/src/main/java/org/cytoscape/work/ValuedTask.java
2011-11-02 00:19:17 UTC (rev 27371)
+++ core3/api/trunk/work-api/src/main/java/org/cytoscape/work/ValuedTask.java
2011-11-02 00:19:51 UTC (rev 27372)
@@ -1,54 +0,0 @@
-package org.cytoscape.work;
-
-/**
- * Describes a unit of work that produces a result asynchronously.
- * This interface is identical to <code>Task</code>, except it allows
- * <code>run</code> to return a result. This interface is analogous to
- * <code>java.util.concurrency.Future</code>.
- *
- * Because a <code>ValuedTask</code> cannot be executed by a
- * <code>TaskManager</code>, an instance of this interface is typically wrapped
- * by an instance of <code>ValuedTaskExecutor</code> in order to be
- * executed by a <code>TaskManager</code>.
- *
- * @author Pasteur
- * @param <V> The generic type of this ValuedTask.
- */
-public interface ValuedTask<V> {
- /**
- * This method contains the action of the <code>ValuedTask</code>.
- *
- * This method should not be called by the programmer,
- * since it will be called by the <code>TaskManager</code>.
- *
- * @return a useful result to be retrieved by another thread
- * after the execution of this <code>ValuedTask</code> has completed.
- *
- * @param taskMonitor This is provided by <code>TaskManager</code>
- * to allow the <code>ValuedTask</code> to modify its user interface.
- *
- * @throws Exception The <code>ValuedTask</code> is at liberty to
- * throw an exception. The exception is
- * caught by <code>TaskManager</code> and the information contained
- * by the exception is displayed in the interface.
- */
- V run(TaskMonitor taskMonitor) throws Exception;
-
- /**
- * This method is called when the user chooses to cancel the
- * <code>Task</code>.
- *
- * This method should not be called by the programmer,
- * since it will be called by the <code>TaskManager</code>.
- *
- * <p>This method should inform the <code>run</code> method that it must
- * terminate execution cleanly and do any necessary cleanup
- * work required.</p>
- *
- * <p><i>WARNING:</i> this method is called by a different
- * thread than the thread executing <code>run</code>.
- * The programmer <i>must</i> be aware of
- * concurrency issues.</p>
- */
- void cancel();
-}
Deleted:
core3/api/trunk/work-api/src/main/java/org/cytoscape/work/ValuedTaskExecutor.java
===================================================================
---
core3/api/trunk/work-api/src/main/java/org/cytoscape/work/ValuedTaskExecutor.java
2011-11-02 00:19:17 UTC (rev 27371)
+++
core3/api/trunk/work-api/src/main/java/org/cytoscape/work/ValuedTaskExecutor.java
2011-11-02 00:19:51 UTC (rev 27372)
@@ -1,175 +0,0 @@
-package org.cytoscape.work;
-
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.CancellationException;
-import java.util.concurrent.TimeoutException;
-
-/**
- * A class for wrapping <code>ValuedTask</code>s so they can be executed
- * by a <code>TaskManager</code>.
- * This class is analogous to <code>java.util.concurrency.FutureTask</code>.
- *
- * @author Pasteur
- * @param <V> The Generic type of this ValuedTaskExecutor.
- */
-public final class ValuedTaskExecutor<V> implements Task {
-
- /**
- * Describes the state the <code>ValuedTask</code> is in.
- */
- private enum State {
- /**
- * The <code>ValuedTask</code> has been created
- * and is ready to be executed, but the
- * <code>run</code> method has not yet been called.
- *
- * This is the default state of the
- * <code>ValuedTaskExecutor</code> when it is created.
- */
- READY,
-
- /**
- * The <code>ValuedTask</code>'s
- * <code>run</code> method is currently
- * being executed.
- */
- RUNNING,
-
- /**
- * The <code>ValuedTask</code> has finished execution,
- * where the <code>run</code> method has finished and
- * returned a result.
- */
- COMPLETED,
-
- /**
- * The <code>ValuedTask</code>'s <code>run</code> method
- * did not complete because the user cancelled the
- * <code>ValuedTask</code>.
- */
- CANCELLED,
-
- /**
- * The <code>ValuedTask</code>'s <code>run</code> method
- * did not complete because it threw an exception.
- */
- EXCEPTION_THROWN;
- }
-
- private final ValuedTask<V> valuedTask;
-
- private V result = null;
- private State state = State.READY;
- private Exception exception = null;
-
- /**
- * Constructs this ValuedTaskExecutor.
- * @param valuedTask the {@link ValuedTask} to wrap.
- */
- public ValuedTaskExecutor(ValuedTask<V> valuedTask) {
- if ( valuedTask == null )
- throw new NullPointerException("The task specified is
null");
- this.valuedTask = valuedTask;
- }
-
- /**
- * This method will be called by the <code>TaskManager</code> and
- * should not be called by the programmer.
- */
- public void run(TaskMonitor taskMonitor) throws Exception {
- state = State.RUNNING;
- try {
- result = valuedTask.run(taskMonitor);
- if (state == State.RUNNING)
- state = State.COMPLETED;
- } catch (Exception exception) {
- this.exception = exception;
- state = State.EXCEPTION_THROWN;
- throw exception;
- } finally {
- synchronized(this) {
- this.notifyAll();
- }
- }
- }
-
- /**
- * This method might be called by the <code>TaskManager</code> and
- * should not be called by the programmer.
- */
- public void cancel() {
- state = State.CANCELLED;
- valuedTask.cancel();
- }
-
- /**
- * Retrieves the result produced by the <code>ValuedTask</code> if it
- * has finished execution, otherwise it waits until it
- * finishes execution.
- *
- * This method will block until the <code>ValuedTask</code> has
- * finished--that is, its state is no longer
- * <code>READY</code> or <code>RUNNING</code>.
- *
- * @return The result of the <code>ValuedTask</code>.
- *
- * @throws InterruptedException if the current thread was interrupted
- * while waiting for the result
- * @throws ExecutionException if the <code>ValueTask</code> threw an
- * exception
- * @throws CancellationException if the user cancelled the
- * <code>ValueTask</code>
- */
- public V get() throws InterruptedException, ExecutionException,
CancellationException {
- if (state == State.READY || state == State.RUNNING) {
- synchronized(this) {
- this.wait();
- }
- }
-
- if (state == State.CANCELLED)
- throw new CancellationException();
- else if (state == State.EXCEPTION_THROWN)
- throw new ExecutionException(exception);
-
- return result;
- }
-
- /**
- * Retrieves the result produced by the <code>ValuedTask</code> if it
- * has finished execution, otherwise it waits a specified amount of
- * time to finish execution.
- *
- * This method will block until the <code>ValuedTask</code> has
- * finished--that is, its state is no longer
- * <code>READY</code> or <code>RUNNING</code>--or the specified
- * wait has timed out.
- *
- * @return The result of the <code>ValuedTask</code>.
- *
- * @throws InterruptedException if the current thread was interrupted
- * while waiting
- * @throws ExecutionException if the <code>ValueTask</code> threw an
- * exception
- * @throws CancellationException if the user canceled the
- * <code>ValueTask</code>
- * @throws TimeoutException if the wait period specified timed out
- */
- public V get(long timeout, TimeUnit unit)
- throws InterruptedException, ExecutionException,
CancellationException, TimeoutException {
-
- if (state == State.READY || state == State.RUNNING) {
- synchronized(this) {
- unit.timedWait(this, timeout);
- }
- }
-
- if (state == State.CANCELLED)
- throw new CancellationException();
- else if (state == State.EXCEPTION_THROWN)
- throw new ExecutionException(exception);
-
- return result;
- }
-}
Deleted:
core3/api/trunk/work-api/src/test/java/org/cytoscape/work/ValuedTaskExecutorTest.java
===================================================================
---
core3/api/trunk/work-api/src/test/java/org/cytoscape/work/ValuedTaskExecutorTest.java
2011-11-02 00:19:17 UTC (rev 27371)
+++
core3/api/trunk/work-api/src/test/java/org/cytoscape/work/ValuedTaskExecutorTest.java
2011-11-02 00:19:51 UTC (rev 27372)
@@ -1,144 +0,0 @@
-/*
- Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
-
- This library is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2.1 of the License, or
- any later version.
-
- This library is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
- MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
- documentation provided hereunder is on an "as is" basis, and the
- Institute for Systems Biology and the Whitehead Institute
- have no obligations to provide maintenance, support,
- updates, enhancements or modifications. In no event shall the
- Institute for Systems Biology and the Whitehead Institute
- be liable to any party for direct, indirect, special,
- incidental or consequential damages, including lost profits, arising
- out of the use of this software and its documentation, even if the
- Institute for Systems Biology and the Whitehead Institute
- have been advised of the possibility of such damage. See
- the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with this library; if not, write to the Free Software Foundation,
- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-*/
-package org.cytoscape.work;
-
-
-import static org.junit.Assert.*;
-import org.junit.Before;
-import org.junit.Test;
-import static org.mockito.Mockito.*;
-
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.CancellationException;
-import java.util.concurrent.ExecutionException;
-
-
-public class ValuedTaskExecutorTest {
-
- private TaskMonitor tm = mock(TaskMonitor.class);
-
- @Test
- public void testSuccessfulRun() throws Exception {
- ValuedTask<String> t = new StringValuedTask("homer");
- ValuedTaskExecutor<String> vte = new
ValuedTaskExecutor<String>(t);
- vte.run(tm);
- assertEquals("homer",vte.get());
- }
-
- @Test(expected=Exception.class)
- public void testExceptionRun() throws Exception {
- ValuedTask<String> t = new ExceptionValuedTask("homer");
- ValuedTaskExecutor<String> vte = new
ValuedTaskExecutor<String>(t);
- vte.run(tm);
- }
-
- @Test(expected=ExecutionException.class)
- public void testExceptionRunInThread() throws Exception {
- ValuedTask<String> t = new ExceptionValuedTask("homer");
- ValuedTaskExecutor<String> vte = new
ValuedTaskExecutor<String>(t);
- new Thread( new TaskRunner(vte) ).start();
- String s = vte.get();
- }
-
- @Test(expected=ExecutionException.class)
- public void testExceptionRunInThreadAltGet() throws Exception {
- ValuedTask<String> t = new ExceptionValuedTask("homer");
- ValuedTaskExecutor<String> vte = new
ValuedTaskExecutor<String>(t);
- new Thread( new TaskRunner(vte) ).start();
- String s = vte.get(100,TimeUnit.MILLISECONDS);
- }
-
-
- @Test(expected=NullPointerException.class)
- public void testNullValuedTask() throws Exception {
- ValuedTaskExecutor<String> vte = new
ValuedTaskExecutor<String>(null);
- }
-
- @Test
- public void testTimeoutSuccessRun() throws Exception {
- ValuedTask<String> t = new SlowValuedTask("homer");
- ValuedTaskExecutor<String> vte = new
ValuedTaskExecutor<String>(t);
- new Thread( new TaskRunner(vte) ).start();
- assertEquals("homer",vte.get(600,TimeUnit.MILLISECONDS));
- }
-
- @Test
- public void testTimeoutFailureRun() throws Exception {
- ValuedTask<String> t = new SlowValuedTask("homer");
- ValuedTaskExecutor<String> vte = new
ValuedTaskExecutor<String>(t);
- new Thread( new TaskRunner(vte) ).start();
- assertNull(vte.get(300,TimeUnit.MILLISECONDS));
- }
-
- @Test(expected=CancellationException.class)
- public void testCancelRun() throws Exception {
- ValuedTask<String> t = new SlowValuedTask("homer");
- ValuedTaskExecutor<String> vte = new
ValuedTaskExecutor<String>(t);
- new Thread( new TaskRunner(vte) ).start();
- vte.cancel();
- String s = vte.get();
- }
-
- @Test(expected=CancellationException.class)
- public void testCancelRunAltGet() throws Exception {
- ValuedTask<String> t = new SlowValuedTask("homer");
- ValuedTaskExecutor<String> vte = new
ValuedTaskExecutor<String>(t);
- new Thread( new TaskRunner(vte) ).start();
- vte.cancel();
- String s = vte.get(100,TimeUnit.MILLISECONDS);
- }
-
- private class TaskRunner implements Runnable {
- private Task task;
- TaskRunner(Task task) { this.task = task; }
- public void run() { try { task.run(tm); } catch (Exception e) {
} }
- }
-
- private class StringValuedTask implements ValuedTask<String> {
- private String s;
- public StringValuedTask(String s) { this.s = s; }
- public String run(TaskMonitor tm) { return s; }
- public void cancel() {}
- }
-
- private class ExceptionValuedTask implements ValuedTask<String> {
- public ExceptionValuedTask(String s) { }
- public String run(TaskMonitor tm) throws Exception { throw new
Exception("test"); }
- public void cancel() {}
- }
-
- private class SlowValuedTask implements ValuedTask<String> {
- private String s;
- public SlowValuedTask(String s) { this.s = s; }
- public String run(TaskMonitor tm) throws Exception {
- Thread.sleep(500);
- return s;
- }
- public void cancel() {}
- }
-}
Modified:
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/creation/NewEmptyNetworkTaskFactory.java
===================================================================
---
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/creation/NewEmptyNetworkTaskFactory.java
2011-11-02 00:19:17 UTC (rev 27371)
+++
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/creation/NewEmptyNetworkTaskFactory.java
2011-11-02 00:19:51 UTC (rev 27372)
@@ -33,7 +33,6 @@
import org.cytoscape.work.TaskFactory;
import org.cytoscape.work.TaskIterator;
import org.cytoscape.work.SynchronousTaskManager;
-import org.cytoscape.work.ValuedTaskExecutor;
import org.cytoscape.model.CyNetworkFactory;
import org.cytoscape.view.model.CyNetworkViewFactory;
import org.cytoscape.view.model.CyNetworkViewManager;
@@ -49,7 +48,6 @@
private final CyNetworkNaming namingUtil;
private final SynchronousTaskManager syncTaskMgr;
- private ValuedTaskExecutor<CyNetworkView> resultHolder;
private NewEmptyNetworkTask task;
public NewEmptyNetworkTaskFactory(final CyNetworkFactory cnf, final
CyNetworkViewFactory cnvf, final CyNetworkManager netmgr, final
CyNetworkViewManager networkViewManager, final CyNetworkNaming namingUtil,
final SynchronousTaskManager syncTaskMgr)
Deleted:
core3/support/trunk/task-testing-impl/src/main/java/org/cytoscape/internal/test/WaitValueAction.java
===================================================================
---
core3/support/trunk/task-testing-impl/src/main/java/org/cytoscape/internal/test/WaitValueAction.java
2011-11-02 00:19:17 UTC (rev 27371)
+++
core3/support/trunk/task-testing-impl/src/main/java/org/cytoscape/internal/test/WaitValueAction.java
2011-11-02 00:19:51 UTC (rev 27372)
@@ -1,103 +0,0 @@
-/*
- Copyright (c) 2006, The Cytoscape Consortium (www.cytoscape.org)
-
- The Cytoscape Consortium is:
- - Institute for Systems Biology
- - University of California San Diego
- - Memorial Sloan-Kettering Cancer Center
- - Institut Pasteur
- - Agilent Technologies
-
- This library is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2.1 of the License, or
- any later version.
-
- This library is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
- MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
- documentation provided hereunder is on an "as is" basis, and the
- Institute for Systems Biology and the Whitehead Institute
- have no obligations to provide maintenance, support,
- updates, enhancements or modifications. In no event shall the
- Institute for Systems Biology and the Whitehead Institute
- be liable to any party for direct, indirect, special,
- incidental or consequential damages, including lost profits, arising
- out of the use of this software and its documentation, even if the
- Institute for Systems Biology and the Whitehead Institute
- have been advised of the possibility of such damage. See
- the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with this library; if not, write to the Free Software Foundation,
- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-
-package org.cytoscape.internal.test;
-
-import java.awt.event.ActionEvent;
-
-import org.cytoscape.application.CyApplicationManager;
-import org.cytoscape.application.swing.AbstractCyAction;
-import org.cytoscape.work.*;
-
-
-/**
- *
- */
-public class WaitValueAction extends AbstractCyAction {
- private final static long serialVersionUID = 1502339870257629L;
-
- private TaskManager tm;
- public WaitValueAction(CyApplicationManager appMgr, TaskManager tm) {
- super("Wait Value", appMgr );
- this.tm = tm;
- setPreferredMenu("Help");
- }
-
- public void actionPerformed(ActionEvent e) {
- Runnable asdf = new Runnable() {
- public void run() {
- DummyTaskFactory tf = new DummyTaskFactory();
- tm.execute(tf);
- System.out.println("got value: " +
tf.getValue());
- }};
- new Thread(asdf).start();
- }
-
- private class DummyTaskFactory implements TaskFactory {
- ValuedTaskExecutor<Integer> vte;
- public TaskIterator getTaskIterator() {
- vte = new ValuedTaskExecutor<Integer>(new DummyTask());
- return new TaskIterator( vte );
- }
- public int getValue() {
- try {
- return vte.get();
- } catch (Exception e) { return -2; }
- }
- }
-
- private class DummyTask implements ValuedTask<Integer> {
- boolean cancelled = false;
- public Integer run(TaskMonitor taskMonitor) throws Exception {
- taskMonitor.setProgress(0.0);
- taskMonitor.setStatusMessage("Excuting Valued DUMMY ");
- int i = 0;
- while(i++ < 10){
- System.out.println("still value dummy
working..." + Thread.currentThread());
- Thread.sleep(1000);
- if ( cancelled ) {
- System.out.println("cancelling Infinite
DUMMY Task");
- return Integer.valueOf(-1);
- }
- }
- return Integer.valueOf(i);
- }
- public void cancel() {
- cancelled = true;
- }
- }
-}
-
-
--
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.