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
 

Get Programming Concurrency on the JVM now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.