Sending messages to self.

943 views
Skip to first unread message

clanie

unread,
Nov 3, 2010, 6:01:43 AM11/3/10
to Akka User List
Hi.

This is kind'a embarrassing to ask, as it sounds like something that
should be very obvious, but I simply can't figure out how to make a
(Java) TypedActor send messages to itself (ie. calling it's own
methods asynchronously).

Can someone point me in the right direction, please?

Best regards
Claus Nielsen

Dustin Whitney

unread,
Nov 3, 2010, 6:23:59 AM11/3/10
to akka...@googlegroups.com
Hey Claus,

    I have encountered similar problems with typed actors where I'd have thought it would work because the message was fire-and-forget.  My way around the problem was to create a private method that performed the logic I needed.  So I had something like (in psuedo-code):

trait MyQueue extends TypedActor{
   def enqueue
   def doStuffThenEnqueue
}

class MyActor extends MyQueue{
    def enqueue = privateEnqueue
    def doStuffThenEnqueue = { .... do stuff ...; privateEnqueue}
   private def privateEnequeue = { ... enqueues things in an encapsulated way ... }
}

Hope that helps,
D


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


clanie

unread,
Nov 3, 2010, 6:40:47 AM11/3/10
to Akka User List
Thanks.

I'm not sure i completely understand (don't know Scala), but I also
got around it by using a second class to call back. Guess that's
similar to what you suggest - it just seems unreasonably difficult.

Best regards
Claus
> > akka-user+...@googlegroups.com<akka-user%2Bunsubscribe@googlegroups .com>
> > .

Jonas Bonér

unread,
Nov 3, 2010, 7:35:17 AM11/3/10
to akka...@googlegroups.com
Could be useful to inject the 'self' typed actor ref, but dangerous as well.
Can you not just lookup your self in the ActorRegistry by UUID?

> 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

work: http://akkasource.org
code: http://github.com/jboner
blog:  http://jonasboner.com
twtr:  @jboner

Dustin Whitney

unread,
Nov 3, 2010, 7:40:30 AM11/3/10
to akka...@googlegroups.com
Oh, right I forgot you were using the Java libs - here is the example in Java:

interface MyQueue extends TypedActor{
  public void enqueue()
  public void doStuffThenEnqueue()
}
 
public class MyActor implements MyQueue{
     public void enqueue() {privateEnqueue();}
     public void doStuffThenEnqueue(){ .... do stuff ...; privateEnqueue()}
     private void privateEnequeue(){ ... enqueues things in an encapsulated way ... }
}

-D

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

√iktor Klang

unread,
Nov 3, 2010, 7:45:20 AM11/3/10
to akka...@googlegroups.com
Hi Clanie,

that's actually a very _good_ question.

The OOTB answer is to look yourself up in the ActorRegistry.

I think I need to think about that some more before I give any other answers.

Cheers,

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




--
Viktor Klang,
Code Connoisseur
Work:   akka.io
Code:   github.com/viktorklang
Follow: twitter.com/viktorklang
Read:   klangism.tumblr.com

Message has been deleted

clanie

unread,
Nov 4, 2010, 7:23:31 PM11/4/10
to Akka User List
I'm trying to use the ActorRegistry as both Viktor and Jonas suggests,
but haven't succeded yet.

In my actor I can use ActorRegistry to get an ActorRef using one of
these methods:

ActorRegistry.actorsFor(getClass());
ActorRegistry.actorsFor(self().id());
ActorRegistry.actorFor(self().uuid());

The first two returns ActorRef arrays and the last one returns an
Option<ActorRef>.

However I don't see how I can invoke the methods defined in MyActor on
any of those.

The docs (under Core | Java API | Actor Registry) says something about
using an UntypedActorRef, but that dosn't exist any more, does it?
Or maby it's newer than the version I'm using: 0.10
Also, it's an TypedActor (MyActor, actually) I want.

Any suggestions?

Best regards
Claus


On 3 Nov., 12:45, √iktor Klang <viktor.kl...@gmail.com> wrote:
> Hi Clanie,
>
> that's actually a very _good_ question.
>
> The OOTB answer is to look yourself up in the ActorRegistry.
>
> I think I need to think about that some more before I give any other
> answers.
>
> Cheers,
>
>
>
>
>
>
>
>
>
> On Wed, Nov 3, 2010 at 11:01 AM, clanie <cn.cncons...@gmail.com> wrote:
> > Hi.
>
> > This is kind'a embarrassing to ask, as it sounds like something that
> > should be very obvious, but I simply can't figure out how to make a
> > (Java) TypedActor send messages to itself (ie. calling it's own
> > methods asynchronously).
>
> > Can someone point me in the right direction, please?
>
> > Best regards
> > Claus Nielsen
>
> > --
> > 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<akka-user%2Bunsubscribe@googlegroups .com>
> > .

Jonas Bonér

unread,
Nov 5, 2010, 2:15:24 AM11/5/10
to akka...@googlegroups.com
Hi.

You need to use one of these methods on the ActorRegistry:

def typedActors: Array[AnyRef]
def typedActorFor(uuid: Uuid): Option[AnyRef]
def typedActorsFor(id: String): Array[AnyRef]
def typedActorsFor[T <: AnyRef](implicit manifest: Manifest[T]): Array[AnyRef]
def typedActorsFor[T <: AnyRef](clazz: Class[T]): Array[AnyRef]

/Jonas

> 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

Jonas Bonér
Specialist at Large
work: http://scalablesolutions.se
code: http://akka.io

clanie

unread,
Nov 5, 2010, 4:56:07 AM11/5/10
to Akka User List
Ahh, no wonder I couldn't find that - weren't there in 0.10.

Thanks a lot.

/Claus

On 5 Nov., 07:15, Jonas Bonér <jo...@jonasboner.com> wrote:
> Hi.
>
> You need to use one of these methods on the ActorRegistry:
>
> def typedActors: Array[AnyRef]
> def typedActorFor(uuid: Uuid): Option[AnyRef]
> def typedActorsFor(id: String): Array[AnyRef]
> def typedActorsFor[T <: AnyRef](implicit manifest: Manifest[T]): Array[AnyRef]
> def typedActorsFor[T <: AnyRef](clazz: Class[T]): Array[AnyRef]
>
> /Jonas
>
> > For more options, visit this group athttp://groups.google.com/group/akka-user?hl=en.
Reply all
Reply to author
Forward
0 new messages