Recommended FSM (Finite State Machine) Library for Java [closed]


Is there a best-of-breed in-memory FSM library for Java?

I think ideal library would be relatively simple with support for events, actions, and transitions. It wouldn't require external configuration or precompilation. It wouldn't have to be concurrent capable or multi-threaded. Nice if it was hierarchical, but also not required. I think the State Machine included in Qt (C++) is at the ideal level of complexity and functionality. In fact, there are a number of interesting FSM libraries for C/C++, but I've been unable to find anything similar for Java.

I've come across the following Java libraries so far:

A number of articles online discuss ideas for implementing a custom FSM in Java, and maybe that's the way to go for simple in-memory FSM needs. At first I considered using a BPM engine like Activiti, but I think that those types of libraries are overkill and are more oriented towards process workflow.

I'm looking to use an FSM for managing the high level behaviors of a small robot. However, I would expect a decent FSM library of this type would also be applicable to GUI state management, game flow, and simple AI.

Any library recommendations, notes on experience with libraries above, or pointers to recent and modern FSM implementation strategies in Java would be appreciated.

share improve this question

closed as off-topic by RaedwaldrgettmanbmarguliesMakotoDrew Sep 28 '13 at 1:44

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – Raedwald, rgettman, bmargulies, Makoto, Drew
If this question can be reworded to fit the rules in the help center, please edit the question.

 

8 Answers

up vote 35 down vote accepted

In answer to my question, there seems to be no defacto FSM libraries for Java. The complete list of options I've come across as of April 2013:

From original question:

Updates:

Also:

share improve this answer
 
 
SMC link doesn't work, also the question is asking about a Java library. Not javascript, not C, not C++. –  Basil Musa  Nov 29 '12 at 10:54
4 
@Basil If the SMC link didn't work, then it's because SourceForge was down temporarily. It works fine now. All of the libraries listed, except for the JavaScript FSM, work with Java directly, or generate pure Java code. And as I explained, the JavaScript FSM can be used from Java using an embedded interpreter. There was no reason to downvote this answer. Thanks for the Stateless4J suggestion. Looks very interesting and I updated this answer to include it. –   kaliatech  Nov 29 '12 at 14:38 
2 
Down vote removed. Up vote applied. Work stress makes me overlook many gems. Apologies. –  Basil Musa  Dec 2 '12 at 11:56
1 
The Tungsten FSM library seems to be no longer maintained. –   spaceknarf  Sep 29 '14 at 10:43
 
Thanks for the list all. Could be worth having a brief summary of features in each. Just to add a little info, Stateless4j has parameterised arguments which were a particular feature I was looking for - they help to capture the information you don't want to put into a state. (e.g. an error code in an error trigger). It would be cool to quickly assess which libraries do this –   Sam  Feb 3 at 18:07 

This library is a very simple but fully functional state machine implementation:http://sourceforge.net/projects/javafsm/ It can be used for two quite distinct sets of purposes:

  1. Define business workflow with the purpose of validating state transitions
  2. Use it as a theoretical FSM for language recognition by defining an alphabet and using the accept() method for strings on this alphabet.

Here is an example of how to build a state machine with JavaFSM:

FSMBuilder<String> builder = FSM.newFSM();
FiniteStateMachine<String> machine =      
builder.setInitialState("A")
       .addFinalState("B")
       .addTransition("A", "A", '0')
       .addTransition("A", "B", '1')
       .addTransition("B", "A", '1')
       .addTransition("B", "B", '0')
       .build();
share improve this answer
 

akka's FSM is also an option..

share improve this answer
 

In the book Agile Software Development, Uncle Bob discusses Finite State Machines and the Statepattern (if I remember correctly). He's created an FSM compiler called SMC. Take a look.

share improve this answer
 
 
The State Map Compiler (SMC) requires external definition and a precompiler, but still, it's very interesting and I hadn't come across it before. Thanks. –   kaliatech  Jun 4 '12 at 13:11
 
