I wanted to add a license header to my Scala source code files. It turns out there is a neat sbt plugin called sbt-license-plugin that does just that. Getting it to work took some fiddling around, so I thought I would share it here to save someone else the time and trouble. Continue reading
Author: nidkil
What happened to akka.util.duration?
In a lot of old Akka examples you will see the following statements:
import akka.util.Timeout import akka.util.duration._ implicit val askTimeout = Timeout(1 second)
This will give error ‘object duration is not a member of package akka.util’. It turns out duration is now included in Scala standard library. To fix the error use the following import statement:
import scala.concurrent.duration._
Check out the migration guide for other pieces of Akka functionality that have moved to Scala.
Executing a method defined in a configuration file
I have a class with a method that takes a function as parameter. This function is the strategy that determines how a file is split into chunks. This is the signature of the method.
def split(r: RemoteFileInfo, append: Boolean, workDir: File, strategy: (Long) => Int = defaultStrategy): LinkedHashSet[Chunk] = {
...
}
There is a companion object that provides a number of predefined strategies. I wanted to make the strategy configurable by adding it to the Akka application.conf file. Continue reading
Loading a class dynamically using the DRY principle
I needed to load a bunch of classes dynamically based on a configuration file. As I am a big fan of the Don’t Repeat Yourself (DRY) principle (who isn’t?!?!), I didn’t want to type/copy the same code but use a reusable function. Continue reading
Interesting open source projects to look at
This will be a never ending list of open source projects I want to look into. They look like potential candidates to be used on future projects, but need more thorough analysis.
- Kamon – Reactive Application Monitoring: Kamon is a Open Source set of tools that help you to get metrics out of your reactive applications built on top of Akka, Spray and Play! Kamon uses bytecode instrumentation to introduce metrics and tracing logic into your application, without you having to modify a single line of code. All the collected information is available through a simple, actor-based messaging protocol with integrations already available out of the box.
Any suggestions you think I should look into?
Adding custom application settings to Akka’s configuration file
Just added custom application settings to Akka’s configuration file. Retrieving these settings is kind of a mission. This is the statement to retrieve a setting:
getContext().system().settings().config().getString("downloader.download.forceDelete")
Hmmm, putting these statements everywhere in my code does not feel right, does it? Continue reading
Where is the slf4j encoder pattern documentation?
Wanting to change the way logging information is logged I looked for the slf4j encoder pattern documentation. Why is it so hard to find? It turns out it was not the slf4j documentation I was looking for, but the logback documentation. Duh!
Anyway, it can be found here.
ClassNotFoundException when adding slf4j to Akka
When adding to a Akka project I got the following error java.lang.ClassNotFoundException: akka.event.slf4j.Slf4jLogger. I double checked my configuration and the Akka documentation. The documentation says the following:
Akka provides a logger for SL4FJ. This module is available in the ‘akka-slf4j.jar’. It has one single dependency; the slf4j-api jar. In runtime you also need a SLF4J backend, we recommend Logback.
No success. Continue reading
Adding sources and javadocs of libraries to Eclipse with SBT
With SBT it is possible to download sources and javadocs of libraries. It is really straight forward, just add withSources() and withJavadoc() to the dependency. Continue reading
Retrieving an item from a Seq by index
Feeling a little frustrated as I just spent a considerable amount of time figuring out how to retrieve an item by index from a Seq. Finally figured it out. It can be done using the lift method. This method is also supported by other collections. Continue reading