Typed actor supervisor hierarchies (in Java)

218 views
Skip to first unread message

Josh

unread,
May 24, 2012, 5:17:05 PM5/24/12
to akka...@googlegroups.com
Is it possible to create a supervisor hierarchy consisting of typed actors in Java? The docs imply that it is possible:


"Since you can obtain a contextual Typed Actor Extension by passing in an ActorContext you can create child Typed Actors by invoking typedActorOf(..) on that."

But there doesn't appear to be a typedActorOf method on ActorContext. How do I create a supervisor hierarchy of typed actors?

Followup question - when an exception occurs in an actor where the supervisor is a typed actor, and the exception is escalated, where does the exception go?

Cheers,
Josh

√iktor Ҡlang

unread,
May 24, 2012, 5:25:46 PM5/24/12
to akka...@googlegroups.com







defget (context: ActorContext)TypedActorFactory

Returns a contextual TypedActorFactory of this extension, this means that any TypedActors created by this TypedActorExtension will be children to the specified context, this allows for creating hierarchies of TypedActors.


http://doc.akka.io/api/akka/2.0.1/#akka.actor.TypedActor$



  1. //Returns a contextual instance of the Typed Actor Extension
  2. //this means that if you create other Typed Actors with this,
  3. //they will become children to the current Typed Actor.
  4. TypedActor.get(TypedActor.context());


Cheers,



--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To view this discussion on the web visit https://groups.google.com/d/msg/akka-user/-/XRDs-Ya5GPUJ.
To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.



--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: @viktorklang

Jonas Bonér

unread,
May 24, 2012, 5:42:36 PM5/24/12
to akka...@googlegroups.com

We should add an example of how to create a supervisor hierarchy with typed actors. Current docs are close to non existant.

--
Jonas Bonér

√iktor Ҡlang

unread,
May 24, 2012, 5:47:46 PM5/24/12
to akka...@googlegroups.com
On Thu, May 24, 2012 at 11:42 PM, Jonas Bonér <jo...@jonasboner.com> wrote:

We should add an example of how to create a supervisor hierarchy with typed actors. Current docs are close to non existant.


Yeah, definitely, I'll do that. Always tricky to know what people will understand from a description and what needs an example.

√iktor Ҡlang

unread,
May 24, 2012, 6:49:57 PM5/24/12
to akka...@googlegroups.com
Done

Josh

unread,
May 24, 2012, 7:01:56 PM5/24/12
to akka...@googlegroups.com
Working good - thanks.

The second thing I was wondering about: Are failures intended to be handled ONLY by one of the pre-defined Directives? Is there any way for a caller (typed actor)/message sender (untyped actor) to learn of a failure, or for a supervisor to learn of a failure, and attempt to handle it?

Cheers,
Josh

On Thursday, May 24, 2012 2:25:46 PM UTC-7, √ wrote:







defget (context: ActorContext)TypedActorFactory

Returns a contextual TypedActorFactory of this extension, this means that any TypedActors created by this TypedActorExtension will be children to the specified context, this allows for creating hierarchies of TypedActors.


http://doc.akka.io/api/akka/2.0.1/#akka.actor.TypedActor$



  1. //Returns a contextual instance of the Typed Actor Extension
  2. //this means that if you create other Typed Actors with this,
  3. //they will become children to the current Typed Actor.
  4. TypedActor.get(TypedActor.context());


Cheers,


On Thu, May 24, 2012 at 11:17 PM, Josh <paces...@gmail.com> wrote:
Is it possible to create a supervisor hierarchy consisting of typed actors in Java? The docs imply that it is possible:


"Since you can obtain a contextual Typed Actor Extension by passing in an ActorContext you can create child Typed Actors by invoking typedActorOf(..) on that."

But there doesn't appear to be a typedActorOf method on ActorContext. How do I create a supervisor hierarchy of typed actors?

Followup question - when an exception occurs in an actor where the supervisor is a typed actor, and the exception is escalated, where does the exception go?

Cheers,
Josh

--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To view this discussion on the web visit https://groups.google.com/d/msg/akka-user/-/XRDs-Ya5GPUJ.
To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.

√iktor Ҡlang

unread,
May 24, 2012, 7:08:25 PM5/24/12
to akka...@googlegroups.com
Hi Josh,

On Fri, May 25, 2012 at 1:01 AM, Josh <paces...@gmail.com> wrote:
Working good - thanks.

Excellent!
 

The second thing I was wondering about: Are failures intended to be handled ONLY by one of the pre-defined Directives?

Yes
 
Is there any way for a caller (typed actor)/message sender (untyped actor) to learn of a failure,

 
or for a supervisor to learn of a failure, and attempt to handle it?

Yes, that is the job description of a supervisor, to learn of failures and attempt to handle them.

Cheers,
 
