<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:iweb="http://www.apple.com/iweb" version="2.0">
  <channel>
    <title>The adventures of a software architect</title>
    <link>http://www.davidgreco.it/MySite/Blog/Blog.html</link>
    <description>I have the chance to challenge myself with very complex software systems and it’s always for me to choose the right tools, technologies and architectures. I know, it’s really a tough task, at least for me, but this is what I like most. My blog tries to describe this continuous effort to become a good software architect.&lt;br/&gt;Disclaimer:&lt;br/&gt;The views expressed in this blog are solely the personal views of the author and DO NOT represent the views of his employer or any third party.&lt;br/&gt;&lt;br/&gt;</description>
    <generator>iWeb 3.0.4</generator>
    <item>
      <title>Having fun with Scala, part 1</title>
      <link>http://www.davidgreco.it/MySite/Blog/Entries/2011/9/30_Having_fun_with_Scala,_part_1.html</link>
      <guid isPermaLink="false">a9985259-f70e-4bbf-9fc6-62fc4b9e4ce1</guid>
      <pubDate>Fri, 30 Sep 2011 11:07:49 +0200</pubDate>
      <description>Developing enterprise applications there is a recurring problem, how to simply manage orthogonal concerns like auditing, logging, authentication, etc. A typical approach is just using an AOP technology, sure, AOP it works but sometime it’s just an overkilling. In my experience, often, we just need a simple mechanism to intercept calls in the service layer, i.e. in the implementation of a REST/WS interface.&lt;br/&gt;So, as an exercise, I tried to implement a simple interception framework using Scala, and since the code worths thousands words here you are the result of my effort:&lt;br/&gt;&lt;br/&gt;package it.davidgreco.scalaexperiments&lt;br/&gt;&lt;br/&gt;import collection.mutable.HashMap&lt;br/&gt;import java.lang.reflect.Method&lt;br/&gt;&lt;br/&gt;private[scalaexperiments] trait ReadWriteLock {&lt;br/&gt;  private val lock = new java.util.concurrent.locks.ReentrantReadWriteLock&lt;br/&gt;&lt;br/&gt;  def writeLock[S](f: =&gt; S): S = {&lt;br/&gt;    lock.writeLock.lock()&lt;br/&gt;    try {&lt;br/&gt;      f&lt;br/&gt;    }&lt;br/&gt;    finally {&lt;br/&gt;      lock.writeLock.unlock()&lt;br/&gt;    }&lt;br/&gt;  }&lt;br/&gt;&lt;br/&gt;  def readLock[S](f: =&gt; S): S = {&lt;br/&gt;    lock.readLock.lock()&lt;br/&gt;    try {&lt;br/&gt;      f&lt;br/&gt;    }&lt;br/&gt;    finally {&lt;br/&gt;      lock.readLock.unlock()&lt;br/&gt;    }&lt;br/&gt;  }&lt;br/&gt;}&lt;br/&gt;&lt;br/&gt;object Interceptable extends ReadWriteLock {&lt;br/&gt;&lt;br/&gt;  type PreInterceptor = Interceptable =&gt; Unit&lt;br/&gt;  type PostInterceptor = PreInterceptor&lt;br/&gt;  type AroundInterceptor = Interceptable =&gt; (=&gt; Any) =&gt; Any&lt;br/&gt;&lt;br/&gt;  var preInterceptors = new Array[Option[PreInterceptor]](5)&lt;br/&gt;  var preInterceptorsNamePosition = new HashMap[String, Int]&lt;br/&gt;&lt;br/&gt;  var postInterceptors = new Array[Option[PostInterceptor]](5)&lt;br/&gt;  var postInterceptorsNamePosition = new HashMap[String, Int]&lt;br/&gt;&lt;br/&gt;  var aroundInterceptors = new Array[AroundInterceptor](5)&lt;br/&gt;  var aroundInterceptorsNamePosition = new HashMap[String, Int]&lt;br/&gt;&lt;br/&gt;  def registerPreInterceptor(pos: Int, name: String, interceptor: PreInterceptor): Unit = {&lt;br/&gt;    writeLock {&lt;br/&gt;      preInterceptorsNamePosition += name -&gt; pos&lt;br/&gt;      preInterceptors.update(pos, Some(interceptor))&lt;br/&gt;    }&lt;br/&gt;  }&lt;br/&gt;&lt;br/&gt;  def unregisterPreInterceptor(pos: Int) {&lt;br/&gt;    writeLock {&lt;br/&gt;      preInterceptors.update(pos, None)&lt;br/&gt;      val name = (for (p &amp;lt;- preInterceptorsNamePosition; if (p._2 == pos)) yield p._1).toList.head&lt;br/&gt;      preInterceptorsNamePosition.remove(name)&lt;br/&gt;    }&lt;br/&gt;  }&lt;br/&gt;&lt;br/&gt;  def unregisterPreInterceptor(name: String) {&lt;br/&gt;    writeLock {&lt;br/&gt;      val p = preInterceptorsNamePosition.get(name)&lt;br/&gt;      for (pos &amp;lt;- p) {&lt;br/&gt;        preInterceptors.update(pos, None)&lt;br/&gt;        preInterceptorsNamePosition.remove(name)&lt;br/&gt;      }&lt;br/&gt;    }&lt;br/&gt;  }&lt;br/&gt;&lt;br/&gt;  def registerPostInterceptor(pos: Int, name: String, interceptor: PostInterceptor): Unit = {&lt;br/&gt;    writeLock {&lt;br/&gt;      postInterceptorsNamePosition += name -&gt; pos&lt;br/&gt;      postInterceptors.update(pos, Some(interceptor))&lt;br/&gt;    }&lt;br/&gt;  }&lt;br/&gt;&lt;br/&gt;  def unregisterPostInterceptor(pos: Int) {&lt;br/&gt;    writeLock {&lt;br/&gt;      postInterceptors.update(pos, None)&lt;br/&gt;      val name = (for (p &amp;lt;- postInterceptorsNamePosition; if (p._2 == pos)) yield p._1).toList.head&lt;br/&gt;      postInterceptorsNamePosition.remove(name)&lt;br/&gt;    }&lt;br/&gt;  }&lt;br/&gt;&lt;br/&gt;  def unregisterPostInterceptor(name: String) {&lt;br/&gt;    writeLock {&lt;br/&gt;      val p = postInterceptorsNamePosition.get(name)&lt;br/&gt;      for (pos &amp;lt;- p) {&lt;br/&gt;        postInterceptors.update(pos, None)&lt;br/&gt;        postInterceptorsNamePosition.remove(name)&lt;br/&gt;      }&lt;br/&gt;    }&lt;br/&gt;  }&lt;br/&gt;&lt;br/&gt;  def registerAroundInterceptor(pos: Int, name: String, interceptor: AroundInterceptor): Unit = {&lt;br/&gt;    writeLock {&lt;br/&gt;      aroundInterceptorsNamePosition += name -&gt; pos&lt;br/&gt;      aroundInterceptors.update(pos, interceptor)&lt;br/&gt;    }&lt;br/&gt;  }&lt;br/&gt;&lt;br/&gt;  def unregisterAroundInterceptor(pos: Int) {&lt;br/&gt;    writeLock {&lt;br/&gt;      aroundInterceptors.update(pos, identityAroundInterceptor)&lt;br/&gt;      val name = (for (p &amp;lt;- aroundInterceptorsNamePosition; if (p._2 == pos)) yield p._1).toList.head&lt;br/&gt;      aroundInterceptorsNamePosition.remove(name)&lt;br/&gt;    }&lt;br/&gt;  }&lt;br/&gt;&lt;br/&gt;  def unregisterAroundInterceptor(name: String) {&lt;br/&gt;    writeLock {&lt;br/&gt;      val p = aroundInterceptorsNamePosition.get(name)&lt;br/&gt;      for (pos &amp;lt;- p) {&lt;br/&gt;        aroundInterceptors.update(pos, identityAroundInterceptor)&lt;br/&gt;        aroundInterceptorsNamePosition.remove(name)&lt;br/&gt;      }&lt;br/&gt;    }&lt;br/&gt;  }&lt;br/&gt;&lt;br/&gt;  private[Interceptable] def identityAroundInterceptor[A](interceptable: Interceptable)(x: =&gt; A): A = {&lt;br/&gt;    x&lt;br/&gt;  }&lt;br/&gt;&lt;br/&gt;  for (i &amp;lt;- 0 until preInterceptors.size) {&lt;br/&gt;    preInterceptors.update(i, None)&lt;br/&gt;  }&lt;br/&gt;&lt;br/&gt;  for (i &amp;lt;- 0 until postInterceptors.size) {&lt;br/&gt;    postInterceptors.update(i, None)&lt;br/&gt;  }&lt;br/&gt;&lt;br/&gt;  for (i &amp;lt;- 0 until aroundInterceptors.size) {&lt;br/&gt;    aroundInterceptors.update(i, identityAroundInterceptor)&lt;br/&gt;  }&lt;br/&gt;}&lt;br/&gt;&lt;br/&gt;trait Interceptable {&lt;br/&gt;&lt;br/&gt;  self =&gt;&lt;br/&gt;&lt;br/&gt;  import Interceptable._&lt;br/&gt;&lt;br/&gt;  def intercept[A](block: =&gt; A): A = {&lt;br/&gt;&lt;br/&gt;/*&lt;br/&gt;    val exc = new Exception&lt;br/&gt;    val st = exc.getStackTrace&lt;br/&gt;    val ste = st.apply(2)&lt;br/&gt;&lt;br/&gt;    val cls = Class.forName(ste.getClassName())&lt;br/&gt;    var back: Method = null&lt;br/&gt;&lt;br/&gt;    cls.getDeclaredMethods().foreach {&lt;br/&gt;      m: Method =&gt;&lt;br/&gt;        if (back == null &amp;amp;&amp;amp; m.getName() == ste.getMethodName()) {&lt;br/&gt;          back = m&lt;br/&gt;        }&lt;br/&gt;    }&lt;br/&gt;*/&lt;br/&gt;&lt;br/&gt;    readLock {&lt;br/&gt;      for (f &amp;lt;- Interceptable.preInterceptors; if (f.isDefined)) {&lt;br/&gt;        f.get(this)&lt;br/&gt;      }&lt;br/&gt;    }&lt;br/&gt;&lt;br/&gt;    val a = readLock {&lt;br/&gt;      aroundInterceptors.apply(4)(self)(aroundInterceptors.apply(3)(self)(aroundInterceptors.apply(2)(self)(aroundInterceptors.apply(1)(self)(aroundInterceptors.apply(0)(self)(block)))))&lt;br/&gt;    }&lt;br/&gt;&lt;br/&gt;    readLock {&lt;br/&gt;      for (f &amp;lt;- Interceptable.postInterceptors; if (f.isDefined)) {&lt;br/&gt;        f.get(this)&lt;br/&gt;      }&lt;br/&gt;    }&lt;br/&gt;&lt;br/&gt;    a.asInstanceOf[A]&lt;br/&gt;  }&lt;br/&gt;&lt;br/&gt;}&lt;br/&gt;&lt;br/&gt;class MyClass extends Interceptable {&lt;br/&gt;&lt;br/&gt;  def method(i: Int): Unit = intercept {&lt;br/&gt;    println(&amp;quot;Method &amp;quot; + i)&lt;br/&gt;  }&lt;br/&gt;&lt;br/&gt;  def methodWithInterception = intercept {}&lt;br/&gt;&lt;br/&gt;  def methodWithoutInterception = {}&lt;br/&gt;&lt;br/&gt;}&lt;br/&gt;&lt;br/&gt;object Main {&lt;br/&gt;&lt;br/&gt;  import Interceptable._&lt;br/&gt;&lt;br/&gt;  def main(args: Array[String]) {&lt;br/&gt;&lt;br/&gt;    registerPreInterceptor(1, &amp;quot;MyPreInterceptor&amp;quot;, (x: Interceptable) =&gt; {&lt;br/&gt;      println(&amp;quot;PRE_INTERCEPTED&amp;quot;)&lt;br/&gt;    })&lt;br/&gt;&lt;br/&gt;    registerPostInterceptor(1, &amp;quot;MyPostInterceptor&amp;quot;, (x: Interceptable) =&gt; {&lt;br/&gt;      println(&amp;quot;POST_INTERCEPTED&amp;quot;)&lt;br/&gt;    })&lt;br/&gt;&lt;br/&gt;    def dummyAroundInterceptor1[A](interceptable: Any)(x: =&gt; A): A = {&lt;br/&gt;      println(&amp;quot;BEFORE_1&amp;quot;);&lt;br/&gt;      val a = x;&lt;br/&gt;      println(&amp;quot;AFTER_1&amp;quot;);&lt;br/&gt;      a&lt;br/&gt;    }&lt;br/&gt;&lt;br/&gt;    def dummyAroundInterceptor2[A](interceptable: Any)(x: =&gt; A): A = {&lt;br/&gt;      println(&amp;quot;BEFORE_2&amp;quot;);&lt;br/&gt;      val a = x;&lt;br/&gt;      println(&amp;quot;AFTER_2&amp;quot;);&lt;br/&gt;      a&lt;br/&gt;    }&lt;br/&gt;&lt;br/&gt;    registerAroundInterceptor(0, &amp;quot;DUMMY1&amp;quot;, dummyAroundInterceptor1)&lt;br/&gt;    registerAroundInterceptor(1, &amp;quot;DUMMY2&amp;quot;, dummyAroundInterceptor2)&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;    val a = new MyClass&lt;br/&gt;&lt;br/&gt;    a.method(1)&lt;br/&gt;&lt;br/&gt;    unregisterAroundInterceptor(0)&lt;br/&gt;    unregisterAroundInterceptor(1)&lt;br/&gt;&lt;br/&gt;    unregisterPreInterceptor(1)&lt;br/&gt;    unregisterPostInterceptor(1)&lt;br/&gt;&lt;br/&gt;    a.method(2)&lt;br/&gt;&lt;br/&gt;    val start = System.currentTimeMillis()&lt;br/&gt;    for (i &amp;lt;- 1 to 1000000) {&lt;br/&gt;      a.methodWithoutInterception&lt;br/&gt;    }&lt;br/&gt;    val stop1 = System.currentTimeMillis()&lt;br/&gt;    println(stop1 - start)&lt;br/&gt;&lt;br/&gt;    for (i &amp;lt;- 1 to 1000000) {&lt;br/&gt;      a.methodWithInterception&lt;br/&gt;    }&lt;br/&gt;    val stop2 = System.currentTimeMillis()&lt;br/&gt;    println(stop2 - stop1)&lt;br/&gt;&lt;br/&gt;    println(stop2 - 2 * stop1 + start)&lt;br/&gt;&lt;br/&gt;  }&lt;br/&gt;&lt;br/&gt;}&lt;br/&gt;&lt;br/&gt;I’m pretty sure that there are better ways for doing the same thing, I’m still on the learning curve and I would really like to have your comments on how this could be improved.&lt;br/&gt;What I like is the fact that I found a way to implement also the around interceptor mechanism which is pretty useful if, for example, you want to measure the execution time for a method call.&lt;br/&gt;Anyway, Scala is such a great language!</description>
    </item>
    <item>
      <title>Scala and JPA: a couple of hints</title>
      <link>http://www.davidgreco.it/MySite/Blog/Entries/2011/2/16_Scala_and_JPA__a_couple_of_hints.html</link>
      <guid isPermaLink="false">a1aadd55-2c2d-4fe8-8e51-4e19ade1cbf4</guid>
      <pubDate>Wed, 16 Feb 2011 17:43:09 +0100</pubDate>
      <description>At work we are developing an application using Scala, during the design phase we had to decide which ORM was better for our purposes. Our first choice was &lt;a href=&quot;http://squeryl.org/&quot;&gt;Squeryl&lt;/a&gt;, it;s a pure Scala based ORM and it’s great, however we thought that it was still on a early stage of development and we didn’t want to add additional risk to our development (we are still a young Scala shop here). Then, we opted to use JPA.&lt;br/&gt;When first I tried to combine Scala with JPA it was pretty weird, Scala 2.7.x used to have a bad support for Java annotations. Now, it works perfectly and what I really like is that it’s possible to use JPA together with immutable case classes, I don’t want to repeat how good is to use immutable objects especially in the functional world. Even with JPA entities we have the full power of pattern matching, really great!&lt;br/&gt;After some investigation I and my colleague Martin we found the solution.&lt;br/&gt;Below I put just a quick example of an immutable case class with the needed JPA annotations:&lt;br/&gt;&lt;br/&gt;@Entity&lt;br/&gt;@Table(name=&amp;quot;devices&amp;quot;)&lt;br/&gt;case class Device(&lt;br/&gt;&lt;br/&gt;  @(Id @field)&lt;br/&gt;  @(GeneratedValue @field)&lt;br/&gt;  @(Column @field)(columnDefinition=&amp;quot;int(11)&amp;quot;)&lt;br/&gt;  id: Long,&lt;br/&gt;&lt;br/&gt;  @(Column @field)(unique=true, columnDefinition=&amp;quot;varchar(255)&amp;quot;)&lt;br/&gt;  @(Index @field)(name=&amp;quot;index_devices_on_machine_id&amp;quot;)&lt;br/&gt;  deviceMachineId: String,&lt;br/&gt;&lt;br/&gt;  @(Type @field)&lt;br/&gt;  @(Column @field)(columnDefinition=&amp;quot;int(10)&amp;quot;)&lt;br/&gt;  fcd: Long {&lt;br/&gt;&lt;br/&gt;  def this() = this (0L, &amp;quot;&amp;quot;,  0L)&lt;br/&gt;}&lt;br/&gt;&lt;br/&gt;the trick is to use the Scala nested annotations to force the compiler to generate setters and getters even if the case class is immutable, &lt;a href=&quot;http://www.scala-lang.org/api/rc/scala/annotation/target/field.html&quot;&gt;@field&lt;/a&gt; annotation does that.&lt;br/&gt;And you have also to add a default constructor. Pretty simple no?</description>
    </item>
    <item>
      <title>I started climbing the Akka mountain</title>
      <link>http://www.davidgreco.it/MySite/Blog/Entries/2011/1/6_I_started_to_climb_the_Akka_mountain.html</link>
      <guid isPermaLink="false">883db36a-c7b6-44c4-a0eb-224e816dedd7</guid>
      <pubDate>Thu, 6 Jan 2011 18:01:11 +0100</pubDate>
      <description>One of the reasons why I like the Scala language is the fact that in the Scala community you can find people like Jonas Bonér and Viktor Klang. Those people created a great framework: &lt;a href=&quot;http://akka.io/&quot;&gt;Akka&lt;/a&gt; &lt;br/&gt;The Akka framework provides an extremely fast and scalable actor implementation. It provides also other interesting goodies, but I don’t want to bother with too much details the Akka site is plenty of documentation and it’s not so difficult to find examples around.&lt;br/&gt;I had the chance to contribute to the Akka framework and for me it was really nice to be able to add a couple of small pieces to it.&lt;br/&gt;One of the things I really appreciate of Akka is the easiness in setting up a Scala project based on &lt;a href=&quot;http://code.google.com/p/simple-build-tool/&quot;&gt;SBT&lt;/a&gt; (Simple Build Tool) and &lt;a href=&quot;http://www.jetbrains.com/idea/&quot;&gt;Idea&lt;/a&gt; as the IDE thanks to this wonderful sbt plugin &lt;a href=&quot;https://github.com/mpeltonen/sbt-idea&quot;&gt;sbt-idea&lt;/a&gt;.&lt;br/&gt;I think that the combination of SBT and Idea is the best environment for developing Scala based applications.&lt;br/&gt;In this post I’ll give you some hints on how to quickly set up an Akka based project using SBT as a building tool and Idea as the preferred tool.&lt;br/&gt;So, let’s start with the various steps. On a shell start to type the following commands (Unix/Linux):&lt;br/&gt;	1)	mkdir akka-template&lt;br/&gt;	2)	cd akka-template&lt;br/&gt;	3)	sbt &lt;br/&gt;Running the command above, sbt will ask you a couple of questions, you can just reply: y, akka-template, myorganization for example, the meaning is pretty obvious.  &lt;br/&gt;	1)	Then, under the sbt console, just type exit&lt;br/&gt;&lt;br/&gt;You should still be under the akka-template directory, so just create two additional directories (under the akka-template directory):&lt;br/&gt;	1)	mkdir project/build&lt;br/&gt;	2)	mkdir project/plugins&lt;br/&gt;&lt;br/&gt;Under the directory akka-template/project/build put a file names akka-template.scala for example with the following content:&lt;br/&gt;&lt;br/&gt;import sbt._&lt;br/&gt;&lt;br/&gt;class AkkaTemplate(info: ProjectInfo) extends DefaultWebProject(info) with AkkaProject {&lt;br/&gt;&lt;br/&gt;  val akka_repo = &amp;quot;Akka Maven Repository&amp;quot; at &amp;quot;&lt;a href=&quot;http://akka.io/repository&quot;&gt;http://akka.io/repository&lt;/a&gt;&amp;quot;&lt;br/&gt;&lt;br/&gt;  val akkaHttp = akkaModule(&amp;quot;http&amp;quot;)&lt;br/&gt;&lt;br/&gt;  val jetty7Server = &amp;quot;org.eclipse.jetty&amp;quot; % &amp;quot;jetty-server&amp;quot; % &amp;quot;7.0.1.v20091125&amp;quot; % &amp;quot;test&amp;quot;&lt;br/&gt;  val jetty7WebApp = &amp;quot;org.eclipse.jetty&amp;quot; % &amp;quot;jetty-webapp&amp;quot; % &amp;quot;7.0.1.v20091125&amp;quot; % &amp;quot;test&amp;quot;&lt;br/&gt;}&lt;br/&gt;&lt;br/&gt;This file represents the actual project build configuration for sbt.&lt;br/&gt;Then, under the directory akka-template/project/plugins put a file named Plugins.scala with the following content:&lt;br/&gt;&lt;br/&gt;import sbt._&lt;br/&gt;&lt;br/&gt;class Plugins(info: ProjectInfo) extends PluginDefinition(info) {&lt;br/&gt;  val akka_repo  = &amp;quot;Akka Maven Repository&amp;quot; at &amp;quot;&lt;a href=&quot;http://akka.io/repository&quot;&gt;http://akka.io/repository&lt;/a&gt;&amp;quot;&lt;br/&gt;  val akkaPlugin = &amp;quot;se.scalablesolutions.akka&amp;quot; % &amp;quot;akka-sbt-plugin&amp;quot; % &amp;quot;1.0-RC2&amp;quot;&lt;br/&gt;}&lt;br/&gt;&lt;br/&gt;This file allows adding additional SBT plugins useful for doing specific building actions. In this specific example you are including the Akka specific plugin.&lt;br/&gt;This specific plugin provides an AkkaProject trait which allows to add Akka modules with their dependencies automatically into your project. In the file akka-template.scala above, you can notice  the line:&lt;br/&gt;    val akkaHttp = akkaModule(&amp;quot;http&amp;quot;)&lt;br/&gt;that means that the web project is using the Akka REST module. In this way you have everything for implementing a REST based application with all the JAX-RS goodies, backed by the powerful Akka actors.&lt;br/&gt;The last step is to run again sbt under the akka-template directory. Under the sbt shell type:&lt;br/&gt;&gt; idea &lt;br/&gt;&lt;br/&gt;That sbt action will create all the needed artifacts for the Idea IDE. Now you can open the project under Idea, that’s it.&lt;br/&gt;I really hope it will be useful for you to start climbing the great Akka mountain ;)&lt;br/&gt;</description>
    </item>
    <item>
      <title>My stairway to the cloud</title>
      <link>http://www.davidgreco.it/MySite/Blog/Entries/2010/7/2_My_stairway_to_the_cloud.html</link>
      <guid isPermaLink="false">8e3b0b60-88aa-49b0-80c5-6d77b6d4bc33</guid>
      <pubDate>Fri, 2 Jul 2010 13:49:18 +0200</pubDate>
      <description>In the last couple of weeks, probably influenced by the hype around that word, I decided to learn a little bit more about cloud computing.&lt;br/&gt;I was already a subscriber of the Amazon EC2 service but I never got the chance to play with it, so I decided to give it a try.&lt;br/&gt;My experience with EC2 has been very positive and I had also the chance to play a lot with the &lt;a href=&quot;http://www.eucalyptus.com/&quot;&gt;Eucalyptus&lt;/a&gt; product which is a sort of “clone” of EC2.&lt;br/&gt;Frankly speaking the word “Cloud” is really over exposed, too much marketing, too much business “noise” around, it remembers me when SOA was like the cure for every IT disease, but like SOA, cloud computing is just a paradigm shift, it’s an evolution of something we have already, like SOA is an architectural pattern evolved from the concept of component based architecture.&lt;br/&gt;I think that cloud computing is just an evolution of the concept of virtualization which is not new, the concept of virtual machine is around since the advent of the IBM VM370 architecture in the early 70’.&lt;br/&gt;Modern cloud infrastructures provide very nice and powerful automation infrastructure around some kind of hypervisor/virtualization kernel.&lt;br/&gt;This is the real value of the cloud, easy to use automation mechanisms for provisioning of virtual resources: machines, disks, networks.&lt;br/&gt;The paradigm shift, I think, is in the fact that the cloud move towards the programmers what is used to be in the hands of system administrators.&lt;br/&gt;Using a private/public cloud, you, as a programmer, can put into your development life cycle the management of the infrastructure needed to run your application. As it happen often, if you want to really get the advantages of a technology you have to pay a price. In the case of the cloud, if your application has not been designed to be “elastic”, i.e. easy to scale and deploy, you don’t get the real bonus in using a cloud.&lt;br/&gt;An application made of many different kind of subsystems with complex and rigid relationships among them it doesn’t fit very well with a cloud infrastructure. A rigid application with a dynamic infrastructure cannot leave well together no ?&lt;br/&gt;There are also “social” consequences in the cloud adoption. If you start to use a cloud either private or public, you could also take the ownership of the physical deployment which is used to be in the sphere of influence of the sys admins. I observed some diffidence in the operational people when I introduced a private cloud into my organization, they thought that it was a sort of lost of power, they used to be engaged even for creating ad hoc virtual machines for doing stress tests for example. With a private cloud in your laboratory, the developers can create by themselves everything they need for doing integration and scalability tests.&lt;br/&gt;Fortunately, the system and network administrators in my company are smart open to new things, so they realized that the cloud can free them from boring provisioning activities, giving them extra time in looking after the “iron”, the actual hardware, the storage, the network elements, etc.&lt;br/&gt;Off course, the cloud allows a better utilization of the hardware, so with the same hardware you can do more. Combining a private cloud with a public one, you could absorb the load peaks just temporary provisioning on the public cloud, in this way you are note necessarily forced to buy all the hardware needed by the foreseen peak.&lt;br/&gt;So, behind the hype I really think that cloud computing it’s another nice tool for us, as software architects, for designing applications easy to scale and to adapt themselves automatically to the load changes.&lt;br/&gt;As a side note, I wanted to learn a little bit more the language Scala, so I decided to define a DSL (Domain Specific Language) for quickly provisioning software infrastructure on top of an EC2 based cloud either Amazon or Eucalyptus, you can find the project &lt;a href=&quot;http://github.com/dgreco/stairway2cloud&quot;&gt;here&lt;/a&gt;. It’s still a working in progress and nothing more than an experiment, but at least I could learn a bit more of Scala and how to deal with EC2 and Eucalyptus.</description>
    </item>
    <item>
      <title>HPC = High Performance Camel ?</title>
      <link>http://www.davidgreco.it/MySite/Blog/Entries/2010/4/19_HPC_%3D_High_Performance_Camel.html</link>
      <guid isPermaLink="false">498fc508-fabc-4987-ab1d-2c4e908c5352</guid>
      <pubDate>Mon, 19 Apr 2010 11:27:12 +0200</pubDate>
      <description>I did another experiment with my favorite software beast. Even if I’m still convinced that using C/C++ for building low latency/high throughput applications is more effective than using Java I’m also convinced that this should be balanced with the cost of development. So, provided that Java allows a more effective way for developing complex applications, I started to wonder if Camel can be also used as a bus in scenarios where performances and scalability really count. &lt;br/&gt;As in the previous post, I made some experiments integrating Camel with a very fast &lt;a href=&quot;http://www.zeromq.org/&quot;&gt;messaging library&lt;/a&gt; and  the preliminary results are not too bad I reached a throughput of more than 50K messages per second (1KB payload). The next step was to see if Camel can be used for storing messages into an highly scalable NoSQL store like &lt;a href=&quot;http://hadoop.apache.org/hbase/&quot;&gt;HBase&lt;/a&gt;. My first idea was to write a Camel component for reading/writing data into HBase as I did with the &lt;a href=&quot;http://camel.apache.org/hdfs.html&quot;&gt;camel-hdfs&lt;/a&gt; component, since I’m lazy I looked around to see if something similar was already made by someone else. This is what I found:&lt;br/&gt;	1.	 &lt;a href=&quot;http://ghelmling.github.com/meetup.beeno&quot;&gt;http://ghelmling.github.com/meetup.beeno&lt;/a&gt;&lt;br/&gt;	2.	 &lt;a href=&quot;http://www.datanucleus.org/plugins/store.hbase.html&quot;&gt;http://www.datanucleus.org/plugins/store.hbase.html&lt;/a&gt;&lt;br/&gt;I decided to investigate a little bit more with the second option. In fact the Datanucleus guys provide us with a JPA/JDO tool with a pluggable storage mechanism where one of the different storages can be HBase. &lt;br/&gt;Using Datanucleus you can just annotate a class using either the &lt;a href=&quot;http://java.sun.com/javaee/technologies/persistence.jsp&quot;&gt;JPA&lt;/a&gt; or &lt;a href=&quot;http://java.sun.com/jdo/&quot;&gt;JDO&lt;/a&gt; standard annotations and voila that class can be automatically persisted into HBase. Additionally, Camel provides a &lt;a href=&quot;http://camel.apache.org/jpa.html&quot;&gt;camel-jpa&lt;/a&gt; component  which allows to to store and retrieve Java objects from persistent storage using JPA. Combining camel-jpa and the Datanucleus Hbase plugin I have a camel based mechanism for streaming messages into an HBase store and this is what I needed. &lt;br/&gt;So, I put together a simple example that shows how to stream events to a Camel endpoint, using zeromq and to store them into an HBase store.&lt;br/&gt;It seems to me that Camel is enough lightweight and fast to be used as a bus for glowing together technologies for the realization of high performant/available architectures. In any case, I think that it could be useful to investigate and to see if it’s possible to increase the overall throughput of Camel this could make it a very nice tool even in contexts where the throughput is the most fundamental requirement. &lt;br/&gt;You can find the complete maven based project &lt;a href=&quot;http://github.com/dgreco/camel-hbase-zeromq-example&quot;&gt;here&lt;/a&gt;.&lt;br/&gt;</description>
    </item>
    <item>
      <title>A quick Camel ride</title>
      <link>http://www.davidgreco.it/MySite/Blog/Entries/2010/3/27_A_quick_Camel_ride.html</link>
      <guid isPermaLink="false">262f5416-62dd-4d59-9675-459487ec9688</guid>
      <pubDate>Sat, 27 Mar 2010 14:00:25 +0100</pubDate>
      <description>I wanted to do a quick experiment with Camel. My idea was to find a way for quickly integrating Camel with any native transport library.&lt;br/&gt;As an example I took the &lt;a href=&quot;http://www.zeromq.org/&quot;&gt;zeromq library&lt;/a&gt; and I wrote a Camel component which supports that library for sending and receiving byte buffers.&lt;br/&gt;For developing this component I needed to find a way for making portable the integration of a pure Java based framework like Camel with C/C++ based code. Fortunately there are nice tools that allow developing portable JNI C/C++ code able to be compiled seamlessly under different platforms. The result is a maven based project that could be integrated into the Camel building process even if it needs to build native libraries.&lt;br/&gt;It works under Mac OSX and Linux and adding the support for other OSes shouldn’t be so difficult.&lt;br/&gt;The tools I used are:&lt;br/&gt;	1.	 &lt;a href=&quot;http://www.cmake.org/&quot;&gt;CMAKE&lt;/a&gt;: it’s a powerful building files generator.&lt;br/&gt;	2.	 &lt;a href=&quot;http://www.swig.org/&quot;&gt;SWIG&lt;/a&gt;: it generates all the JNI plumping for integrating existing C/C++ code with Java.&lt;br/&gt;	3.	 &lt;a href=&quot;http://www.boost.org/&quot;&gt;BOOST&lt;/a&gt;: it’s one of the most important C++ frameworks. It provides among many different things OS independent APIs for concurrent programming.&lt;br/&gt;You can find the project under &lt;a href=&quot;http://github.com/dgreco/camel-zeromq&quot;&gt;GitHub&lt;/a&gt;.&lt;br/&gt;See you at the next Camel ride.</description>
    </item>
    <item>
      <title>My Camel likes the Elephant</title>
      <link>http://www.davidgreco.it/MySite/Blog/Entries/2009/12/20_My_Camel_likes_the_Elephant.html</link>
      <guid isPermaLink="false">5ad3cd11-e1b4-4023-ab30-06ad3a9fb6d7</guid>
      <pubDate>Sun, 20 Dec 2009 13:00:36 +0100</pubDate>
      <description>I’m still working on the Camel HDFS component and I think it reached a good level of maturity. I added also the consumer part, so it’s possible now to read from an HDFS file. I submitted the patch to the Camel community and it’s pending for the approval and to be integrated into the Camel trunk.&lt;br/&gt;In the meanwhile if you wanna play with the latest version of this component, you can check it out from my &lt;a href=&quot;http://home.davidgreco.it/svn&quot;&gt;subversion repository&lt;/a&gt;:&lt;br/&gt;&lt;br/&gt;svn co &lt;a href=&quot;http://home.davidgreco.it/svn/camel-hdfs/trunk&quot;&gt;http://home.davidgreco.it/svn/camel-hdfs/trunk&lt;/a&gt; camel-hdfs&lt;br/&gt;&lt;br/&gt;Below the documentation of the component.&lt;br/&gt;&lt;br/&gt;HDFS Component:&lt;br/&gt;&lt;br/&gt;URI Format&lt;br/&gt;&lt;br/&gt;hdfs://hostname[:port][/path][?options]&lt;br/&gt;&lt;br/&gt;the path is treated in the following way:&lt;br/&gt;	1)	as a consumer if it’s a file it just read the file, otherwise if it represents a directory it scans all the file under the path satisfying the configured pattern. All the files under that directory must be of the same type.&lt;br/&gt;	2)	as a producer, if at least one split strategy is defined, the path is considered a directory and under that directory the producer creates a different file per split named seg0, seg1, seg2, etc.&lt;br/&gt;&lt;br/&gt;Options&lt;br/&gt;&lt;br/&gt;Name                 Default Value       Description&lt;br/&gt;overwrite             true                       the HDFS file can be overwritten&lt;br/&gt;&lt;br/&gt;bufferSize           4096                     the buffer size used by HDFS &lt;br/&gt;&lt;br/&gt;replication           3                           the HDFS replication factor&lt;br/&gt;&lt;br/&gt;blockSize            64MB                    the size of the HDFS blocks&lt;br/&gt;&lt;br/&gt;fileType               NORMAL_FILE    it can be SEQUENCE_FILE,&lt;br/&gt;                                                         MAP_FILE, ARRAY_FILE, or&lt;br/&gt;                                                         BLOOMMAP_FILE, see Hadoop&lt;br/&gt;&lt;br/&gt;fileSystemType   HDFS                   it can be LOCAL for local filesystem&lt;br/&gt;&lt;br/&gt;keyType              NULL                    the type for the key in case of&lt;br/&gt;                                                         sequence or map files. See below.&lt;br/&gt;&lt;br/&gt;valueType           TEXT                    the type for the key in case of&lt;br/&gt;                                                         sequence or map files. See below.&lt;br/&gt;&lt;br/&gt;splitStrategy                                     A string describing the strategy on &lt;br/&gt;                                                         how to split the file based on different&lt;br/&gt;                                                         criteria. See below.&lt;br/&gt;&lt;br/&gt;openedSuffix        opened                When a file is opened for reading/&lt;br/&gt;                                                         writing the file is renamed with this&lt;br/&gt;                                                         suffix to avoid to read it during the&lt;br/&gt;                                                         writing phase.&lt;br/&gt;&lt;br/&gt;readSuffix             read                    Once the file has been read is&lt;br/&gt;                                                         renamed with this suffix to avoid to&lt;br/&gt;                                                         read it again.&lt;br/&gt;&lt;br/&gt;initialDelay            0                         For the consumer, how much to wait&lt;br/&gt;                                                        before to start scanning the directory.&lt;br/&gt;&lt;br/&gt;delay                     0                         Then interval between the directory&lt;br/&gt;                                                         scans.&lt;br/&gt;&lt;br/&gt;pattern                   *                         The pattern used for scanning the&lt;br/&gt;                                                         directory&lt;br/&gt;&lt;br/&gt;chunkSize            4096                    When reading a normal file, this is split   &lt;br/&gt;                                                         into chunks producing a message per&lt;br/&gt;                                                         chunk       &lt;br/&gt;&lt;br/&gt;The keyType and the valueType can be:&lt;br/&gt;NULL it means that the key or the value is absent&lt;br/&gt;BYTE for writing a byte, the java Byte class is mapped into a BYTE&lt;br/&gt;BYTES for writing a sequence of bytes. It maps the java ByteBuffer class&lt;br/&gt;INT for writing java integer     &lt;br/&gt;FLOAT for writing java float&lt;br/&gt;LONG for writing java long&lt;br/&gt;DOUBLE for writing java double&lt;br/&gt;TEXT for writing java strings&lt;br/&gt;&lt;br/&gt;BYTES is also used with everything else, for example, in Camel a file is sent around as an InputStream, int this case is written in a sequence file or a map file as a sequence of bytes.&lt;br/&gt;&lt;br/&gt;Splitting Strategy&lt;br/&gt;In the current version of Hadoop (0.20.1) opening a file in append mode is disabled since it’s not enough reliable. So, for the moment, it’s only possible to create new files. The Camel HDFS endpoint tries to solve this problem in this way:&lt;br/&gt;	•	 If the split strategy option has been defined, the actual file name will be &amp;lt;file name&gt;0 initially&lt;br/&gt;	•	 Every time a splitting condition is met a new file is created with name &amp;lt;original file name&gt;N where N is 1, 2, 3, etc.&lt;br/&gt;The splitStrategy option  is defined as a string with the following syntax:&lt;br/&gt;splitStrategy=&amp;lt;ST&gt;:&amp;lt;value&gt;,&amp;lt;ST&gt;:&amp;lt;value&gt;,*&lt;br/&gt;&lt;br/&gt;where &amp;lt;ST&gt; can be:&lt;br/&gt;BYTES a new file is created, and the old is closed when the number of written bytes is more than &amp;lt;value&gt;&lt;br/&gt;MESSAGES a new file is created, and the old is closed when the number of written messages is more than  &amp;lt;value&gt;&lt;br/&gt;IDLE a new file is created, and the old is closed when no writing happened in the last &amp;lt;value&gt; milliseconds&lt;br/&gt;&lt;br/&gt;for example:&lt;br/&gt;hdfs://localhost/tmp/simple-file?splitStrategy=IDLE:1000,BYTES:5&lt;br/&gt;it means: a new file is created either when it has been idle for more than 1 second or if more than 5 bytes have been written&lt;br/&gt;&lt;br/&gt;P.S. (8 Jan 2010)&lt;br/&gt;I moved this project to &lt;a href=&quot;http://www.github.com/&quot;&gt;github&lt;/a&gt; &lt;a href=&quot;http://github.com/dgreco/camel-hdfs&quot;&gt;here&lt;/a&gt;. There is also a wiki page under the Apache Camel documentation, &lt;a href=&quot;http://camel.apache.org/hdfs.html&quot;&gt;here&lt;/a&gt;.</description>
    </item>
    <item>
      <title>When a Camel encounters an Elephant</title>
      <link>http://www.davidgreco.it/MySite/Blog/Entries/2009/11/17_When_a_Camel_encounters_an_Elephant.html</link>
      <guid isPermaLink="false">a642e27b-87c9-4972-a3a2-6d7be2c0f1af</guid>
      <pubDate>Tue, 17 Nov 2009 11:59:30 +0100</pubDate>
      <description>I don’t know why, but I’m still pretty linked to my HPC background, even if I spent most of my time working for different kind of enterprises and trying to solve problems on different domains, I always thought that enterprises should try to learn from the HPC community how to solve “hard” business problems. With  the adjective “hard”, I mean difficult in terms of computational power needed for solving the problem.&lt;br/&gt;I’m observing a sort of convergence towards a sort of cross fertilization in terms of technologies involved between the HPC community and the enterprise business community. For example, grid computing and cloud computing are technologies that used to be already popular in the HPC field, but now are getting more and more interest even in the enterprises.&lt;br/&gt;In the HPC, off course the emphasis is more on the solution of numerical problems where the data set involved can be really huge. There are so many interesting problems in this area: oil exploration, weather forecast, molecular dynamics, etc. On the other end enterprises need to process huge amount of data as well, but in this case they usually need to digest huge amount of data in structured/semi-structured form for extracting something useful: analysis of web servers logs, information retrieval/extraction from a massive number of documents, indexing, etc.&lt;br/&gt;In both cases, there is a trend in trying to scale the applications using many inexpensive nodes than using big computers.&lt;br/&gt;Along this line, I started to give a look to a very interesting technology used for scaling the analysis of very huge quantity of data.&lt;br/&gt;This technology is &lt;a href=&quot;http://hadoop.apache.org/&quot;&gt;Hadoop&lt;/a&gt;. Hadoop is an open source implementation of the &lt;a href=&quot;http://labs.google.com/papers/mapreduce.html&quot;&gt;map/reduce algorithm&lt;/a&gt; proposed by Google. I would say that Google didn’t invent anything, they just applied the concept of collective computations (reductions), typically used in parallel computing, to the problem of creating reverse indexes for the web search. I used to use sort of map/reduce algorithm using &lt;a href=&quot;http://www.mpi-forum.org/&quot;&gt;MPI&lt;/a&gt; when I was working in a parallel computing laboratory.&lt;br/&gt;I don’t want to go deep into details regarding the Hadoop ecosystem, on the Apache site it’s plenty of information. What I tried to do is to see if one of my favorites open source tools, &lt;a href=&quot;http://camel.apache.org/&quot;&gt;Camel&lt;/a&gt;, could be useful for making the usage of Hadoop easier. Look at the picture below:&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;A fundamental piece in the Hadoop ecosystem is HDFS (Hadoop File System). From the Apache site: “The Hadoop Distributed File System (HDFS) is a distributed file system designed to run on commodity hardware. It has many similarities with existing distributed file systems. However, the differences from other distributed file systems are significant. HDFS is highly fault-tolerant and is designed to be deployed on low-cost hardware. HDFS provides high throughput access to application data and is suitable for applications that have large data sets.”&lt;br/&gt;So, before analyzing the data the first step is to put the data on the HDFS filesystem. HDFS provides APIs and also command line utilities for loading data into HDFS, however I thought it would be nice to take advantage of the multi-transport/multi-protocol nature of Camel for accomplishing the task of filling the Hadoop file system. &lt;br/&gt;In fact, using Camel you could easily gather data for virtually any kind of system using a plethora of many different mechanisms: files, ftp, http, mail, atom, rss, xmpp, etc. So, having an HDFS Camel component you could just define routes that gather data from any kind of sources to be put directly into the Hadoop file system, this is why I wrote a Camel HDFS component. In attachment I put the zip file containing the component, youi can dig around the tests to see how it works. At the end of this post I’ll put some documentation. For the next steps I’m thinking if it makes sense to integrate Camel even with the map/reduce framework. In the meanwhile I think that using Camel only for writing data into an HDFS filesystem could really help.&lt;br/&gt;Very soon I’ll try to submit this work to the official Camel project.&lt;br/&gt;&lt;br/&gt;HDFS Component:&lt;br/&gt;This component provides only a producer, it only allows writing data into the HDFS, reading from HDFS is not implemented yet. This component can be only used with the to clause.&lt;br/&gt;&lt;br/&gt;URI Format&lt;br/&gt;&lt;br/&gt;hdfs://hostname[:port][/path][?options]&lt;br/&gt;&lt;br/&gt;Options&lt;br/&gt;&lt;br/&gt;Name                 Default Value       Description&lt;br/&gt;append               false                      the HDFS file is opened in append&lt;br/&gt;                                                        mode&lt;br/&gt;&lt;br/&gt;overwrite             true                       the HDFS file can be overwritten&lt;br/&gt;&lt;br/&gt;bufferSize           4096                     the buffer size used by HDFS &lt;br/&gt;&lt;br/&gt;replication           3                           the HDFS replication factor&lt;br/&gt;&lt;br/&gt;blockSize            64MB                    the size of the HDFS blocks&lt;br/&gt;&lt;br/&gt;fileType               NORMAL_FILE    it can be SEQUENCE_FILE or  &lt;br/&gt;                                                         MAP_FILE, see Hadoop&lt;br/&gt;&lt;br/&gt;fileSystemType   HDFS                   it can be LOCAL for local filesystem&lt;br/&gt;&lt;br/&gt;keyType              NULL                    the type for the key in case of&lt;br/&gt;                                                         sequence or map files. See below.&lt;br/&gt;&lt;br/&gt;valueType           TEXT                    the type for the key in case of&lt;br/&gt;                                                         sequence or map files. See below.&lt;br/&gt;&lt;br/&gt;splitStrategy                                     A string describing the strategy on &lt;br/&gt;                                                         how to split the file based on different&lt;br/&gt;                                                         criteria. See below&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;The keyType and the valueType can be:&lt;br/&gt;NULL it means that the key or the value is absent&lt;br/&gt;BYTE for writing a byte, the java Byte class is mapped into a BYTE&lt;br/&gt;BYTES for writing a sequence of bytes. It maps the java ByteBuffer class&lt;br/&gt;INT for writing java integer     &lt;br/&gt;FLOAT for writing java float&lt;br/&gt;LONG for writing java long&lt;br/&gt;DOUBLE for writing java double&lt;br/&gt;TEXT for writing java strings&lt;br/&gt;&lt;br/&gt;BYTES is also used with everything else, for example, in Camel a file is sent around as an InputStream, int this case is written in a sequence file or a map file as a sequence of bytes.&lt;br/&gt;&lt;br/&gt;Splitting Strategy&lt;br/&gt;In the current version of Hadoop (0.20.1) opening a file in append mode is disabled since it’s not enough reliable. So, for the moment, it’s only possible to create new files. The Camel HDFS endpoint tries to solve this problem in this way:&lt;br/&gt;	•	 If the split strategy option has been defined, the actual file name will be &amp;lt;file name&gt;0 initially&lt;br/&gt;	•	 Every time a splitting condition is met a new file is created with name &amp;lt;original file name&gt;N where N is 1, 2, 3, etc.&lt;br/&gt;The splitStrategy option  is defined as a string with the following syntax:&lt;br/&gt;splitStrategy=&amp;lt;ST&gt;:&amp;lt;value&gt;,&amp;lt;ST&gt;:&amp;lt;value&gt;,*&lt;br/&gt;&lt;br/&gt;where &amp;lt;ST&gt; can be:&lt;br/&gt;BYTES a new file is created, and the old is closed when the number of written bytes is more than &amp;lt;value&gt;&lt;br/&gt;MESSAGES a new file is created, and the old is closed when the number of written messages is more than  &amp;lt;value&gt;&lt;br/&gt;IDLE a new file is created, and the old is closed when no writing happened in the last &amp;lt;value&gt; milliseconds&lt;br/&gt;&lt;br/&gt;for example:&lt;br/&gt;hdfs://localhost/tmp/simple-file?splitStrategy=IDLE:1000,BYTES:5&lt;br/&gt;it means: a new file is created either when it has been idle for more than 1 second or if more than 5 bytes have been written&lt;br/&gt;</description>
    </item>
  </channel>
</rss>

