I'm a Ruby dev, not a Java dev and so I'm trying to find up to date examples of using the Scala Akka library with JRuby but coming up short.
I've got the following code in place...
require "java"
[
"akka-2.3.8/lib/scala-library-2.11.4.jar",
"akka-2.3.8/lib/akka/akka-actor_2.11-2.3.8.jar",
"akka-2.3.8/lib/akka/config-1.2.1.jar"
].each { |lib| $CLASSPATH << lib }
java_import java.lang.System
java_import "java.io.Serializable"
java_import "akka.actor.ActorRef"
java_import "akka.actor.ActorSystem"
java_import "akka.actor.Props"
java_import "akka.actor.UntypedActor"
class Greeting
include Serializable
attr_reader :who
def initialize(who)
@who = who
end
end
class GreetingActor < UntypedActor
class << self
alias_method :apply, :new
alias_method :create, :new
end
def onReceive(message)
puts "Hello " + message.who
end
end
system = ActorSystem.create("GreetingSystem") # <Java::AkkaActor::ActorSystemImpl:0x68c9133c>
props = Props.new(GreetingActor) # Java::AkkaActor::Props
greeter = system.actorOf(props, "greeter");
greeter.tell(Greeting.new("Rocky Jaiswal"));
system.shutdown
system.await_termination
...but this is causing the following error...
ArgumentError: wrong number of arguments (1 for 3)
(root) at size.rb:39
This error is caused by Props.new(GreetingActor) but reading through the documentation for Akka it's not clear how to translate that code over to Ruby.
Does anyone know how to resolve this issue? Looking at http://doc.akka.io/api/akka/2.3.1/index.html#akka.actor.Props I can't see how this correlates/maps over to Ruby code.
I'm aware of the Celluloid ruby library, but I wanted to see how to implement the Actor pattern using more low level code. It seems to be more awkward than I initially imagined.