If you're interested in functional programming, you might also want to checkout my second blog which i'm actively working on!!

Monday, November 22, 2010

Benchmark on Synchronization in Java

The article mentions several ways of synchronizing a method and shows performance vs. number of threads. So if the solution has to scale you are better off using semaphores or explicit locks.

Saturday, November 13, 2010

Persevere, a NoSQL database

I've read quite a bit about client-server architecture but the fundamental problem seems like a scalability issue. Maintaining session state and generating not only the model(data) but also the view on the server side is asking for problems. And de(serialization) of your data between a relational database and your domain model sounds like a time consuming operation. Some databases like CouchDB and Persevere skip this tedious task and since the data is stored as JSON, it's immediately usable in the browser. So it's a matter of providing efficient ways to store and query the data from within the browser.

I was reading through Persevere and Pintura documentation and it's definitely worthwile to build a little sample app with these technologies to get a better understanding. To be continued real soon...

Wednesday, November 10, 2010

From XML to JSON using SAX

As a die hard Apache Cocoon user I deal with lots of XML data. And there is more then way to transform your data into another output format like xhtml.
  • use xslt to transform directly into xhtml -> serialize to xhtml -> render page
  • use xslt to transform to json -> serialize to text -> render the page template -> make an asynchronous request to fetch the json data -> preferably instantiate some javascript widget and populate it with the data
For my last project I created a new search module which was working from top-to-bottom asynchronously and fetched only the minimal amount of data at the time it was needed.

One use case was where I needed to transform a large xml document describing some tree like structure and the customer wanted that tree to be displayed nicely as a tree.

I'd like to describe how you can generically convert any xml document into json.

Let's first start taking a quick look at what JSON is all about.

You basically have to deal with arrays, objects, dates, booleans, numbers and strings.

Based on the above we can come up with a generic XML way of describing the above:

So we can easily write a generic transformer for this use case:

Now you only need to convert your input xml file into the generic JSON xml structure and transform it with the above stylesheet.

PDOM: Yet another XML parser

People keep being creative and xml is here to stay for a long time. So we already had SAX (not memory expensive but hard to program against) and (J)DOM which loads the complete document in memory but is easier to use.

Now they released a new parser somewhere in between: PDOM

Tuesday, November 9, 2010

Selectors API

I never really used the selectors API's untill my customer wanted to add some special behaviour on the first tree cells of all rows of a particular table body.

In combination with YUI this proves to be a really cool feature.

Some new specs for my TO-READ list:

The snippet below selects the first 3 cells from all rows inside tbody[id='fileresults']

Below the macro which generates my table using jx-template (Apache Cocoon)

YUI3 using YUI2 TreeView

I was pleased to find out that the YUI team offers functionality to access YUI2 modules from within YUI3. Anyway... just sharing some code I wrote which offers me reusable Tree functionality:

YUI 3 transaction management simplified

After using YUI3 for a while I was quite satisfied with most of the API but the IO module was still quite cumbersome to use. I came up with following user-friendly function.

Some examples of how i use them in my project:

An example of executing a synchronous transaction

An example of using a SimpleContainerTransaction

An example of a ContainerTransaction where I override the onComplete method

Sunday, November 7, 2010

WebP as replacement for JPEG

Google always is trying to cut down on loading time of webpages. Since most webpages contain many images in JPEG format they decided to use a newer compression technique called WebP and they provide a conversion tool to convert your JPEG images to WebP format. They claim an average reduction in filesize of 39% based on converting 900.000 random images.