But following code is not working as expected and its always executing all the nodes.
The code should work, but the problem is that the process definition is composed of <node> elements. As these are not wait states, the process execution just continues, regardless of the ActionHandler. Change all the <node> elements in your process to <state> elements, and you should get the desired result with the AutomationHandler.