To view this discussion on the web visit https://groups.google.com/d/msg/akka-user/-/ZqLpQlU1U0YJ.

To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.

Josh

unread,
May 24, 2012, 8:00:31 PM5/24/12
to akka...@googlegroups.com
Thanks for the response.

From the docs and a bit of experimenting, it looks like exceptions only get thrown back to the caller/sender for typed actors? For typed actors that do result in exceptions being thrown back to the caller, is it recommended to handle those via supervision instead of try/catch in the caller?

Cheers,
Josh

Roland Kuhn

unread,
May 25, 2012, 2:41:36 AM5/25/12
to akka...@googlegroups.com
Hi Josh,

TypedActors really should be called something else, because they are not really actors in the model sense. Please have a look at this blog (http://letitcrash.com/post/19074284309/when-to-use-typedactors) for a recommendation on when to use them.

To highlight what I think is the core of the problem: POJOs and actors are two ways of doing object oriented programming (which is not at all about inheritance, mind you), and these ways differ fundamentally. POJOs are poked arbitrarily at the whim of anybody who happens to have a reference while actors consume messages at their own convenience, which is why I think that actors offer better encapsulation—the core feature of OO. Keeping this in mind should help understanding why trying to wrap an actor in POJO clothes will never yield a completely consistent picture.

This ties back into your problem because supervision is a feature only offered by real actors, and it leaks when forcing the POJO looks onto the crew.

Regards,

Roland

To view this discussion on the web visit https://groups.google.com/d/msg/akka-user/-/XRwAeRSo488J.

To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.

Roland Kuhn
Typesafe – The software stack for applications that scale.
twitter: @rolandkuhn


Jonas Boner

unread,
May 25, 2012, 4:16:13 AM5/25/12
to akka...@googlegroups.com
Another big difference is the dynamic nature in "real" actors and
static nature of typed-actors.

This means that in the real actors are much more loosely coupled and
we can easily do things like changing the protocol/interface/impl of
the actor at runtime through 'become', very easily do things like
supervision, location transparency, dynamic proxying through routers
etc. These things are much harder in the static typed-actor world.
>>>>> akka-user+...@googlegroups.com.
>>>>> For more options, visit this group at
>>>>> http://groups.google.com/group/akka-user?hl=en.
>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Viktor Klang
>>>>
>>>> Akka Tech Lead
>>>> Typesafe - The software stack for applications that scale
>>>>
>>>> Twitter: @viktorklang
>>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Akka User List" group.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msg/akka-user/-/ZqLpQlU1U0YJ.
>>>
>>> To post to this group, send email to akka...@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> akka-user+...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/akka-user?hl=en.
>>
>>
>>
>>
>> --
>> Viktor Klang
>>
>> Akka Tech Lead
>> Typesafe - The software stack for applications that scale
>>
>> Twitter: @viktorklang
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Akka User List" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/akka-user/-/XRwAeRSo488J.
> To post to this group, send email to akka...@googlegroups.com.
> To unsubscribe from this group, send email to
> akka-user+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/akka-user?hl=en.
>
>
> Roland Kuhn
> Typesafe – The software stack for applications that scale.
> twitter: @rolandkuhn
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Akka User List" group.
> To post to this group, send email to akka...@googlegroups.com.
> To unsubscribe from this group, send email to
> akka-user+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/akka-user?hl=en.



--
Jonas Bonér
CTO
Typesafe - The software stack for applications that scale
Phone: +46 733 777 123
Twitter: @jboner

Josh

unread,
May 25, 2012, 6:29:10 PM5/25/12
to akka...@googlegroups.com
Good stuff. Thanks for the responses all.
>>>>> akka-user+unsubscribe@googlegroups.com.
>>>>> For more options, visit this group at
>>>>> http://groups.google.com/group/akka-user?hl=en.
>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Viktor Klang
>>>>
>>>> Akka Tech Lead
>>>> Typesafe - The software stack for applications that scale
>>>>
>>>> Twitter: @viktorklang
>>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Akka User List" group.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msg/akka-user/-/ZqLpQlU1U0YJ.
>>>
>>> To post to this group, send email to akka...@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> akka-user+unsubscribe@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/akka-user?hl=en.
>>
>>
>>
>>
>> --
>> Viktor Klang
>>
>> Akka Tech Lead
>> Typesafe - The software stack for applications that scale
>>
>> Twitter: @viktorklang
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Akka User List" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/akka-user/-/XRwAeRSo488J.
> To post to this group, send email to akka...@googlegroups.com.
> To unsubscribe from this group, send email to
> akka-user+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/akka-user?hl=en.
>
>
> Roland Kuhn
> Typesafe – The software stack for applications that scale.
> twitter: @rolandkuhn
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Akka User List" group.
> To post to this group, send email to akka...@googlegroups.com.
> To unsubscribe from this group, send email to
> akka-user+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages