Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Akka design for Authentication (Finite State Machine)

Tags:

java

akka

I am quite new to Akka and I'd love to have some support for a design decision for my application. I have a rather typical Client/Server application. At the start the client should be able to authenticate at the application level and after that should be able to run in normal operational mode. There are also other state like closing, disconnected, etc. pp.

At the moment, I implemented this using become()

public class MyServerActor extends UntypedActor {
  Procedure<Object> normal = new Procedure<Object>() {
    @Override
    public void apply(Object msg) {
      handleMessage(msg);
    }
  };

  @Override
  public void onReceive(Object msg) throws Exception {
    if (msg instanceof LoginMessage) {
      // do login stuff, assume the login was successful
      getContext().become(normal);
  }

So I would use a different Procedure for a different state. However, in the doc at http://doc.akka.io/docs/akka/snapshot/java/fsm.html there is a Finite State Machine description which pretty much works like a standard State Machine; depending on the state do certain actions.

I wonder which is the better approach? Or what is the usual approach implementing a Client/Server application in Akka with java?

like image 988
dirkk Avatar asked Nov 12 '22 04:11

dirkk


1 Answers

If you're going for a state based approach, then use Procedure and become. It makes it very clear that you're in a specific state since all the code for that state is grouped together.

like image 176
Björn Antonsson Avatar answered Nov 14 '22 21:11

Björn Antonsson