I'm using Akka from Java. According to documentation, context.become()
takes Procedure<Object>
as a parameter. In fact, it expects PartialFunction<Object, BoxedUnit>
which appears to be something auto-generated with lot's of methods with strange names.
What is the right way of using become() from Java?
PS i'm using Akka 2.0.3
Update:
Looks like that there are two methods: context() and getContext(). The first one returns ActorContext, and the second one returns UntypedActorContext. UntypedActorContext has become(Procedure<Object>)
.
You are confusing Akka Java and Scala API. Technically you can use Scala libraries like Akka from Java code, but quite often it's verbose and cumbersome. So the Akka team decided to develop to separate APIs - native in Scala and Java adapter.
In Scala API you extend akka.actor.Actor
which has a context
field of type akka.actor.ActorContext
. This ActorContext.become()
accepts PartialFunction
, which is a Scala-specific class.
On the other hand in Java API you extend akka.actor.UntypedActor
having (Java-like) method getContext()
, returning akka.actor.UntypedActorContext
. This one accepts akka.japi.Procedure
.
To cut the long story short - if you are using Java API, stick to it. There is a clear distinction between Scala and Java documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With