1 17 package org.apache.servicemix.beanflow; 18 19 import org.apache.commons.logging.Log; 20 import org.apache.commons.logging.LogFactory; 21 22 27 public class ExampleWorkflow extends Workflow<ExampleWorkflow.Step> { 29 private static final Log log = LogFactory.getLog(ExampleWorkflow.class); 30 31 private int loopCount; 32 private long timeout = 500; 33 private String userEmailAddress; 34 35 public static enum Step { 36 startStep, afterEnteredEmailStep, loopStep, waitForUserInputStep, forkStep, 37 aCompletedStep, abcCompletedStep, stop 38 }; 39 40 public ExampleWorkflow() { 41 super(Step.startStep); 42 } 43 44 47 public void startStep() { 48 addStep(Step.loopStep); 51 } 52 53 public Step loopStep() { 55 if (++loopCount > 3) { 56 return Step.waitForUserInputStep; 57 } 58 return Step.loopStep; 60 } 61 62 public void waitForUserInputStep() { 63 } 67 68 public Step afterEnteredEmailStep() { 69 log.info("User entered email address: " + userEmailAddress); 72 return Step.forkStep; 73 } 74 75 public void forkStep() { 76 TimeoutActivity a = new TimeoutActivity(); 78 TimeoutActivity b = new TimeoutActivity(); 79 TimeoutActivity c = new TimeoutActivity(); 80 81 log.info("Forking off processes a, b, c"); 82 fork(a, b, c); 83 84 joinAll(Step.aCompletedStep, timeout, a); 86 joinAll(Step.abcCompletedStep, timeout, a, b, c); 87 } 88 89 public void aCompletedStep() { 90 log.info("child flow A completed!"); 91 } 92 93 public Step abcCompletedStep() { 94 log.info("child flows A, B and C completed!"); 95 96 return Step.stop; 98 } 99 100 public void userEntered(String emailAddress) { 103 if (emailAddress != null && emailAddress.indexOf("@") > 0) { 104 this.userEmailAddress = emailAddress; 105 106 log.info("Lets re-start the suspended workflow"); 107 addStep(Step.afterEnteredEmailStep); 108 } 109 } 110 } 111 | Popular Tags |