Wednesday, February 28, 2007

The Indian team left for the windies last night amidst much fanfare. On their shoulders rests the hopes and aspirations of a billion people. We have a well-balanced side this time with the return of the likes of sourav and zaheer to the team. The only area where the team may be found wanting is fielding. In my opinion, even that too may not matter much as there's still youngsters like Yuvraj, robin and karthick in the side. That doesn't mean that sehwag, sourav, dravid and sachin are bad fielders. So we can all expect a good world cup once we get past the preliminary stages where big teams play against teams like Ireland, canada etc. India is in the same pool as srilanka, bangladesh and Bermuda are the other teams in pool B. India would do well to remain wary of B'desh as they can spring a surprise or two. But Iam sure India would do well and reach the later stages with ease.
The budget has been announced though I haven't had a chance to check it out fully yet. From the little I have seen, there doesn't appear to be anything worth writing home about in the budget. For the emplloyed, it will be the same as last year. There appears to be extra cess for education and the farming sector has received some funds. Agriculture has received quite a bit of attention though Iam not sure if veterinary, an allied field till some time ago, has received some of the benefits.
Better infrastructure is an absolute must. The roads leading to and from the IT corridor are in a sorry state and taking too long to build. On the bright side, Chennai is becoming the next detroit and should strive to make a mark on the global economy.
Just yesterday there was a post about a java expression evaluator called JEval going open source. This brought back memories of early part of last year when I had wanted the software for a rule engine I was developing. I am not sure what I hoped to achieve by doing this because in my case the rules were in java syntax. Some products I tested were

1. jep
2. jeplite
3. jformula

None of these would suit my need and I decided to write my own using javacc. I wanted a parser that would parse the expression and return me an AST. The parsers were in fact capable of evaluating the AST. But I didn't want that and just wanted only the AST. I found that while JavaCC would compile the expression and tell me if it was correct, I couldn't get a handle to the AST. The AST is used in a parser as an intermediate between a parse tree and a data structure
and differs from a parse tree by omitting nodes and edges for syntax rules that do not affect the semantics of the program. For example, grouping parentheses are omitted in an AST as the grouping of operands is explicit in the tree structure. In the end, I tried AST and the Calculator sample program was what fit my need to a T and I could get the AST that I wanted. I was a little
sad in the end because once I came to know of JavaCC, I had come to the conclusion that JavaCC would solve all my parsing needs. Only this time, javaCC proved inadequate and had to use ANTLR.

Tuesday, February 27, 2007

Just got an email. My paper has been selected for presenting at the Jazoon'2007 conference to be held in Zurich in June 2007. I had submitted my paper titled 'Adapting swingx JXTreeTable component to display XML" to both Java One and Jazoon. The Java One folks didn't see any merit in my paper whereas the jazoon folks did. I had written this paper based on the work I had done with the JXTreeTable for the XML grid component I was developing. Iam still waiting to hear more from the Jazoon people and if all goes well, I might go to Zurich in June. It was really good that Jazoon had a track for desktop java as I have been doing mostly desktop related work the past few months. It is only recently that I have taken interest in web 2.0, RIAs and such that I would have been hard pressed for a topic in which to present on had there not been a desktop java track. The next step would be for me to get ready a camera ready presentation. I will update this space frequently on what transpires. Switzerland has one of the prettiest landscapes on earth and what's more, I haven't been there yet. So Iam hoping it will be a great experience for me if I do make it. The kind of good work Bonanzasoft is doing in the open source space is starting to get recognized by the technological community at last. Iam sure only good things awaits the hard working people at Bonanzasoft from now on.

Monday, February 26, 2007

