switching default from wait to proceed
tom.baeyens Jan 31, 2008 4:40 AMIn NodeBehaviours, currently the default is wait. Meaning that if you don't call proceed, the execution will wait.
I remember that I had a few occasions where I saw that the default could be changed to proceed. In that case, the execution would proceed after the execute or signal was invoked unless a new wait() method was called. Up to now, i didn't find enough motivation to actually make the switch.
The only motivation so far was the overloaded execute method on Actions and NodeBehaviours. I previously opted for renaming the Action method to run to prevent a name clash there.
Now I think I might have found a real motivation: Exception handlers.
When an exception handler handles an exception, the execution is supposed to proceed after the delegation method that was invoked. Suppose now that we have an automatic activity like sending an email. The call to execution.proceed() will be at the end after the email sending code. Now suppose that sending the email throws an exception that is handled by an exception handler. Then the problem is that the execution.proceed of the automatic activity is not executed. So after the handling the exception, the execution will enter a wait state.
Come to think of it, changing the default only partially resolves the problem. If we change the default to proceed, we might have an analogue situation with wait states, where an exception might skip the invocation of execution.wait.
The solution is that NodeBehaviour implementors will have to put try-finally blocks around code that potentially throws an exception. In the finally block, they can call execution.wait().
In conclusion, switching the default from waiting to proceeding will have 2 main benefits:
1) The action.run method can be renamed to execute again. Automatic activities can just implement both Action and NodeBehaviour and only implement the execute method.
2) The extra difficulty of coding a try-finally will only be for node behaviours that are wait states. I think those are the ones that users will typically not write themselves. If we keep waiting as the default like it is now, we will put that burdon on the automatic activity implementors.
I'll let it sink in some more.
All thoughts are appreciated.