@kaliatech and Jordao: I was looking for a popular and decent quality state machine that can be used in android. Can you please elaborate on your experience with SMC; having an external definition seemed like a plus to me. –   likejiujitsu  Jun 4 '14 at 14:51 

Try this wonderful library from code.google.com :

Stateless4J

share improve this answer
 
1 
That version is no longer being maintained, try github.com/oxo42/stateless4j </plug> –   John Oxley  Apr 23 '14 at 9:06

You can check for "squirell-foundation" too.

share improve this answer
 
1 
Too much reflection/annotations, Android no likey. –   MLProgrammer-CiM  Oct 23 '14 at 13:39

I was looking for a FSM for Android a few months ago but couldn't find anything suitable, so had to create my own - EasyFlow.

I reviewed the existing at that moment solutions and developed a light-weight library that is easier to use. With EasyFlow even complex logic can be implemented with clean and well-structured code.

If anyone's still looking for a state machine for java, check it out.

You can contribute to the project as well.

share improve this answer
 
 
Hey I had a look at EasyFlow and it looks good. unfortunately, one of the main features I'd like to have is paramaterized arguments. I've come to realise they let you capture the things you dont want to put into states, but DO have as a requirement. I just thought I'd add this help anyone make a decision - if you don't need parameterised event arguments , EasyFlow looks like one of the lightest-weight state machine implementations on the list. –   Sam  Feb 3 at 18:28 