After nearly a month (3 weeks to be precise) my trip to Mumbai is finally coming to an end. It's been an interesting 3 weeks but also a somewhat exasperating one. The trip itself started on a sour note with me getting conned by a taxi driver, through a sleight of hand, made me pay the fare twice. Then my trip gets extended and I find that I haven't packed enough clothes. I hadn't even packed the mandatory night suit I would need for the first night only. Must have been dreaming while I packed. However, there was this big store called 'Big Bazaar' near my hotel where I could get the stuff I wanted. It is these stores that 'walmart' would be pitting against should it enter the retail segment. I knew beforehand that there was a possibility of the trip getting extended as the client I was meeting needed more convincing. The hotel room was booked for only 3 days and I had to extend that as well and also change rooms once. I hadn't even bothered to note down the client's name and phone number when I started. Thankfully, I remembered the company name and was able to get the number eventually and contact the client thereafter. I had to go outside to access the internet as my hotel didn't have wi-fi. I searched for a list of wi-fi zones in Mumbai from the client's place and made note of several. The first weekend on saturday, I spent visiting churchgate, Gateway of India and the Elephanta caves. The boat ride to elepanta was an hour long each way and the ride was really thrilling. I saw an internet cafe sign in Colaba, where GoI is located, and checked my email. Nothing of interest other than that a CD I had ordered had been dispatched. I then dropped into a Barista nearby and was told they had wi-fi and charged Rs 113 per hr. Not bad but I was too hosed to stop there.
My second attempt at finding a Wi-fi came when I went to the Inorbit mall in Malad West which is not far from where I stayed. But on going there I found that the connection wasn't going through even though it said "signal strength - strong 11 Mbps" in the taskbar. Don't know if it was the wi-fi or my laptop. But I had to settle for checking out the movie 'Blood diamond' instead. A couple of things I missed sorely were my sneakers and my trunks. I couldn't get any exercises during my three weeks of stay. The hotel didn't allow you into the pool unless you had proper swimming costume and I was averse to running barefeet on the road.
The meals in Mumbai are different from the one's Iam used to down south. There's less of rice and more roti which was good. The hotel where I stayed served rice and I couldn't help myself from ordering a sizeable portion each time I sat down to eat. I plan to embark on a strict regimen of diet and exercise upon my return. On a philosophical note, as I write this blog, a song comes to mind though I forget the album or the singer's name "The sad part is living without love".

Thursday, February 22, 2007

This thought occurs to me every time I see an application using Eclipse RCP. Have I made a mistake by spending so much time building my application from scratch. So many other vendors are leveraging the power of RCPs to build their applications. Here's a few examples.

1. Oracle uses Eclipse RCP for their BPEL product
2. Active BPEL uses Eclipse RCP
3. FlexBuilder uses Eclipse ECP

and many others. This allows them to focus on the business logic rather than worrying about such things as CloseableTabbedPanes, Dockable panels syntax highlighting, context-sensitive content assist etc to name a few. Never mind the end result gives the same effect as looking at a brand new urban citybuilt with lots of minarets and spires just because it was faster to build. That is only a small price to pay for other benefits realized such as faster time to market, smaller development cost, tested GUI layer etc.
Am I bothered by this thought. Not really. First of all, when I started developing my app a few years ago, I had no idea that such a thing existed. AFAICT, the RCP movement began quite recently. Further, Iam proud of my achievement and people just have to look at my product to see that Iam right. I'd like to believe that I have achieved something big, built a masterpiece as opposed to riding on the work done by others. Mind you, that this is not another instance of 'not developed here' syndrome. Its just that due to a twist of fate, I have come to become the owner of a cool looking product that I have developed myself without relying on anyone else.

Wednesday, February 21, 2007

Wicked wicket framework
---------------------------
I had earlier blogged about my foray into web 2.o and how I ended up trying wicket. I still am quite impressed with Wicket though I no longer work with it. Wicket interested me because it had a TreeTable component which I wanted to adapt to display XML. The exisiting TreeTable in Wicket displayed static, hierarchical data that could display only 5 columns. This was because the Wicket used a model bean which is a plain old java bean that looked like this:

public class ModelBean {

public ModelBean() {
}

public String getColumn_1_Value() {
}

public String getColumn_2_Value() {
}


:
:
:
}

