O'Reilly logo

Programming Concurrency on the JVM by Venkat Subramaniam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

JRuby Akka Integration

To use Akka in JRuby, we’ll follow along the same lines as we did in Java. The main difference is we’ll be able to benefit from JRuby conciseness. We’re already familiar with the capabilities of Akka and its powerful API from Chapter 8, Favoring Isolated Mutability. Let’s jump right into implementing the design in Coordinating Actors for the file size program in JRuby. Remember, we need a bunch of message types, two actor types, and some main code to exercise these. Let’s start with the message types first:

polyglotActors/jruby/FileSize.rb
 
class​ RequestAFile; ​end
 
 
class​ FileSize
 
attr_reader :size
 
def​ initialize(size)
 
@size = size
 
end
 
end
 
 
class​ FileToProcess
 
attr_reader :file_name
 

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required