Hi Britt, anonymous wrote : | Hmm...perhaps you can simply not use sub processes at all
I seem to like your first suggestion that each candidate should be a subprocess. Anyway, I was thinking long about it last night and I thought the key for it to work was to make child tokens to bind to the subprocess or probably create task instances to bind the subprocess. I looked up the posts regarding how to create child tokens but it seems the wiki custom fork was already very outdated. I also checked the manual on leaving transitions (decision) also it was outdated. Last resort was to dig up the code and do trial and error. I seem to come up with a better solution. The new solution has much natural design bec. it has the proper connections and transitions unlike the first. Workarounds are very hard to remember but quite easy to forget. ;) Here is my new process defintion. The fork-join is quite important so that the sub processes will know where they will meet when they end. | <process-definition name="hire-process"> | | <start-state name="start-hire"> | <transition to="fork"/> | </start-state> | | <fork name="fork"> | <transition to="approved-state"/> | </fork> | | <state name="approved-state"> | <transition name="default" to="approved-state"/> | <transition name="close" to="stop-hiring"/> | <transition name="add-candidate" to="approved-state"> | <action name="create-child-token" class="org.jbpm.CreateNewToken"> | <leavename>candidate-process</leavename> | </action> | </transition> | <transition name="candidate-process" to="candidate-process"/> | </state> | | <process-state name="candidate-process"> | <event type="subprocess-created"> | <script>print( "ENTERING SUBPROCESS ... TOKEN: " + token.getName() );</script> | </event> | <event type="subprocess-end"> | <script>print( "ENDING SUBPROCESS ... TOKEN: " + token.getName() );</script> | </event> | <sub-process name="candidate-process"/> | <transition to="join"/> | </process-state> | | <node name="stop-hiring"> | <event type="node-enter"> | <action name="kill-subprocess" class="org.jbpm.SubProcessKiller" /> | </event> | <transition to="join"/> | </node> | | <join name="join"> | <transition to="end-process"/> | </join> | | <end-state name="end-process"/> | | </process-definition> Here are the custom actions. I don't know if I've done this correctly. | public class CreateNewToken implements ActionHandler { | | String leavename; | | public void execute(ExecutionContext executionContext) throws Exception { | Token childToken = new Token( executionContext.getToken(), "TK" + (new UID()) ); | ExecutionContext newctx = new ExecutionContext(childToken); | executionContext.getTransitionSource().leave(newctx, leavename ); | } | | } | In order for it to work, you must provide a token name. I found about it the hard way. I think we can use the id here of the candidate, the name must be unique. Here is the sub process clean up. | public class SubProcessKiller implements ActionHandler { | | public void execute(ExecutionContext executionContext) throws Exception { | System.out.println( "START THE STOPPING PROCESS..."); | int i = 0; | Map m = executionContext.getProcessInstance().getRootToken().getActiveChildren(); | System.out.println( "NO. OF ACTIVE CHILDREN " + m.size() ); | Iterator iter = m.values().iterator(); | while( iter.hasNext() ) { | Token t = (Token)iter.next(); | System.out.println( "end token name " + t.getName() ); | if( t.getSubProcessInstance()!=null) { | System.out.println( "ending subprocess"); | t.getSubProcessInstance().end(); | i++; | } | } | System.out.println( "SUBPROCESSES CLEANED UP. NO. OF SUBPROCESS CLOSED " + i ); | } | | } | Anyway all seems to work this time and my design requirements are satisfied. I seem to prefer declarative programming as much as possible. Its self-documenting and we do not have to dig up code to remember things. If you or anybody has a much better design regarding handling of multiple subprocesses, I'd very much like to hear it. Thanks a lot for your help and have a happy new year. :) Regards, Elmo View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3914660#3914660 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3914660 ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click _______________________________________________ JBoss-user mailing list JBoss-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jboss-user