-1

Was looking at implementing Non-deterministic finite state machine in Java. Have checked easyflow and many other such libraries but they offer is Deterministic finite state machine.

Eg. Use case. A user is in suspended state and has bill due of 100$ now he can refill his account with money voucher. if he refills with amount that makes his user balance less than 100 then he will continue in suspended state and if his account balance reached equal or more than hundred dollar then user is send to Active state.

So the event is same "refill" but user states very on his user-balance. So FSM is not deterministic.

Is there any idea on how to cater the case??

On contrary on the second thought I can implement this indeterministic FSM (or kind of FSM) using rule engines like drools .

Oracle BRM seems to be using some sort of state machine. Any idea on how ND-FSM is implemented in crm-systems. And what are the most used library(java) for same.

ManMohan Vyas
  • 4,004
  • 4
  • 27
  • 40
  • why -1 ?? I have also mentioned library I tried, and also catered use case where I think people have imlemented. I have also mentioned what other can be done using drools. !! :( – ManMohan Vyas Jun 15 '15 at 12:01

1 Answers1

1

Your state machine is not 'non-deterministic', but merely needs either guards on some of the transitions, which reduce to extra transitions in your handler. I don't know the library you're using and it has no documentation so I don't know whether it supports guards, so instead when in the 'refill received' state your handler can check the resultant balance immediately trigger either transition to either 'suspended' or 'active'

Pete Kirkham
  • 48,893
  • 5
  • 92
  • 171
  • could you suggest any library that is used industry wide. On the first glance https://code.google.com/p/tungsten-fsm/wiki/IntroToFSM#Incorporating_Tungsten_FSM_in_Applications looks promising. – ManMohan Vyas Jun 16 '15 at 06:15
  • Secondly, What If I have hierarchical entities for which I have different states to manage. Eg, On refill , first voucher state needs to be set to used, then user status needs to be set from suspended or active to active. then its services(may be more than one) needs to be changed. and so on many cascaded operations. so is it right thing to do or, This should not just be implemented in FSM. ?? Any idea on same?? – ManMohan Vyas Jun 16 '15 at 06:25
  • @ManMohanVyas I've not been in the Java ecosystem recently, having switched to C# a few years ago, so can't recommend a product. However, the vast majority of state machine derived code I've seen has been compiled rather than interpreted ( i.e. code is generated from a state machine model then compiled rather than the state machine being built out of an object graph). – Pete Kirkham Jun 17 '15 at 09:14
  • What if I can move from suspended to active or inactive state then it is non deterministic state .. right?? – ManMohan Vyas Jun 30 '15 at 08:20
  • @ManMohanVyas if there is nothing to determine which of the two states it ends up in, yes. However, in your case you can use a guard to check the amount in the account and so determine which state it should be go into. – Pete Kirkham Jun 30 '15 at 21:20
  • but from what i have read guards can only evaluate to true or false and cannot determine next state https://en.wikipedia.org/wiki/UML_state_machine#Guard_conditions – ManMohan Vyas Jul 01 '15 at 15:10
  • @ManMohanVyas you have two transitions both with the same event and guards which are exclusive. So the event either causes transition to 'active' state if the guard {account>=100} is is true and transition to 'inactive' state if the guard {!(account >=100)} is true. As the guards can't both be true, there is no indeterministic behaviour. – Pete Kirkham Jul 02 '15 at 10:18
  • thats completely true, in case I don't want to perform the action. The problem is even if the given amount is less than 100 I as a operator will always accept it. Now if accepting the payment is the action of changing transaction then this make the transaction non -deterministic , as I am not holding to the current transaction instead I want to do the internal transaction to same state or I want to go to different state ... is am still wrong?? I suppose what u told is correct in case I do not want to accept payment , or case is reject payment less than 100. ..please correct me if wrong – ManMohan Vyas Jul 03 '15 at 03:14