jeudi 15 juin 2017

State machine and asynchronous messaging, avoiding unexpected events

Say that you are designing a system with two subsystem, one is a state machine, A, and the other is a functional subsystem, B. subsystem B has methods like "doAsync()", that perform some operation and later return a completion or error event to back to system A.

Now subsystem A, can receive events from other external system, like “ModeChange” which results in changing to the proper state.

Here is the problem, say that subsystem A is in state AA that invoked the function doAsync() and is waiting for the completion event. Yet, before the completion event is received, I get a “ModeChange” event that now pushes subsystem A to state AB. However, the completion event for doAsync() is now received on state AB instead of AA and thus captured as an unexpected event.

What would be the best way to solve this problem?

Here are some possible solutions and my thoughts:

  1. Implement cancel operation for every async operation in system B.

I would prefer not to do this since it add a lot more work. It would increase the complexity of system B.

  1. Ignore the unexpected Events. I don’t like this solution because it would hide other problems.

Aucun commentaire:

Enregistrer un commentaire