Akka framework recommends using typed actor only for interacting with external code. However, standard actors from akka are untyped. Is there any better way to create type safe actors? Are there some other actor frameworks or type safe wrappers around akka?
-
What problems are you trying to solve? – Viktor Klang Jul 01 '12 at 20:41
-
2@ViktorKlang I want to be sure that only correct messages are sent to my actors. – Konstantin Solomatov Jul 01 '12 at 21:22
-
You might want to check out http://stackoverflow.com/a/5551034/734191 where Viktor gives some more explanations (e.g., `become`). – Hbf Jul 23 '12 at 18:37
4 Answers
If you really want actors with static typing, then you might as well go ahead and use typed actors throughout your code. This is strongly discouraged for a couple of reasons.
1.) You run the risk of your system degenerating into a bunch of RPCs. An actor's receive method makes it pretty obvious that the whole thing is about message passing, much less so if you're just calling methods on a typed actor.
2.) An actor just really doesn't have a type. While it's running, the messages an actor is able to process may change depending on what state is in, as may what it does with those messages. This is an excellent way of modeling a lot of protocols, and Akka actors have first class support for it with FSMs.
So if you really want to do it, you're free to used typed actors everywhere and it'll work, but you should really think hard about the problem you're trying to solve before doing so.

- 3,264
- 17
- 15
For compile time checking see SynapseGrid framework. It defines a SystemBuilder that constructs the DataFlow topology. While constructing it is guaranteed that types that pass by are checked. Then the resulting system is converted to RuntimeSystem with nested and properly interconnected actors.

- 2,381
- 17
- 21
Why is this a problem for you? akka.actor.Actor
has the receive method of type PartialFunction
that will only be called for messages that it can handle. Why do you need compile time checks? But to answer your question: one way would be - for an external api - to build a wrapper around your ActorRef
that then sends the messages to the actor.

- 24,225
- 4
- 67
- 81
-
4
-
-
An actor should decide for itself whether or not it can process a certain message. If you want to add more messages afterwards you will have to make a lot of code changes and also it makes remoting harder. – drexin Jul 02 '12 at 11:26
-
Actor decides for itself only because type safety is not supported by akka. It would be really good to be sure you sending message to right type of actor statically without catching runtime errors "could not process the message". Making extensible protocols that could be composed on the fly - is hard task for scala. Still possible to achieve: http://milessabin.com/blog/2011/06/09/scala-union-types-curry-howard/ – ayvango Jul 15 '15 at 22:52
Things are going quite fast, I thought about giving an update 1. Typed actors are deprecated 2. Instead a new concept of Akka Typed is being devloped at the momemnt
As I understood this should be the definitive solution to an typed actor system. But since this is at least the third try and planned earliest for Akka 2.4, this claim remains to be proven.
I personally do look forward to have both systems available: the existing one for more dynamic use cases, the new one for more robust ones

- 784
- 5
- 12