Scala

Supervisor strategy using an exponential back off algorithm

rroestenburg

In this blog post I’m going to show you how you can use an exponential backoff algorithm in combination with a stopping supervisor strategy. In many cases you would like to retry some ‘dangerous operation’, something that can crash, for instance a call to some external service.

The OneForOneStrategy andAllForOneStrategy supervisor strategies have two arguments for a retry window; maxNrOfRetries and withinTimeRange can be used to define a maximum amount of retries within a maximum time range. This retry mechanism retries as soon as possible and does not wait between retries.

In some cases you would like the retry to be delayed so that the failing service does not get overloaded with unnecessary retries; it might be busy recovering and that might take some time. Instead of overloading the failing service with the same request we would like to use an algorithm that decides to wait longer if the dangerous operation keeps failing.

Exponential truncated backoff is such an algorithm which is also used in network congestion avoidance. The algorithm is quite simple:
 Read more

Testing Akka with Specs2

Age Mooij

This year I have been working on several systems based on Akka, usually in combination with the excellent Spray framework to build fully asynchronous actor-driven REST servers. All in all this has been going very well but recently I had to reinvent a certain wheel for the third time (on the third project) so I thought it might be good to blog about it so others can benefit from it too.

The problem is very simple: Akka has great unit test support but unfortunately (for me) that support is based on ScalaTest. Now there is nothing wrong with ScalaTest but personally I prefer to write my tests using Specs2 and it turns out that mixing Akka TestKit with Specs2 is a little tricky. The Akka documentation does mention these problems and it gives a brief overview of ways to work around them, but I could not find any current example code online.
 Read more

Play!: Body parsing with Jerkson

Maarten Winkels

While playing around with the Play! framework today, I stumbled upon the somewhat clunky JSON integration for reading the body of an HTTP request. The recommended approach of using type safe JSON and browsing the tree while creating your custom object or using a Format seems quite cumbersome for most standard situations that the standard libraries Jerkson and Jackson (included in Play!) handle gracefully. In this blog I will describe an approach that uses a custom BodyParser to come to a simpler solution.
 Read more

Scala Lists: Watch your append and prepends

Jeroen van Erp

Today I came across a nice problem in a piece of code one of our colleagues sent around asking for improvements. The problem consists of grouping a large List of lines according to some characteristics. Once the List grew large, the function which took care of the grouping took over 2 minutes to group the dataset. Read more

Apply TDD to Hadoop jobs with Scoobi

Maarten Winkels

Map Reduce is a programming model for writing algorithms that process large quantities of data in a (relatively) short time. The building blocks for the programs are very simple map and reduce functions. Writing programs that do more and more complex tasks to data based on those simple functions becomes harder and harder and thus requires more thorough testing in early stages. This blog attempts to outline a simple method for testing the algorithm of a Map-Reduce program based on scoobi.

 Read more

Easy breezy restful service testing with Dispatch in Scala

Urs Peter

For testing a restful service API I was looking for a lean library, which would allow me to test CRUD operations of rest services with as little code as possible.

My search led me to Dispatch, which is a highly compact Scala DSL wrapper around Apache’s reliable HttpClient. This DSL, however, is not very well documented and rather hard to decipher due to it’s heavy usage of symbolic method names but nevertheless highly appealing when understood.

In this blog I’ll decipher it for you and show how easy it is to test restful services with mere oneliners.

 Read more

Getting the Java out of your Scala, part 2

Jan Vermeir

Getting the Java out of your Scala, part 2

I’m still trying to get rid of old habits, to shake of my winter hide, so to speak, and create some real Scala in stead of ScaVa (i.e. Java with a Scala syntax). If you’re interested you can bear witness to my struggle on GitHub (ShoppingList on GitHub). This story came about because I asked some colleagues for help. We ended up rewriting loops in several ways.
What I’ll show you is some alternatives to classic loops over collections.
 Read more

Comparing Apples to Pears in Scala – or Abstract Types to the Rescue

Urs Peter

Abstract types in Scala can make your life much easier. In this blog I’m going to recap my intellectual journey to compare ‘apples to pears’ in a typesafe manner, which led me to abstract types.

 Read more

Scala ORM with Squeryl – A simple getting started guide

Jeroen van Wilgenburg

Since my pet project (I will eventually blog about that) is in desperate need of a database and I’m doing enough Java on my day job I decided to give a Scala ORM framework a shot.
I have to warn you that I’m kind of a Scala hacker. I abuse it like a scripting language and usually grab some examples, put them together and wait for my colleagues to say “You don’t want that” or “You’re doing it wrong”. So don’t hesitate to correct me, maybe I’ll learn something too ;-)

 Read more

Scala Options the slick way

Thijs Vermeer

The Scala Option type is key for dealing with variables that can have values or not. Most libraries and applications make use of this handy type. However, it’s usage in certain cases can lead to rather verbose code. This blog explains how to deal with this particular case in an elegant way using implicits. Read on to see how easy it is to tailor any kind of existing Scala type to perfectly fit your needs based on an example with Options.
 Read more