您的位置:首页 > 编程语言 > Java开发

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

2015-04-03 18:03 447 查看
50down
votefavorite
23

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:

Unimod FSM Framework - Looks
very good, but maybe overly complex.
Tungsten FSM Library -
No longer active as a standalone library. No documentation that I could find.
Apache SCXML - Maybe? I've
read that it has issues, but haven't used it yet myself.

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.

java finite-state-machine fsm
shareimprove
this question
asked Jun 4 '12 at 1:14





kaliatech

9,42233148


closed as off-topic by Raedwald, rgettman, bmargulies, Makoto, Drew 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.

add
a comment


8 Answers

activeoldestvotes

up vote35down
voteaccepted
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:

Unimod FSM Framework
Tungsten FSM Library
Apache SCXML

Updates:

SMC: The State Map Compiler (per @Jordão's
answer)

Stateless4J (per @Basis
Musa's answer)

Ragel State Machine Compiler

EasyFlow (per @Andrey's
answer)

Squirrel-Foundation (per @Fluera's
answer)

Also:

JavaScript
Finite State Machine

A clean design that could be easily used from Java with embedded script engine.

shareimprove
this answer
edited Apr
23 '14 at 9:08




John Oxley

4,68283062

answered Nov 21 '12 at 17:25





kaliatech

9,42233148

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
add
a comment





up vote6down
vote
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:

Define business workflow with the purpose of validating state transitions
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();


shareimprove
this answer
answered Dec 26 '12 at 15:52





Dimitri Papaioannou

6111

add
a comment
up vote6down
vote
akka's FSM is also an option..

shareimprove
this answer
answered Feb 25 '13 at 2:42





Bùi Việt Thành

9427

add
a comment
up vote5down
vote
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.

shareimprove
this answer
answered Jun 4 '12 at 1:33




Jordão

32k46279

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
add
a comment
up vote5down
vote
Try this wonderful library from code.google.com :

Stateless4J

shareimprove
this answer
answered Nov 29 '12 at 10:55





Basil Musa

79711325

1
That version is no longer being maintained, try github.com/oxo42/stateless4j </plug> – John
Oxley Apr
23 '14 at 9:06
add
a comment
up vote5down
vote
You can check for "squirell-foundation" too.

shareimprove
this answer
answered Apr 18 '13 at 14:32




Flueras Bogdan

2,13372228

1
Too much reflection/annotations, Android no likey. – MLProgrammer-CiM Oct
23 '14 at 13:39
add
a comment
up vote2down
vote
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.

shareimprove
this answer
answered Apr 16 '13 at 2:10





Andrey Chausenko

1014

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
add
a comment
up vote0down
vote
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.

shareimprove
this answer
answered Sep 25 '13 at 13:59





Chapman Flack

1

add
a comment


Not the answer you're looking for? Browse other questions tagged java finite-state-machine fsm orask
your own question.

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

50down
votefavorite
23

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:

Unimod FSM Framework - Looks
very good, but maybe overly complex.
Tungsten FSM Library -
No longer active as a standalone library. No documentation that I could find.
Apache SCXML - Maybe? I've
read that it has issues, but haven't used it yet myself.

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.

java finite-state-machine fsm
shareimprove
this question
asked Jun 4 '12 at 1:14





kaliatech

9,42233148


closed as off-topic by Raedwald, rgettman, bmargulies, Makoto, Drew 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.

add
a comment


8 Answers

activeoldestvotes

up vote35down
voteaccepted
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:

Unimod FSM Framework
Tungsten FSM Library
Apache SCXML

Updates:

SMC: The State Map Compiler (per @Jordão's
answer)

Stateless4J (per @Basis
Musa's answer)

Ragel State Machine Compiler

EasyFlow (per @Andrey's
answer)

Squirrel-Foundation (per @Fluera's
answer)

Also:

JavaScript
Finite State Machine

A clean design that could be easily used from Java with embedded script engine.

shareimprove
this answer
edited Apr
23 '14 at 9:08




John Oxley

4,68283062

answered Nov 21 '12 at 17:25





kaliatech

9,42233148

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
add
a comment





up vote6down
vote
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:

Define business workflow with the purpose of validating state transitions
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();


shareimprove
this answer
answered Dec 26 '12 at 15:52





Dimitri Papaioannou

6111

add
a comment
up vote6down
vote
akka's FSM is also an option..

shareimprove
this answer
answered Feb 25 '13 at 2:42





Bùi Việt Thành

9427

add
a comment
up vote5down
vote
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.

shareimprove
this answer
answered Jun 4 '12 at 1:33




Jordão

32k46279

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
add
a comment
up vote5down
vote
Try this wonderful library from code.google.com :

Stateless4J

shareimprove
this answer
answered Nov 29 '12 at 10:55





Basil Musa

79711325

1
That version is no longer being maintained, try github.com/oxo42/stateless4j </plug> – John
Oxley Apr
23 '14 at 9:06
add
a comment
up vote5down
vote
You can check for "squirell-foundation" too.

shareimprove
this answer
answered Apr 18 '13 at 14:32




Flueras Bogdan

2,13372228

1
Too much reflection/annotations, Android no likey. – MLProgrammer-CiM Oct
23 '14 at 13:39
add
a comment
up vote2down
vote
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.

shareimprove
this answer
answered Apr 16 '13 at 2:10





Andrey Chausenko

1014

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
add
a comment
up vote0down
vote
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.

shareimprove
this answer
answered Sep 25 '13 at 13:59





Chapman Flack

1

add
a comment


Not the answer you're looking for? Browse other questions tagged java finite-state-machine fsm orask
your own question.

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