What I envisaged would solve the problem was:

public class MyModelBean {

public MyModelBean() {...


public String getColumnValue(int columnNumber) {
if(columnNumber == 0)
return name;
else if(columnNumber == 1)
return size;
else if(columnNumber == 2)
return type;
else if(columnNumber == 3)
return lastModified;
}


This way the treetable would be able to display any kind of hierarchical data. However, in the end it proved to be easier said than done. Wicket uses PropertyResolver to resolve a compound expression of the form

userObject.value

which then got evaluated to

getUserObject().getValue()
}


using reflection. i.e 2 calls were being made on the PropertyResolver. The first one would ofcource return the userObject associated with the ModelBean and the getValue would then be called on the userObject. My new version would then pass the columnNumber as the argument to getValue. Further, key classes and methods inside wiket were marked private which hindered direct subclassing and workarounds had to be devised. Further there were so many execution paths since Wicket supports indexing of arrays, hashmaps besides javabean types that finding the places that needed changing was difficult to say the least. But as they say, Alls well that ends well and the code is now in the Apache incubator as Wicket has formally been inducted into Apache.
The work is by no means complete. The treetable editing functionality is not complete as yet. The treenodes are not editable. The swing version that I have developed is able to edit the treenodes. If time permits I would like to take that up as well. The only thing that is stopping me is the stack up inside my head has been cleared to make room for other stuff. Restarting work would mean once again going back and starting from the beginning

At times I did end up comparing wicket's syntax with that of JSF. JSF uses EL (expression language) for their expression support. JSF too uses PRopertyResolvers and with JSF our job is made slightly more difficult by ther being 2 different EL syntaxes, the JSTL syntax and JSF syntax which ofcourse is the topic of another blog altogether

Tuesday, February 20, 2007

Mumbai Dairy

This is my take on recent events and what's in store for the next month or so. Unlike last year, this year's superbowl went almost unnoticed. I didn't know about it until I heard of it from my sister. It was the bears vs the colts was what she told me. Don't know who won it too. On the homefront, the men in blue are preparing for the world cup of cricket to be held in the w.indies. Down under, Australia is coming under fire for recent flurry of losses. England, India and S.Africa and New zealand are the teams on a high after recent victories but the cup could be anybodys.
The oscars are also much awaited. Iam not sure who the contenders are this year. It's probably volver vs water in the best foreign film category. Brad pitt's babel too could be in contention. Clint Eastwood's 'letters from Iwo Jima' cannot be taken lightly either.
The tabloid's don't lose no time bringing us news about Hollywood celebrities. It was however, digg that first brought the news of Britney spears shaving her head. Aishwarya's engagement to Abhishek too is big news around these parts. Shilpa shetty might permanently settle in UK I guess the way the English have taken a liking to her. Or it could be that they want to compensate for the treatment they handed out to her in the Big Brother show. Roger waters performed in Mumbai on sunday. But I skipped it because he was before my time. I was prepped up on pink floyd in grad school and my first cd purchased was Pink floyd's 'The division bell'. By then Roger waters had retired and David Gilmour taken over. Still I remeber being transported to another dimension by "Shine on you crazy diamond" and the album "The wall" the last time I heard it. Life in Mumbai is going on and my work here should soon get over. I can't wait to get back to my desk as there's tons of things I have in my mind. Still there's a few good reasons why I might want to stay here a little longer. But that's a secret which I may share some other day.

Monday, February 19, 2007

Many rule engines compile the rules to achieve better performance. Drools uses Janino to compile the rules dynamically. Other rules engines use proprietary approaches. With code for javac being made public, rules in java syntax can also be compiled. Since the advent of Mustang, there's been a lot of talk about scripting support in java and I thought why not try something with a scripting language for instance. A benchmark I saw on the net revealed that groovy was by far the fastest next only to Rhino. My inherent suspicion of javascript made me to advise my team to use Groovy and this blog contains the results of our findings. I asked my team to to beat the timings of a fictitious evaluator that would evaluate the rules in 30ms or so.
To be honest, they were circumspect from the beginning but put up a brave front to me anyways. Later they told me it was the time taken to initialize the scripting engine, the binding of the params etc that worried them. So I asked them to try a lot of techniques like pre-cooking (a term I coined for initializing everything beforehand and leaving only the binding and evaluation for the last minute) for achieving better performance.

Now for some Groovy lessons. Groovy can be integrated in your java program in multiple ways.

1. GroovyShell approach
You could use the Groovy shell which wouldn't be much unlike a call to system in c or Runtime.exec in java. This is by far the slowest and I gave up this approach soon as I tried it.


2. GroovyClassLoader approach
The second approach was using the GroovyClassLoader. The groovy class is loaded into the ‘GroovyClassLoader’ and the ‘evaluate’ method invoked using reflection. The ‘GroovyClassLoader’ provides a ‘loadClass’ method for this purpose. However, this method only accepts a source file of a groovy script as input which it then compiles and returns a ‘GroovyClass’ object. The code for this approach is given below:

ClassLoader parent = ScriptRunnerLoader.class.getClassLoader();
GroovyClassLoader loader = new GroovyClassLoader(parent);

Object [] ps = vect.toArray(); // parameters to the method
File groovyFile = new File(ruleDir + File.separator + rname + ".groovy");
// Get an groovyClass object
Class groovyClass = loader.parseClass(groovyFile);

//create instance of class
groovyObject = (GroovyObject) groovyClass.newInstance();
//call method
Object obj = groovyObject.invokeMethod("evaluate", ps);


3. Groovy class approach
The last approach was using compiled groovy class. This is the most straightforward way of calling the groovy class and therefore the most efficient. The groovy class is directly imported into the application and the ‘evaluate’ method is called, similar to function calls made on other java objects in the application. This approach yields drastic improvement in performance, as there is no overhead of classloading or from interpreting the rules. The code for this is as below:

Vector vc = (Vector) vec.get(s);
String rname = (String) vc.get(0);

int rno = Integer.parseInt(rname.substring(4));

if(skipListContains(rno))
continue;

Vector vect = (Vector) vc.get(2);
String cond = (String) vc.get(1);

Object [] ps = vect.toArray();
Class groovyClass = Class.forName("rules." + rname);
groovyObject = (GroovyObject) groovyClass.newInstance();


Object res = groovyObject.invokeMethod("evaluate", ps);

Moral:
Don't expect some benefit when the real benefit lies elsewhere. In this case, the benefit of groovy was in its rich syntax and closure support and not in terms of cpu cycles.

Conclusion:
Groovy is great. But it is yet another java syntax. For someone who works with java day in and day out and looking for something new, give Ruby, beanshell, python and F3 a test drive. Forget such things as benchmarks for the time being and do what your heart tells you.

Sunday, February 18, 2007

This is a review of the book "The Last Juror" by John Grisham. I bought this book to keep me company on my current visit to Mumbai for some discussions with some business prospects. I was glad that I had this book with me as there was lots of spare time and I had this good book to keep me company. This book features Grisham's usual style that captivates you and amazes you on the amount of knowledge he author has in his field. Through this book, the author takes us into what life was like in the days of segregation in rural Mississippi. The epilogue says that this book is Grisham's second book after "A time to kill" to be set in Ford county, MS. I have read the book and watched the movie as well of that one and find that this time the author has surpassed his earlier work.
The book is about the life of one Willie Traynor, an average student from syracuse who makes a mark on the lives of the people of Ford county. The bond that Willie establishes with a black family from lowtown ( a segregated area) is astonishing. He revives Ford county's local newspaper when it falls on bad times and increases the circulation. Willie comes to Ford county to work as an intern under Wilson caudle, the owner of the Times. He then goes on to take over the paper itself with a small loan from his well-to-do Grandma. From there on it's by Willie's hard work and his firm commitment to maintaining the high standards of reporting that gets him to the top. The slow, uneventful life of Ford county residents is disturbed by the rape and violent murder of a yound widow by a member of the county's padgitt clan. The Padgitts are feared and loathed by the Ford county residents for their involvement in various nefarious activities. The Padgitts are also a reclusive lot never leaving their home in the Padgitt island. They island is an impenetrable fortress and any attempt to penetrate the island has been met with force and people getting killed. The tentacles of the Padgitt's has spread far and wide and even the town's sheriff is under their payroll.The Sheriff's and the defense attorney's efforts to first gain bail for Daniel Padgitt (The accused) and then to prove him innocent goes in vain as the prosecution builds a strong case against him. They are only successful in saving their client from the noose. Danny does not help himself by threating to kill the jurors if they found him guilty. The Jurors go ahead and find him guilty anyways and surprisingly do not award the death sentence.
Meanwhile Willie goes about his business of covering the trial and at personal risk to his life and his newspaper brings to light the severity of the crime which plays a major part in making the Ford county residents becoming less tolerant of the Padgitt clans activities if not the result of the trial itself.
Willie's black friend is Ms.Callie who has raised seven children six of whom are Ph.Ds and working as Professor's across the U.S. No mean achievement since segregation was in effect. Willie pays scant heed to the color difference and makes friends with Callie. Callie also has italian blood as she is brought up by an Italian. The author needs to be congratulated for bringing this piece of history to us i.e if what he says is true. He goes further by becoming a member of their family and visits their home every thursday for lunch with Ms.Callie. He even invites them to his mansion and plays host to some 30+ Ruffins over a weekend. He helps protect Ms.Callie from Dannie's threat and also saves her last son Sam from another threat from another white man. Willie, being white himself, never sees a black as different from himself and takes on such issues as segregation in schools, churches and politics using his newspaper editorials. When a black gets killed in the Vietnam war, he actively takes up the cause of the young blood by calling for an end to the war. He dreams of buying fancy gifts for his friend Ms.Callie out of the wealth he earns by selling his newspaper. All this and a lot more takes the reader to the days of segregation itself.
True to Danny's threat, jurors start getting killed once he is out on Parole. First it is a helpless kid in a wheelchair and then a mechanic. The story revolves around the threat that exists to the remaining jurors and the unknown identity of the perpetrator of the shootings widely believed to be Danny Padgitt.
There's a few dry sections to the book as well. For example, the author's description of the laws and rules of 1970 Missippi and about the ways elections are held is rather boring. There's even an authors note at the end which says how he has misused the laws sometimes in the book.

All in all an enjoyable read.

Thursday, February 15, 2007

Is this what Maven was intended for

My company has installed a firewall so that the staff do not download software to their computers. We use a software that tracks the sites from which the files are being downloaded and also the filetypes. Typically downloading of exe files, zip files etc are prevented for obvious reasons. I also head the company's R&D team which means I have to download software frequently and evaluate them. Since the person heading the IT team is often involved in attending to some issue or other, I have to wait several hours before he downloads the files and gives it to me. I have found a better way to get around this problem. Since the arrival of Maven, most software gets published to the Maven repository as jar files. Interestingly, the jar format isn't one that is blocked by our corporate firewall and I can download it quite easily. There is a repository of open source projects and their jar files in the maven repository at http://www.ibiblio.org/maven. The softwares I have so far downloaded and installed include

1. asm
2. axis
3. batik
4. commons-*
5. dom4j
6. drools
7. groovy
8. izpack
9. jaxen
10. myfaces
11. wicket
12. wsdl4j
and many others.

I can download the binaries of the recent as well as older versions of all the products and the sources too for some of them. This kind of benefit that Maven is providing together with the continued use of Ant by many make me wonder if this was the main intended use of Maven or would Maven end up as the software that resulted in providing us with a steady stream of downloadable jar files without quite being put to its intended use which is as a build system.