Skip to Content

Create concurrent and distributed applications isn’t a easy task, the Akka Tookit was created to bring the Actors power to JVM, currently SCALA or JAVA can be used as development language. Akka is responsible for delivery the  infrastructure for concurrent, distributed and fault tolerant event driven applications, Akka emphasizes the asynchronous model, Akka can be deployed on servlet container, so it fits on SAP HANA Cloud, to complement the Akka toolkit, another tookit focused on REST services on top of Akka was created (Spray), with this is possible to expose the Akka Actors as Rest services for consumption. To demonstrate how we can use Scala + Akka + Spray on SAP HANA Cloud, I’ve created a simple application that implements a classical Word Count using Map/Reduce using Akka Actors.

The project can be cloned from my Github account: https://github.com/isaias/spray-hana

The build of project is based on SBT, for a simple definition it is like MAVEN and Ant.

To publish a WAR for deploy on SAP HANA Cloud just use the SBT Task package it will generate a WAR that can be deployed directly.

Some attention points:

  • The application.conf must be specificy the root path
  • You will need Console Client

Brief explanation about the Akka Actors of project:

  • MasterActor, it acts like a coordinator of the process, it will receive the chunks of Strings that will be passed for Map Actor.
  • MapActor, this actor receive a String, splits it in words and process the occurrences of each word, after execution MapActor returns the result for MasterActor.
  • ReduceActor, it will consolidate the mapped data that will be used to generate a final reduced list on next Actor, the Aggregator.
  • AggregatorActor, it will create the final Map end decrease a CountDownLatch that is used to indicate that all process was finished.

A CountDownLatch was used to indicate when all words was reduced and are ready to get final result.

To run it using Jetty just use the task container:start at SBT, after open your  browser and call http://localhost:8080 to get a index or http://localhost:8080/wordcount to get a result of a processing using Akka Actors. After executing wordcount we will get a output like bellow:

{

  “youthful”: 1,

  “rage”: 1,

  “looks”: 2,

  “buriest”: 1,

  “decrease,”: 1,

  “ordering;”: 1,

  “sweet”: 8,

  “liquid”: 1,

  “used”: 1,

  “eye”: 2,

  “evident:”: 1,

  “spring,”: 1,

  “silvered”: 1,

  “joy:”: 1,

  “lend,”: 1,

  “comment.”: 1,

  “perfection”: 1,

  “plants”: 1,

  “widow”: 2,

}


Final considerations:

  • To use Eclipse as IDE for Scala development try the Scala IDE plugin (http://scala-ide.org/), there is a plugin that puts a eclipse task on SBT to generate eclipse files (https://github.com/typesafehub/sbteclipse).
  • The Akka documentation is excellent, the quality of both (JAVA and SCALA) are the same
  • For developers of another languages (JAVA, ABAP, Ruby) developing using SCALA can be a great opportunity to get new skills on Functional Programming
  • The Spray documentation isn’t complete like Akka but you can get some help on Google Groups

Spray is also a great option to provide REST services for SAP UI5. For this application spray-routing was used because it is on top of spray-servlet that is indicated to run a Servlet Container.

What do you think about the use of another languages on SAP HANA Cloud?

To report this post you need to login first.

7 Comments

You must be Logged on to comment or reply to a post.

  1. Oliver Roser

    Thanks for your article! This opens a door in the right direction.

     

    (To answer your Question:) … this is the logical next step on the stairwell!

     

    May I add … it will be not just another language: It will be the Akka approach!

    The causality will lead to the obvious bottleneck. Great work M.O. does to prevent this.

     

    So, have to say: Your post is avant-garde on SDN. And it is … a splendid anchor point to spread the word! 😉

    (0) 
  2. Siyavash Habashi

    Hi Isaias,

     

    Thanks, that’s exactly what I was trying to do. Unfortunately, I have tried to deploy this approach locally on HCP and all I got was a blank page or a “resource not found”. There is no problem with the WAR file or the localhost path (set it to ROOT.war).

     

    What did you mean with “The application.conf must be specify the root path”?

     

    Would be cool if u can help me.

     

    Best regards

    (0) 
    1. Isaías Cristiano Barroso Post author

      Hi Siyavash,

       

      The root path is the path that you need to use to access the application.

       

      Im my example it was setted as /spray so the application can be launched locally as http://localhost:8080/spray/wordcount.

       

      My application.conf

       

      akka {

        loglevel = INFO

      }

       

      spray.servlet {

        boot-class = “br.com.strategiatec.spray.hanacloud.Boot”

        request-timeout = 30s

        timeout-timeout = 500 ms

        root-path = “/spray”

        timeout-handler = “”

        remote-address-header = off

        verbose-error-messages = off

        max-content-length = 5 m

      }

       

      Best regards

      (0) 

Leave a Reply