Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use become() from Java

Tags:

java

akka

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>).

like image 620
aav Avatar asked Feb 04 '13 12:02

aav


1 Answers

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.

like image 152
Tomasz Nurkiewicz Avatar answered Sep 18 '22 01:09

Tomasz Nurkiewicz