Friday, December 08, 2006

Are you suffering from using Dojo in Grails ?

Everything works fine for Grails 0.3.1 when I'm not using Dojo.
But after I'm using it with Grails, I'm suffering from the 100% CPU usage.
This performance hit's caused by Jetty (Grails' default server) is trying to response Dojo files.

From my understanding, it might be that
1. Jetty in Grails distribution has not been configured for this purpose ? or
2. It's normal that a Servlet container's not good at serving a big static file ?

Anyway, I still don't know what's going on inside the container, but I've got a workaround for this problem.
My current solution is to use lighttpd as the front server to serve this Dojo monster ;)
I connect lighttpd with Grails' server using the mod_proxy.
Here's my current config in \etc\lighttpd.conf

proxy.server = ( "/" =>
( "" =>
"host" => "",
"port" => 8080

Then you need to put your Dojo files into the \htdocs, and correct all script's references in your GSP pages.
Lighttpd uses the default 80 port. So, you just point your browser to, every should work correctly.

IMO, this solution should work for the production phase as well.

Friday, December 01, 2006

Minimum "rt.jar" for Hello World

Here's a list of classes that are needed to run a Java hello world program.
I find this list using java -verbose (motivated by this post).

== listfile.txt ==

The following is a command for 7z to strip down the rt.jar (from 37,043 Kb to 1,806 Kb).

7z.exe d -r -x@listfile.txt rt.jar *.class

I tested with JRE 1.5_08 on Windows XP.

Saturday, April 08, 2006

Practical AOP #2 - What's done behind-the-scene?

I'll show you something that I think it's hard to maintain without AOP.
As in my Practical AOP #1, I mentioned that I have 8 inter-type declarations and 5 pointcuts to make data-binding work in ZK framework.

The main important thing is that I need one of the ZK base class to implement my Bindable interface. This change can be considered as somekind of the architectural change. Other point is that several UI element classes need to be modified. One of my pointcuts weaves to add the special event trigger to, at least, 9 classes.

The figure below partially shows the UML-like class diagram for the data-binding aspect.

AOP | Modularity ~= Responsibility

It's difficult to making change to many opensource projects that their developers are taking full responsibility to their own codes. The process of changing must be done via their process. Many projects use the opensource community to find their bugs rather than feature enhancement becuase the developer still want to control the way the project should be. This is somewhat to crash the innovations. Someone who has some ideas to completely enhace the original project has to *fork* to the new project. In my opinion, we can use AOP to solve these social phenomena.

What I've done is in the same way I mentioned above. At the first place, I want to add some new features to ZK. I created some new code and was thinking about sending the patch to ZK developers. But I stopped and thought again. If I send my patches to them, my code may break their code and it's not good for the ZK community. The development may have to be slow down because something will be patched into the core. So my solution is to convert all my new code into an aspect. Then I'll take all responsibilities to my aspect rather than push it to the ZK core developers. I think this solution could be good when someone wants to contribute a new thing to the core of some working frameworks. That's why the data-binding aspect has been made.

Practical AOP #1: Data-Binding Aspect for Web UI

ZK ( is one of the best XUL tool for Java that I've known. It's a very powerful framework working on server-side to render DHTML with Ajax capability. ZK is heavily based on MVC model, but I personally want to use the .NET-like data-binding feature in this framework. To avoid making changes direct to the ZK core, which is being maintained by its developers, I use AspectJ (1.5) to create the "data-binding" aspect.

However, I firstly started with OO approach in my development process. After I have some working code, I've tried to refactor the data-binding aspect out of the base code. During development, I've found that it is difficult to develop aspects without looking to the base source code. Because I need to ensure that my aspect weaves the base code correctly.

In my data-binding aspect, I have 5 pointcuts and 8 inter-type declarations.

I've finished the first version of zk-databinding aspect outside the ZK team.
With AspectJ 1.5 and Java 5, I can deploy my aspect to a Web container (tested with
Tomcat 5.5.16) and get the data-binding feature transparently.
Not surprisingly, the data-binding aspect works with ZK 1.1 and ZK 1.2 flawlessly.

Wednesday, March 15, 2006

Together + NHibernate ~= A Great Duo

I just have an opportunity to use Borland Together 2005 for VS.NET. Its LiveSource ? feature is very cool !!!. So, I’m here to tell my experience.
I’m evaluating a modeling tool for modeling business sytem that will be implemented using NHibernate. This system will contains 70-80 classes (a small-medium system). Someone who visited my website may be wonder why I don’t use ECO III. The main reason is because ECO III doesn’t work will with MySQL dbms. The other reason is that ECO III uses the unified approach to maintain object id, so the system may have a number of objects no more that 2^31 (please correct me if I’m wrong). However, this limitation is not a problem for a small to medium system. I calculated that the system can run and work well for at least 50 years. But the problem will occur when there are a lot of transaction per day. Object ids will be run out, and ECO won’t reuse any deleted id.

On the other hand, NHibernate is boring because it cannot fully manage bi-directional associations because it isn’t controlled by a state machine, which ECO has. The main advantages of NHibernate are. 1. ) It allows developer to do o/r mapping at low-level, and 2.) NHibernate objects are plain .NET objects (while ECO objects are not, all ECO business entity implements IObject interface).

I’m evaluating DevExpress XtraGrid for UI layer, it’s amazing control. Not much needed to say. Its databinding ability is extremely cool !!. One problem I encountered for NHibernate with DevExpress and other GUI layer is just we need to implement Equals, ToString, Hash methods for every class. And I’m now ready to by XtraGrid :). FYI, I use ObjectViews to connect NHibernate to XtraGrid instead of ISet, IList or Array.

Back to Together, it is useful for modeling and it makes me wonder that why Together for VS.NET is faster that Together for Delphi (they should be share the same implementation, shouldn’t they.) Code synchronization is beautiful (v. SP1) I am much faster to model the business entity. AFAIK, Together is one of a few tools that allow designer to put some attributes to the design elements (class, method). I think Rational XDE also have this feature, but didn’t try yet. One feature I don’t see in Together is automatic field encapsulation as property, which is needed by NHibernate. May be I just don’t know how to use it (please tell me if you know). Other great features of Together are namespace management, and enum and inner class modeling, which may be useful for one who uses NHibernate. Together also provides very flexible refactoring.

Wednesday, January 18, 2006

Moved to Manchester

Long time no posting.
I'm very busy about moving from Thailand to Manchester, UK.
This is the first day in Manchester that I can online more than 3 hrs :).
I'll study a PhD research program at the University of Manchester for, at least, 3 years.