[akka-user] Type safety

19 views
Skip to first unread message

Oleg Galako

unread,
May 24, 2010, 2:56:41 PM5/24/10
to Akka User List
Hi all!

I like using Scala type system. It helps with refactorings, detecting
errors, etc... You know.

The actor messaging works ok when sending: i use a type safe case
class, but i can't control the result type (at least i dont know how
to do it).

I wonder if its right (not against some kind of ideology behind actors
or any other factors) to implement (for myself) a type safe 'receive'
based on reflection. Something like 'ActorForTrait(class: Class[_])'
with 'receive' method that will accept a 'case class
TraitMessage(methodName: String, params: List[AnyRef])' and invoke the
specified method. Then i'll have a proxy of a trait for sending the
messages and an implementation of the same trait with mixed in
ActorForTrait.

Or maybe it is already implemented somewhere?

I'd like to know your opinions on this.

Thanks in advance.

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

Oleg Galako

unread,
May 25, 2010, 12:34:33 PM5/25/10
to Akka User List
I've found some interesting opinions in a not so long ago thread:
http://groups.google.com/group/akka-user/browse_thread/thread/efeef25c1fd348ba/63d586ba996897e8?#63d586ba996897e8

I'll now try to implement my idea and if it looks/works ok, i'll post
the source here. I think it could be just a really useful tool in the
toolbox.

Jonas Bonér

unread,
May 25, 2010, 1:06:00 PM5/25/10
to akka...@googlegroups.com

Cool. Looking forward to see what you come up with.
I've been thinking of impl an Actor with just one message type and one return type.

trait TypedActor[M,R] { ... }

trait Actor extends TypedActor[Any,Any]

--
Jonas Bonér
http://jayway.com
http://akkasource.com
twitter: jboner

On 25 May 2010 18:48, "Oleg Galako" <ojo...@gmail.com> wrote:

I've found some interesting opinions in a not so long ago thread:
http://groups.google.com/group/akka-user/browse_thread/thread/efeef25c1fd348ba/63d586ba996897e8?#63d586ba996897e8

I'll now try to implement my idea and if it looks/works ok, i'll post
the source here. I think it could be just a really useful tool in the
toolbox.


--
You received this message because you are subscribed to the Google Groups "Akka User List" grou...

Viktor Klang

unread,
May 25, 2010, 1:46:14 PM5/25/10
to akka...@googlegroups.com
On Tue, May 25, 2010 at 6:34 PM, Oleg Galako <ojo...@gmail.com> wrote:
I've found some interesting opinions in a not so long ago thread:
http://groups.google.com/group/akka-user/browse_thread/thread/efeef25c1fd348ba/63d586ba996897e8?#63d586ba996897e8

I'll now try to implement my idea and if it looks/works ok, i'll post
the source here. I think it could be just a really useful tool in the
toolbox.

I've got some code laying around if you want some inspiration/deterrent ;-)

Looking forward to see what you can do!
 

--
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
| "A complex system that works is invariably
| found to have evolved from a simple system
| that worked." - John Gall

Akka - the Actor Kernel: Akkasource.org
Twttr: twitter.com/viktorklang

Oleg Galako

unread,
May 25, 2010, 2:38:28 PM5/25/10
to Akka User List
Here is a draft: http://pastie.org/976693

But it would be preferable to tie the type of the proxied object to
ActorRef. So we could replace ProxyForActor(classOf[SampleClass], a)
with something like just a.proxy

Dustin Whitney

unread,
May 25, 2010, 3:08:40 PM5/25/10
to akka...@googlegroups.com
That looks like Jonas's idea for an actor that receives on type of message?

The problem is an actor that only accepts one message is kind of annoying.  It'd require a lot more classes and instances to accomplish one logical act than an actor that accepts multiple messages. 

Just thinking out loud since I don't even know if this is possible, or even where to begin:  is it possible to write a compiler plugin that inspects the receive statement for the types of messages it receives, and then checks that all sends match the respective types?  That would be more useful than an actor that only receives on message.

Dustin

Oleg Galako

unread,
May 25, 2010, 11:21:48 PM5/25/10
to Akka User List
You can have many methods (with typed arguments and return values),
and you use an actor by calling methods on a proxy. So i don't think
it looks like an actor that receives one type of message. And also you
can extend it and override the receive method to handle more message
types where needed.

The main point is that you can use actors by calling type safe methods
you define on a class. Annotations could help here too for marking
methods that will be proxied (i didnt include annotations in my code
to make it shorter to express the main idea).

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

Jonas Bonér

unread,
May 26, 2010, 1:37:14 AM5/26/10
to akka...@googlegroups.com
Cool. 

However, this is what I do now in the Active Object API. 
You can take a POJO:

class POJO {
  def foo(bar: Bar): Baz = { 
    ...// use Bar directly, return Baz
  }
}

val pojo = ActiveObject.newInstance(classOf[POJO])

val baz: Baz = pojo.foo(new Bar)

And it is using AspectWerkz proxy which is more performant than CGLIB.

/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

work:   http://jayway.com
code:   http://akkasource.com
blog:    http://jonasboner.com
twitter: @jboner




Oleg Galako

unread,
May 26, 2010, 2:34:36 AM5/26/10
to Akka User List
I see, but why is it called "Java API" then? Its just a type safe
approach to actors and nothing against Scala, right?

I didn't even look at it because i thought its some kind of a limited
version for Java.

Oleg Galako

unread,
May 26, 2010, 4:03:43 AM5/26/10
to Akka User List
I still don't understand why type safety was discussed in the thread
mentioned above then. Do ActiveObjects miss any important features? If
so maybe its better to separate the ActiveObject approach and Java API
(in case Java limitations don't allow to express it as full as we want
for Scala)?

I think the answers to these questions could be useful to all who read
the Actor/ActiveObject documentation and should be added there.

Jonas Bonér

unread,
May 28, 2010, 4:28:01 AM5/28/10
to akka...@googlegroups.com
Hi Oleg.

That is a valid question.

I have never thought about them being a type-safe alt. Which they of
course are. I think we have to market them better.

I like the POJO-based approach to Actors a lot. But since Akka was
born in the Scala community is is just naturally be more focus on the
Scala Erlang-style way of doing actors.

The main goal for the next release is to make the POJO style (and Java
integration) as a good the Erlang-style Actors can every regard.

Thanks for your ideas and thoughts.

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

Oleg Galako

unread,
May 28, 2010, 4:43:12 AM5/28/10
to Akka User List
Awesome!

And thanks again for your answers. I'm not an old enterprise pro with
huge experience, just trying to grasp the cool new things so your
answer was really helpful.
> > For more options, visit this group athttp://groups.google.com/group/akka-user?hl=en.

Jonas Bonér

unread,
May 28, 2010, 4:45:56 AM5/28/10
to akka...@googlegroups.com
On 28 May 2010 10:43, Oleg Galako <ojo...@gmail.com> wrote:
> Awesome!
>
> And thanks again for your answers. I'm not an old enterprise pro with
> huge experience, just trying to grasp the cool new things so your
> answer was really helpful.
>

So is your feedback. Very valuable. Keep it coming :-)

Reply all
Reply to author
Forward
0 new messages