Cameron Taggart wrote: >> project in MINA so far, but now it's not. As you know, we have at least >> three projects in our sandbox; aioj, mina-sm, and serial. > > What are the mina-sm & serial projects in the sandbox for? > mina-sm is a package for defining state machines. Have a look at this JIRA issue: http://issues.apache.org/jira/browse/DIRMINA-160
The design have been changed since my last comments in JIRA. The current design uses annotations on methods to build the SM. You use the @State annotation to define the available states and then you annotate the methods which will be wrapped in MethodTransition objects using the @Handler annotation. Then you use StateMachineFactory and specifiy the classes which you want it to build a StateMachine from. It will read all the annotations and build the directed graph of State and Transition objects. Finally you use StateMachineProxyFactory to create the dynamic proxy for the interfaces of your choice (e.g. IoHandler in MINA). The proxy will translate all method calls on the dynamic proxy into Event objects which are passed on to your state machine methods. Normally the next state is statically defined in the @Handler annotation. However, you can also change the flow programatically through the StateControl class. Using it you can specify a different next state and whether it should handle the next event or the current event. There's also a subroutine like feature. This can be used if you have a sub graph in your state machine which will be called from several places and it should return to different states depending on the state it was called from. One of my favorite features with mina-sm is the method arguments matching described in the comments of the JIRA issue. It could be quite slow since it uses reflection and the matching is executed for every event. But this could probably be optimized significantly using byte code generation. That would be a lot of fun to implement! :-) So far mina-sm seems to work very well for the very complex state machines we have in our app. It hasn't been put in production yet but it will in a few weeks. If you want to check it out you will have to checkout the code from subversion and build yourself for now. -- Niklas Therning www.spamdrain.net
