Thursday, April 16, 2015

Scala Future Callback for Apache HTTP Async Client

In a recent project, I needed an asynchronous HTTP client and due to some other requirements, I decided to use the Apache Async HTTP Client. The problem is, that the Async HTTP Client uses Java's Future implementation:
"The result can only be retrieved using method get when the computation has completed, blocking if necessary until it is ready." [Java Futures]
An example code snippet demonstrates how to send an asynchronous HTTP request. To make a long story short: accessing the result of the Future means we block the current thread. An alternative solution is to use the Apache FutureCallback interface, which also lacks the ability to access the result of the future in a non-blocking way (see example). Hence: the provided functionality does not scale well in highly concurrent environments.

After I discussed the problem with a collegue, he came up with a pretty cool solution that prepares the ground for Scala Futures. The trick is to implement the FutureCallback interface by using a Scala Promise:

class ScalaFutureCallbackImpl[T] extends FutureCallback[T] {
  private val promise: Promise[T] = Promise()


  def cancelled(): Unit = 

     promise.failure(new RuntimeException("cancelled!"))

  def completed(result: T): Unit = promise.success(result)


  def failed(ex: Exception): Unit = promise.failure(ex)


  def getScalaFuture: Future[T] = promise.future
}


Its interesting to see, how perfect the methods from the interface can be mapped to the corresponding Promise methods. The additional method getScalaFuture is necessary to give the caller access to the underlying Scala Future. With the new implementation, we are now able to use the Apache Async HTTP Client in a more convenient way:

val httpclient = HttpAsyncClients.createDefault()
val callback = new ScalaFutureCallbackImpl[HttpResponse]
httpClient.execute(host, request, context, callback)

for {
   httpResponse <- callback.getScalaFuture

}
yield httpResponse

Thursday, January 8, 2015

Thinkpad T410 Wireless (Intel Centrino Advanced-N 6200 AGN) and Debian Wheezy

It might happen that your T410 wireless doesn't work after installing Debian, because you didn't have the non-free firmware at hand.

You'll find the missing firmware at the packages site. After you downloaded and decompressed the tarball put the file iwlwifi-6000-4.ucode-9.221.4.1 into /lib/firmware and create a symlink:

# ln -s iwlwifi-6000-4.ucode-9.221.4.1 iwlwifi-6000-4.ucode

Now, its time to reboot!

Friday, December 19, 2014

Scala Maven Project including Specs2

Since I found no up-to-date Maven Project for Scala that includes everything I want (especially Specs2), I created my own one on GitHub. There's a problem with some versions of Specs2, because org.scalaz.stream cannot be found. Due to that issue, the project currenty uses Specs 2.4 (for Scala 2.11).

Tuesday, December 16, 2014

Updating Adobe Flash Plugin on Debian Wheezy

After my Iceweasel (Firefox) was telling me several times that the Adobe Flash Plugin is vulnerable and needs to be updated (Chromium wasn't complaining at all), I was wondering why no update is being installed when running APT?

Fortunately, the Debian Wiki explains how to update the Adobe Flash Plugin:

~# update-flashplugin-nonfree --install

Thursday, December 11, 2014

Published 'admintools' on GitHub

Some helpful scripts for system administrators are now available on GitHub.

Wednesday, December 3, 2014

IMAP over SSLv2 - Evolution Mail does not work on Debian 7.7 Wheezy: Enable TLS over port 993

After my email provider disabled SSLv3 for IMAP due to that security problem known as Poodle, Evolution Mail 3.4.4 on my Debian 7.7 Wheezy stopped working. Since there's no "ready-to-install" patch available yet, I rolled my own solution. [1] describes a patch that needs to be applied to the evolution-data-server and therefore we need to build evolution-data-server from the sources available through APT. In [2] there's a step-by-step howto, that explains how to build a APT package. I augmented those steps with the steps that were missing to build a patched evolution-data-server.

  1. su -
  2. create a new directory and cd into it 
  3. apt-get build-dep evolution-data-server
  4. apt-get source evolution-data-server
  5. cd evolution-data-server-3.4.4
  6. apply patch as described in [1]
  7. dpkg-source --commit (e.g. "Enable TLS over port 993)
  8. maybe: install fakeroot and dpkg-dev
    • apt-get install fakeroot
    • apt-get install dpkg-dev
  9. dpkg-buildpackage -rfakeroot
  10. cd ..
  11. dpkg -i *.deb

[1] evolution-data-server-3.10.4-poodle-enable-tls-for-ssl.patch for bug #1153052

[2] Re: [Evolution] my Evolution 3.6.2 backport to Ubuntu 10.12

Dynamic Packaging Prototype on GitHub

Something that I should have done in the past, but due to a lack of something that I consider "interesting" or worse to bore the world with it...at the end I never open sourced anything. But this will change now!

The first project that I gonna open source is an implementation of a distributed web-server written with Scala, Akka and Spray during my Master Thesis last year. The aim of the project was to implement a prototype for a "Dynamic Packaging" application, which is commonly used in the travel and tourism industry. I used the prototype mainly to do measurements and evaluate how Akka performs in terms of CPU utilization and horizontal scaling. I wouldn't necessarily recommend to use the project for "mission critical" things, but more as a source for ideas.

- Dynamic Packaging Prototype (server)
- Dynamic Packaging Prototype (client)