You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by js...@apache.org on 2006/05/10 18:02:02 UTC

svn commit: r405787 - in /incubator/servicemix/trunk/servicemix-beanflow/src: main/java/org/apache/servicemix/beanflow/ test/java/org/apache/servicemix/beanflow/

Author: jstrachan
Date: Wed May 10 09:01:54 2006
New Revision: 405787

URL: http://svn.apache.org/viewcvs?rev=405787&view=rev
Log:
tidied up the javadoc some more and added an isFailed() method to the flow

Modified:
    incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/Flow.java
    incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/FlowSupport.java
    incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/State.java
    incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/TimeoutFlow.java
    incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/TimeoutFlowTest.java

Modified: incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/Flow.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/Flow.java?rev=405787&r1=405786&r2=405787&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/Flow.java (original)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/Flow.java Wed May 10 09:01:54 2006
@@ -17,11 +17,23 @@
 package org.apache.servicemix.beanflow;
 
 /**
+ * Represents a flow instance which is a bean based workflow written using Java code.
+ * A flow monitors various {@link State} objects and takes action when things change.
+ * Flows are designed to be thread safe and are intended for use in highly concurrent
+ * or distributed applications so that the state can be changed from any thread.
+ * <br>
+ * The Processing of notifications of state changes should generally be quick; if lots of work
+ * is required when some state changes it is advisable to use a thread pool to do the work.
  * 
  * @version $Revision: $
  */
 public interface Flow {
 
+    /**
+     * The core transitions of a flow
+     * 
+     * @version $Revision: 1.1 $
+     */
     public enum Transitions {
         Initialised, Starting, Started, Stopping, Stopped,
     };
@@ -47,4 +59,8 @@
      */
     public boolean isStopped();
 
+    /**
+     * Returns true if the flow has failed to complete succesfully
+     */
+    public boolean isFailed();
 }

Modified: incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/FlowSupport.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/FlowSupport.java?rev=405787&r1=405786&r2=405787&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/FlowSupport.java (original)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/FlowSupport.java Wed May 10 09:01:54 2006
@@ -31,6 +31,7 @@
 public abstract class FlowSupport implements Runnable, Flow {
 
     private State<Transitions> state = new DefaultState<Transitions>(Transitions.Initialised);
+    private State<Boolean> failed = new DefaultState<Boolean>(Boolean.FALSE);
     private Introspector introspector = new FieldIntrospector();
 
     /**
@@ -54,6 +55,14 @@
     }
 
     /**
+     * Stops the flow with a failed state
+     */
+    public void fail() {
+        stop();
+        failed.set(true);
+    }
+    
+    /**
      * Returns the current running state of this flow
      */
     public State<Transitions> getState() {
@@ -64,6 +73,10 @@
         return state.is(Transitions.Stopped);
     }
 
+    public boolean isFailed() {
+        return failed.get();
+    }
+    
     // Implementation methods
     // -------------------------------------------------------------------------
     protected void doStart() {

Modified: incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/State.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/State.java?rev=405787&r1=405786&r2=405787&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/State.java (original)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/State.java Wed May 10 09:01:54 2006
@@ -18,7 +18,8 @@
 
 /**
  * Represents a piece of state which can be accessed in a multi threaded way
- * together with adding listeners to be notified if the state changes.
+ * rather like {@link java.util.concurrent.atomic.AtomicReference} but which also 
+ * supports the use of listeners to be notified when the state changes.
  * 
  * @version $Revision: $
  */

Modified: incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/TimeoutFlow.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/TimeoutFlow.java?rev=405787&r1=405786&r2=405787&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/TimeoutFlow.java (original)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/main/java/org/apache/servicemix/beanflow/TimeoutFlow.java Wed May 10 09:01:54 2006
@@ -41,7 +41,7 @@
     public void run() {
         if (!isStopped()) {
             if (timedOut.get().booleanValue()) {
-                stop();
+                fail();
             }
         }
     }

Modified: incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/TimeoutFlowTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/TimeoutFlowTest.java?rev=405787&r1=405786&r2=405787&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/TimeoutFlowTest.java (original)
+++ incubator/servicemix/trunk/servicemix-beanflow/src/test/java/org/apache/servicemix/beanflow/TimeoutFlowTest.java Wed May 10 09:01:54 2006
@@ -33,21 +33,37 @@
     public void testFlowStopsSuccessfully() throws Exception {
         flow.getState().set(Transitions.Stopped);
         
-        assertTrue("Flow should be stopped", flow.isStopped());
+        assertEquals("Transition", Transitions.Stopped, flow.getState().get());
+        
+        assertTrue("Flow should be stopped but is: " + flow.getState().get(), flow.isStopped());
+        assertTrue("Flow should not have failed", !flow.isFailed());
+        
+        // lets sleep so that the timer can go off now to check we don't fail after we've stopped
+        Thread.sleep(timeout  * 4);
         
         assertEquals("Transition", Transitions.Stopped, flow.getState().get());
+        
+        assertTrue("Flow should be stopped but is: " + flow.getState().get(), flow.isStopped());
+        assertTrue("Flow should not have failed", !flow.isFailed());
     }
 
     public void testFlowTimesOutAndFails() throws Exception {
         Thread.sleep(timeout  * 4);
         
+        assertEquals("Transition", Transitions.Stopped, flow.getState().get());
+        
         assertTrue("Flow should be stopped but is: " + flow.getState().get(), flow.isStopped());
-        assertTrue("Flow should have timed out", flow.isTimedOut());
+        assertTrue("Flow should have failed", flow.isFailed());
         
     }
 
     protected void setUp() throws Exception {
         timer.schedule(flow.getTimeoutTask(), timeout);
+        
+        assertTrue("flow should not be stopped", !flow.isStopped());
+        assertTrue("flow should not have failed", !flow.isFailed());
+        assertEquals("Transition", Transitions.Initialised, flow.getState().get());
+        
         flow.start();
         assertEquals("Transition", Transitions.Started, flow.getState().get());
     }