The CS department at Aarhus University has www.brics.dk/automaton which looks interesting. It seems most geared towards automata derived from regular expressions, but you can create them manually. It has three different algorithms for determinizing an NFA, and a lot of formal operations on automata (combining them, comparing them, describing what input sequences they'll match, etc.)

I don't see support for actions, which seems an odd omission to me. Maybe I'm missing it. Maybe it's tricky to have them end up in the right places after the various formal operations. Still, it doesn't seem as if it should be impossible to have some notion of actions; maybe that could be added and submitted upstream.

share improve this answer
 

Not the answer you're looking for? Browse other questions tagged    orask your own question.


http://stackoverflow.com/questions/10875317/recommended-fsm-finite-state-machine-library-for-java

Is there a best-of-breed in-memory FSM library for Java?

I think ideal library would be relatively simple with support for events, actions, and transitions. It wouldn't require external configuration or precompilation. It wouldn't have to be concurrent capable or multi-threaded. Nice if it was hierarchical, but also not required. I think the State Machine included in Qt (C++) is at the ideal level of complexity and functionality. In fact, there are a number of interesting FSM libraries for C/C++, but I've been unable to find anything similar for Java.

I've come across the following Java libraries so far:

A number of articles online discuss ideas for implementing a custom FSM in Java, and maybe that's the way to go for simple in-memory FSM needs. At first I considered using a BPM engine like Activiti, but I think that those types of libraries are overkill and are more oriented towards process workflow.

I'm looking to use an FSM for managing the high level behaviors of a small robot. However, I would expect a decent FSM library of this type would also be applicable to GUI state management, game flow, and simple AI.

Any library recommendations, notes on experience with libraries above, or pointers to recent and modern FSM implementation strategies in Java would be appreciated.

share improve this question

closed as off-topic by RaedwaldrgettmanbmarguliesMakotoDrew Sep 28 '13 at 1:44

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – Raedwald, rgettman, bmargulies, Makoto, Drew
If this question can be reworded to fit the rules in the help center, please edit the question.

 

8 Answers

up vote 35 down vote accepted

In answer to my question, there seems to be no defacto FSM libraries for Java. The complete list of options I've come across as of April 2013:

From original question:

Updates:

Also:

share improve this answer
 
   
SMC link doesn't work, also the question is asking about a Java library. Not javascript, not C, not C++. –  Basil Musa  Nov 29 '12 at 10:54
4 
@Basil If the SMC link didn't work, then it's because SourceForge was down temporarily. It works fine now. All of the libraries listed, except for the JavaScript FSM, work with Java directly, or generate pure Java code. And as I explained, the JavaScript FSM can be used from Java using an embedded interpreter. There was no reason to downvote this answer. Thanks for the Stateless4J suggestion. Looks very interesting and I updated this answer to include it. –   kaliatech  Nov 29 '12 at 14:38 
2 
Down vote removed. Up vote applied. Work stress makes me overlook many gems. Apologies. –  Basil Musa  Dec 2 '12 at 11:56
1 
The Tungsten FSM library seems to be no longer maintained. –   spaceknarf  Sep 29 '14 at 10:43
   
Thanks for the list all. Could be worth having a brief summary of features in each. Just to add a little info, Stateless4j has parameterised arguments which were a particular feature I was looking for - they help to capture the information you don't want to put into a state. (e.g. an error code in an error trigger). It would be cool to quickly assess which libraries do this –   Sam  Feb 3 at 18:07 

This library is a very simple but fully functional state machine implementation:http://sourceforge.net/projects/javafsm/ It can be used for two quite distinct sets of purposes:

  1. Define business workflow with the purpose of validating state transitions
  2. Use it as a theoretical FSM for language recognition by defining an alphabet and using the accept() method for strings on this alphabet.

Here is an example of how to build a state machine with JavaFSM:

FSMBuilder<String> builder = FSM.newFSM();
FiniteStateMachine<String> machine =      
builder.setInitialState("A")
       .addFinalState("B")
       .addTransition("A", "A", '0')
       .addTransition("A", "B", '1')
       .addTransition("B", "A", '1')
       .addTransition("B", "B", '0')
       .build();
share improve this answer
 

akka's FSM is also an option..

share improve this answer
 

In the book Agile Software Development, Uncle Bob discusses Finite State Machines and the Statepattern (if I remember correctly). He's created an FSM compiler called SMC. Take a look.

share improve this answer
 
   
The State Map Compiler (SMC) requires external definition and a precompiler, but still, it's very interesting and I hadn't come across it before. Thanks. –   kaliatech  Jun 4 '12 at 13:11
   
@kaliatech and Jordao: I was looking for a popular and decent quality state machine that can be used in android. Can you please elaborate on your experience with SMC; having an external definition seemed like a plus to me. –   likejiujitsu  Jun 4 '14 at 14:51 

Try this wonderful library from code.google.com :

Stateless4J

share improve this answer
 
1 
That version is no longer being maintained, try github.com/oxo42/stateless4j </plug> –   John Oxley  Apr 23 '14 at 9:06

You can check for "squirell-foundation" too.

share improve this answer
 
1 
Too much reflection/annotations, Android no likey. –   MLProgrammer-CiM  Oct 23 '14 at 13:39

I was looking for a FSM for Android a few months ago but couldn't find anything suitable, so had to create my own - EasyFlow.

I reviewed the existing at that moment solutions and developed a light-weight library that is easier to use. With EasyFlow even complex logic can be implemented with clean and well-structured code.

If anyone's still looking for a state machine for java, check it out.

You can contribute to the project as well.

share improve this answer
 
   
Hey I had a look at EasyFlow and it looks good. unfortunately, one of the main features I'd like to have is paramaterized arguments. I've come to realise they let you capture the things you dont want to put into states, but DO have as a requirement. I just thought I'd add this help anyone make a decision - if you don't need parameterised event arguments , EasyFlow looks like one of the lightest-weight state machine implementations on the list. –   Sam  Feb 3 at 18:28 

The CS department at Aarhus University has www.brics.dk/automaton which looks interesting. It seems most geared towards automata derived from regular expressions, but you can create them manually. It has three different algorithms for determinizing an NFA, and a lot of formal operations on automata (combining them, comparing them, describing what input sequences they'll match, etc.)

I don't see support for actions, which seems an odd omission to me. Maybe I'm missing it. Maybe it's tricky to have them end up in the right places after the various formal operations. Still, it doesn't seem as if it should be impossible to have some notion of actions; maybe that could be added and submitted upstream.

share improve this answer
 

Not the answer you're looking for? Browse other questions tagged    orask your own question.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值