Monday, November 28, 2011

Entity abstraction for Scalapi

I created an abstraction for storing and accessing persistent entities using the Scalapi library.

I find it useful when experimenting with various data providers and comparing benchmarks results.

Below you can see example of its usage to feel the flavor of this API.
// Define entity class
case class SampleEntity(id: String) extends Entity[String] {
  entityId = Some(id)

// create DB4O entity store
val objectContainer = Db4oEmbedded.openFile("/tmp/db")
val entityStore = new Db4oEntityStore(objectContainer)

// Store entity SampleEntity("id"))

// Find entity
val query: Predicate[SampleEntity] = (entity: SampleEntity) => entity.getEntityId() == Some("id")
val results = store.query[SampleEntity](query)

Thursday, November 24, 2011

Scalapi 0.3.0 snapshots are now available in Sonatype repository

I pushed Scalapi 0.3.0 to the OSS sonatype snapshot repository. It makes easier to include snapshots artifacts of the Scalapi in the Maven projects.




Scalapi is my library pimping existing Java APIs (both JDK and popular 3rd parties libraries). Using Scala, I miss the enhancements that Groovy provides with its distribution. I'm using Scalapi in few of my projects and it makes my life easier so far.

Monday, November 21, 2011

The technologies I'm enthusiastic about

Here is the summary of the technologies I'm the most enthusiastic about.

Financial markets systems
  • QuickFixJ

    Programming languages
  • Java
  • Scala

    Mobile platforms
  • Android
  • Sunday, November 20, 2011

    Financial markets resources summary

    This is the place where I'll keep summarized references to the sources of information regarding the financial markets.

  • Practical .NET for Financial Markets, by Yogesh Shetty and Samir Jayaswal, Apress, 1st edition

    Online resources:
  • Investopedia dictionary
  • RSS with Term Of A Day from Investopedia
  • stock investing headlines RSS from Investopedia
  • Friday, November 18, 2011

    How to create public Maven repository for free

    I needed QuickFixJ 1.5.1 to be available for Maven dependency resolution. Official QuickFixJ repository doesn't contain the latest version of the projects artifacts. In order to allow the other people to build my QuickFixJ 1.5.1 related project I needed to put QuickFixJ libraries in Maven repository available via the Internet.

    So I created my "private public" repository on the Google Code Project SVN server. This is approach I know from the Apache Camel extra project where we put missing dependencies from the 3rd parties this way. This is possible since Google Projects allows you to display the SVN repository of your project via the web browser. Useful and free of charge :) .

    Saturday, November 12, 2011

    Scala resources summary

    This is the summary post to keep my favorite Scala-related resources and references in one place.

  • Beginning Scala by David Pollack, 1st edition, Packt publishing
  • Scala tutorial at Stack Overflow

  • Scala tag at Stack Overflow (plus RSS channel for it)
  • Wednesday, November 9, 2011

    Transformation Channel pattern for Scala

    I'm particularly keen in Scala because of my strong integration background. Scala (and functional programming in general) promotes message-based communication between the objects. When we design the applications to be more message-oriented, we also could start using patterns typical for integration architecture (like Hohpe's EIP patterns).

    One of the most powerful integration pattern is Message Translation (aka Message Transformation). The idea behind this pattern is quite simple. You intercept the message and affect it in some way.

    How this pattern can apply to the Object Oriented design? Imagine that you want to pass some data from one object (let's call it Data Provider) to the another that will perform some operation on the data (we will refer the second object as Data Receiver). Then Data Receiver processes the data and returns it.

    We may also want Data Receiver to send processed data to some other object.

    The processing scheme presented above is quite common. The idea behind Message Transformation pattern in the context of Object Oriented design is to allow us to intercept the latter processing scheme in order to affect the message sent between Data Provider and Data Receiver.

    To achieve the goal described above, we need to add a layer of abstraction between the communication objects. Let's name it TransformationChannel. Instead of sending messages directly to Data Receiver, Data Provider will send messages to the channel. Than channel will notify the Data Receiver that message with data is available to be processed.

    Channel allows us to register message translators to listen for the data and modify it before Data Receiver gets it.

    Using the Message Translator pattern and Transformation Channel we can easily add additional behavior to the default version of the algorithm processing our data.

    I've created a simple implementation of the Transformation Channel in Scala. It uses partial functions and pattern patching as Message Translators. In the example below Strings sent to the Transformation Channel are converted to uppercase by Data Receiver. This base functionality can be packed into the jar file and delivered to the other team of developers.

    // Some data to process
    val data = "foo"
    // Data Receiver which converts Strings to upper case
    val dataReceiver: PartialFunction[Object, String] = {
      case s: String => s.toUpperCase
    // Transformation channel with registered Data Receiver 
    val channel = new TransformationChannel(dataReceiver)
    // Data processing
    val upperCasedData: String = channel.transform(data)

    If at some point the other team of developers decides that data should be affected somehow before the processing, they can dynamically add Message Translator (defined as partial function) to the channel defined by us.

    // Register Message Translator
    channel.addPreTransformation {
       case s: String => "prefix_" + s
    // Process data
    val prefixedAndUpperCasedData: String = channel.transform(data)
    When would you like to use Transformation Channel?
    • when you want to deliver default implementation of data exchange between two objects but still be able to dynamically modify or extend this behavior
    • when you can't predict all possible scenarios of data exchange between two objects
    • when data exchanged between two object is likely to be modified by other collabolators
    • when you want to provide plug-in point for communication between two objects
    • when you want to provide unifed implementation of the Observer design pattern
    • when you want achieve very loose coupling between two communicating objects