Monday, February 20, 2006

JMS backed by Websphere MQ

This is a learning experience about a JMS queue backed by Websphere MQ. My initial understanding was that a message published on the MQ queue wouldn't invoke the onMessage method of a listener/MDB. The notion sounded logical as the Java/JMS equivalent of the message exposed by the MQ JMS is of type com.ibm.mq.JMSBytesMessage and the onMessage expects the argument to be of type javax.jms.Message. Yesterday, we were able to publish a message on MQ and get an MDB listen to the messages. The details follow...

Before getting into the nitty-gritty, some backdrop on the context - our requirement was to process messages put on the MQ "asynchronously". Our knowledge of MQ being naive, the task motivated us and we explored the MQI(java interface for MQ) and played with it by developing some sample code. This led to the roll out of a design using the MQI and the quartz scheduler. I named it the "Pull Approach". A quartz job would poll the MQ at a defined time intervals and retrieve any messages in the MQ queue. Developed the code for the Pull approach and gave a demo of it.

Intrigued by the challenge and exploring more, came up with a second design that would use the inbuilt features of the MQ. A trigger is invoked on publishing a message. The trigger "translates" the message to JMS compatible message and publishes the message on a Topic. This design was baptized as "Push Approach" as the MQ server was pushing the messages. A document has been prepared with both the approaches and with crisp state diagrams made using Rational Rose and circulated it across. There was an inherent flaw in the Push approach, it didn't give implicit support for transactions. There were mixed opinions amongst the folklore about the the approaches with offhsore favoring Pull and onsite for Push.

With adrenalin still gushing, we got more adventurous and explored the JMSAdmin of the MQ. We have been playing around with that for a while but couldnot hit the bush.We decided to give try it afresh from scratch. So, created a context in the JMSAdmin, bound the connection factory and queue to the JNDI, used the same bindings in the JMS configuration on Websphere App server. The prototype was ready for testing. And to our surprise, when we pubslished a message on the MQ, it did invoke the MDB, though there was a ClassCastException for com.ibm.jms.JMSBytesMEssage. The cast exception could be resolved by reading out the bytes out of the JMSBytesMessage and copying them onto the JMS TextMessage.

This was an interesting development, indeed. Although, the earlier two approaches would be promptly decommissioned in favor of the third approach, we are happy that we were able to suggest a robust design that leverages the inbuilt features of the product. The learning curve has taken off. The documentation and the articles found on the IBM developer works site didn't help us much and most of the examples appeared to ratify our initial understanding. Well, being li'l adventurous and thinking outta box does help sometimes. There will a sequel to this blog entry soon with gory technical details.

*** UPDATE ***
There is an article on IBM site that explains in detail about configuring Weblogic JMS for Websphere MQ. Read the article here. I wish the article would have been published earlier that would have saved a few days of my tussle .

Thursday, February 09, 2006

Tussle with Websphere

Has been working with a variety of App. servers like Weblogic, JBoss, and JRun, but never got a chance to work with Websphere. Recently, got a chance to work with Websphere suit of products. First the websphere MQ and then the websphere server itself. The experience with MQ was bit adventurous, as the technology predates JMS. With some trial and error, intuition, googling, got the things up and running. Reb books helped a lot in understanding the internals for MQ.

To test the use cases against our design, we decided to develop a vertical slice of the application. One part of the slice was an MDB that listens to a JMS Queue on the websphere, backed by the MQ. The task is broken to two parts - have an MDB listening to the JMS queue on webspshere and once part 1 is in place, configure a MQ as a backend for the JMS queue. Developing an MDB was no much hassle and it got deployed on the websphere(The server had to be bounced everytime after configuring the Listener Ports and registering the Queue with the JMS server, and after deploying the jar file with MDB, duh, it sucks!). The next step was to publish some messages on the queue and see if the onMessage of the MDB is getting called.

I developed a suit of small utilities to help me in server-side testing, which I call as the fixture. The configuration of the fixture is externalized to facilitate portability. The messaging fixture worked without any errors when it was pointing to Weblogic, JBoss, JRun. But with Websphere, a lot of tweaking of the classpath is required. The following is the summary of the tweaking:

1. First of all, use the JDK that comes with the server, located at ${was_home}/java. If you don't, you'll waste a couple of hours like me.

2. Place these jars in the classpath:
com.ibm.mq.jar
com.ibm.mqjms.jar
dhbcore.jar
ecutils.jar
j2cImpl.jar
j2ee.jar
messagingClient.jar
naming.jar
namingClient.jar
namingserver.jar
webcontainer.jar
Properties folder. Place all or you'll repent.

3. Websphere works on iiop. So the JNDI props will be com.ibm.websphere.naming.WsnInitialContextFactory and iiop://localhost:2809.

To figure out what jars go in the classpath, it took me almost 6 hours. Extensive googling and some experimentation made the things work. It seems most of the people had a similar experience. Looks like I'm going to have some more tussles with websphere in the near future. Why can't the Websphere be as developer friendly as Weblogic.

Tuesday, January 31, 2006

Year.introspect(2005)

Yesterday,I was arranging my book-shelf to accomodate new books and a paper fell-out. It was a receipt of a book purchased from Gangarams book store, Bangalore, dated Jan 31, 2005. The book, Head First Design Patterns, is still my favorite book. After reading the book, there is a conspicuous change in the way I write code. I have undergone a transformation, hehehe. A friend calls it metamorphosis. I have recommended the book to all my colleagues and the next day there were 5 more purchases of the book.

Incidentally, on the same day Jan 31, 2005, I've put my papers at HP. The co-incidence of the events developed a retrospective urge and made me look back and introspect the last year. I had more >5 offers on hand from good companies at that moment. I've truned down all the offers from companies in Bangalore as the real estate prices skyrocketed and the traffic is horrendous. Subsequently, I decided to relocate to Hyderabad, my native place and narrowed down on a medium sized company doing product development for wealth management segment of the financial industry.

The year was of mixed results, sometimes working more than 14 hours a day and sometimes with absolutely no work for weeks together! oh yeah! there was an onsite trip for 3 months to San Francisco. Oflate, I have become a passionate reader[almost a bookworm ;-)] and mostly I'm reading tech books (currently reading Introduction to Algorithms by Thomas Cormen, Geeeee).Things worked out ,more or less,as expected and the year was a break-even, if not lucrative. Wondering what 2006 has in store for me, wink!

Sunday, January 29, 2006

The Jaipur trip

A week long trip to Jaipur had been full of joy and happiness. I was wondering if I could make it to Vivek's wedding amidst so much work. My manager finally relented and approved a leave for 3 days. Weekend + republic day added 3 more days. 6 days of total fun and joy.

I have known Vivek since my engineering days. He is a Telugu speaking Marwadi :-).
The train journey to Jaipur and back was really entertaining. I travelled along with 40 other friends and relatives of Vivek. There was no need to turn on the mp3 player as the kids were playing anthakhasari non-stop. Though, the particpation from elders (including me) was meagre, it was nice to listen to the Hindi songs.

The marriage and the reception were very elegant and full of activity. I never got a chance to see a traditional north Indian marriage, except in the movies. The baraath was the ultimate. We danced and enjoyed the music played by the band. It was all fun and an unforgettable experience. Look at Vivek on the horse..

Wednesday, December 14, 2005

Capital Markets - a Fascinating Journey

I'm very fascinated by the Capital Markets and their workings. Incidentally, my current work is developing a wealth management solution product that shall be implemented for major banks in US. The current task is to develop the Portfolio Performance pages. Business knowledge and understanding of the performance measurement techniques were impediments to roll out the task on time. A business analyst from the client was sent to provide inputs on the domain

With client's presence in the office and questions getting answered instantaniously, we are in a pretty good shape now. This was more of a learning exercise than just coding. Reading the book "Pratical Portfolio Performance Measurement & Attribution" helped a lot in getting upto speed. More specifically, it helped me to get a clear understanding of the Dietz's formula.

I'm delighted on hearing that I was nominated for a week long training on Financial Concepts and Capital Markets, starting next week. More inputs on the Finance Domain. But, I'm still not an investor ;-)

Sunday, December 04, 2005

My New Laptop

I bought a new laptop on the weekend. It is Compaq Presario V4000/4103AP make with ubiquitous disk space and RAM. The most impressive features are the wide screen and the TFT display, playing Age of Empires/Kings on the laptop is a delight. Now, I can do some serious programming on the weekend and play my favorite games - The Commandos and Age of Empires. Has been trying from a long time to learn Ruby, but that remained elusive due to the tight work schedules, client visits. I hope with the laptop, I'll be an Rubyist soon. :-D

Tuesday, November 29, 2005

Humor: Knowledge Theorem

This blog entry is for those cribbing about their low salaries and comparing their salaries with their friends in other companies. Not intended to hurt anyone's feelings and opinions.To be taken in a lighter spirit.

I received a mail today about something called as the Knowledge Theorem, that states "An Engineer cannot make as much money as the Politicians, artists". The author used the following "inductive procedure" to substantiate the theorem.

Two adages everyone is aware of - "Knowledge is Power" and "Time is Money". If represented mathematically, these two adages would be

Knowledge = Power
- eqn. 1
Time = Money - eqn. 2

High school physics has taught us that

Power = Work/Time.

From eqn. 2, Time = Money, so

Power = Work/Money

From eqn. 1, Knowledge = Power, so

Knowledge = Work/Money

Rearranging the quotient and the divisor would result in

Money = Work/Knowledge

The lesser the denominator, the more is the fraction. Hence proved!
If a person is earning less, that means he is more knowledgable. The converse of the statement is, however, not true.

Wednesday, November 16, 2005

The best description of OO

Had been reading an article titled "OO in One Sentence: Keep It DRY, Shy, and Tell The Other Guy" from pragmaticprogrammer. A funny sounding title, but the content explains the essence of OO in a more interesting way. I liked a particular paragraph so much that I'll quote it all in verbatim:
"The best code is very shy. Like a four-year old hiding behind a mother’s skirt, code shouldn’t reveal too much of itself and shouldn’t be too nosy into others affairs. But you might find that your shy code grows up too fast, shedding its demure shyness in favor of wild promiscuity. When code isn’t shy, you’ll get unwanted coupling."

This is the best description of OO I've heard of so far.

Wednesday, November 02, 2005

AJAX Mania

Oflate, the "ajax" is in the limelight. The technology has created so much excitement among the web developer community and eventually is conferred with laurels. Some of the accolades received are "The next big thing", "revolutionary web technology", "web2.0", etc. The technology indeed has a potential and some applications have leveraged and demonstrated it. The most famous and often cited are the google maps, gmail, flickr.

Recently, rediffmail rolled out a new version of their web mail that offers some goodies implemented using ajax - mail preview, instant download of attachments, drag drop unwanted mails to trash, auto suggest of email ids while composing a mail, etc. It is now pleasure to use rediffmail with all the ajax goodies.

We have an ajax implementation in our product to retrieve information at lower levels from a hierarchically organized data, on click of expand/collapse (+/-). The existing functionality retrieved all the data at once, dumped the data behind the div tags and the selected div would be made visible using javascript. This worked fine for smaller amounts of data and for large data, apparently, became a bottleneck in terms of retrieval and rendering times. Subsequently, the issue has been resolved by implementing ajax. When someone suggested the ajax solution to our chief architect, he suggested some concerns and asked us to explore more for an optimal solution:

1. Browser compatibility - there should be a utility to check for the compatibility of the browser for ajax to serve the ajaxified and no-ajaxified versions accordingly.

2. Increase in the server hits for every ajax call

3. Feedback mechanisms during ajax calls and appropriate messages on the screen

4. Processing order of the ajax calls

5. The change should have a least impact on the existing functionality/code and should be maintenable.

These concerns were very realistic and very soon we realized that ajax is not a panacea. The final solution used ajax at only certain points where it added value. My request to fellow developers and friends is not to get carried away by the excitement, understand the true potential of the technology and implement it at a place where it makes sense.

Friday, October 21, 2005

Updations on XML

I didn't have much work for today except for attending a series of (boring) meetings and churning out word docs and spreadsheets, the weekly status reports and the rest of the junk, tch!. A friend of mine mailed a problem that triggered a deluge of mails with interesting and impressive ways to solve the problem. The hinge point of the problem relied on a XPath expression that should perform a "reverse search" - retrieve all nodes with any attribute having value "abc". Here is my approach:

1. The attribute can be nested anywhere in the document, so my expression starts with //
2. Should return all matching nodes, //*
3. Th test condition is a predicate, //*[]
4. The tricky one, each is a attribute node and can be any attribute,
//*[@*='abc']

That completed the XPath expression.

The complete solution for the problem was decided to be implemented using XQuery. Awesome! Sometime back, I implemented a basic screen scraper (HTML parsing) using XQuery, but that was stop-gap solution and didnot scale well. I'm still a novice to XQuery and wanted to learn the nitty-grrity of the FLWOR expression. As XQuery relies on XPath, I chose to update on the XPath2.0 first. The new version has added functions to make lives easy. Some of such functions are collection,current-date,current-time,implicit-timezone etc. Ofthese, the collection function, apparantly, was found very useful. It can be used to overcome the memory issues with the doc/document() function. This would not only eliminate a round of looping but also offers a clean solution in terms of performance.

Thanks to my friend, my XML arsenal got enriched with new info.

Monday, October 10, 2005

Program to an Interface or Design Pattern

Nowadays, I often hear people saying I used the X design pattern, Y design pattern giving a lengthy list of all the patterns. But when asked what is the motivation behind using a particluar pattern, there is always a stunning silence. Most of the developers these days want to make their resume impressive, so they use every available api and design patterns. The outcome is code that is not readable, bloated and not maintenable.

This reminds me an incident in a well known Telugu movie - the hero wants to learn the fine points of a martial art and want to avenge the death of his brother. The master asks him to realize that the true meaning of the martial arts is Non Violence. The analogy many not be apt, but sensible developers should realize that the design patterns help in producing code that is adhering to the OO principles and code that is maintenable.

Power of XML Entities

I have been using XML for quite sometime in my projects and was quite comfortable with the semantics and syntax. Today, I added a new tool to my XML arsenal - realized the true power of "entities". So far, my understanding of entities is that Entities are variables used to define shortcuts to common text viz. "& copy ;" for © etc. Now, I would like to paraphrase the statement to Entity references are references to entities. The reason for this ...

My requirement was to copy the contents of two config (XML) files into one single config file. The two files are in different directories. I was evaluating the possible solutions to pick an optimal option. A few lines of code did the work, in a elegant way:



<!ENTITY file1 PUBLIC "path1/file1.xml" "path1/file1.xml">
<!ENTITY file2 PUBLIC "path2/file2.xml" "path2/file2.xml">
<root>
&file1;
&file2;
</root>


The entities would get resolved while parsing the file and the contents get copied dynamically. This is such a useful feature, saved lot of LOC and moreover the bottleneck of "transformation" has been avoided. And to display the code fragment correctly on this page, I had to use "& lt ;" and "& gt ;" :-)

Monday, October 03, 2005

A week full of activity

Last week was full of Activity. on Monday and Tuesday, I worked for 14 hours a day under a "unrealistic" target. Whew! Wednesday and Thursday were bit eased up with 10 hours of work. I had to accede to such unplanned and a work without a process as it was a request from the client. Friday was a day of relaxation with absolutely nothing to work on except going thru the BRD of the work for the subsequent week.

On the weekend, I met some of my colleagues from previous companies and the topic immediately was the burgeoning job market in Bangalore and Hyderabad, and interview (er)s. It seems one of them has attended an interview with a major telecom company in Hyderabad. The first round went off well, both the interviewer and interviewee enjoyed the discussion talking many things about technology, issues faced in the project and how they have been resolved. The next round, it seems, was pathetic.

An (incompetent) interviewer with more than 8 years of experience and miserable communication took the second round. I couldnot help laughing when my friend told that the person literally barged into the room, shook hands and immediately asked about JVM architecture and the difference between "==" and ".equals()". My friend got a shock of his life at the crude behavior and started answering with patience. Soon, he realized that the interviewer is expecting bookish answers and is reluctant to accept any answers other than what he had in the mind. My friend should have known "Telepathy". A couple of funny questions and answers from the interview:

Interviewer: "Which method will you use for file upload, doGet() or doPost() "
My Friend:"doPost(), as multipart requests are supported, explained about multipart requests, form processing of the fileupload, limitations with doGet()"
Interviewer:"Fine, but you didn't tell that doGet() doesn't support transfer of binary content."


A more funny interaction occured at a later stage..

Interviewer:"Do you know design patterns? How did you use them in your projects?"
My Friend;"I know core java patterns and J2EE patterns, but don't use them because they are there. If there is a compelling reason, I use a design pattern. In my projects I used Factory, Visitor, Singleton.. the list went on"
Interviewer:"Hold on.. You said Singleton.. How did you use Singleton, How did you implement a Perfect Singleton?"
My Friend: (Routine Question)..gave the bookish answer the interviewer was expecting and the end added "I prefer using registries instead of singletons as singletons are not interface friendly and pose problem in a clustered application"

Now it was the turn of the interviewer to get shocked and it seems he was reluctant to take the answer and started arguing insensibly. My friend remained silent, nodded his head in agreement to whatever the other person said and finally got an offer from the company and now the interviewer is his project lead..hehehe!
These days it is not uncommon to hear about such incidents.

Wednesday, September 21, 2005

A day with Hibernate

I always felt I had a sound understanding of hibernate and offered "expert" advise to my friends over chat/phone. I chanced to get Hibernate in Action and wanted to try out the traditional "Hello World!" example. Immediately fired up Eclipse and started coding, what a pleasure it is to code! I soon realized that my belief is a fallacy as there were exceptions on the console. The exception was org.hibernate.HibernateException: database product name cannot be null. Wrestled with the exception for a couple of hours but in vain. Upon retrospection, I noticed that there was an unwanted line of code

configure.setProperties(System.getProperties());

This line was overriding the properties already loaded by configure() method. If hibernate.cfg.xml is used to configure hibernate, c3p0 pool then the following lines of code would suffice:

Configuration cfg = new Configuration().configure();
SessionFactory factory = cfg.buildSessionFactory();


My hibernate skills are withering and need updation, more pratice is required to keep up the pace.

Friday, September 16, 2005

Code as Design or ????

An interesting conversation with my friend brought out a point of concern - what exactly is software design? I always advocated that programming is essentially designing software, but most of my colleagues differ. I feel that programming is not just building the software but a more *disciplined* process of writing "meaningful" code. There are (increasing)instances of people trying to keep away from coding after they have been conferred august sounding designations by their employers. Unfortunately, some of friends whom I respected tremendously for their coding ability are following this band wagon concept.

One item from such species drew an illustration of Turbine Production. What an example, Duh! His argument was that there will be a separate design team (sitting in plush air conditioned rooms gazing at their monitors and building models, and doing all sorts of simulations) responsible for coming up with design documents and the shop floor uses these designs for production. This model is convincing as long as it is the production of tangible stuff. But, when it comes to software development, the model completely fails. Can Oceanography be applied in the space?

I firmly believe a well written code is a testimonial for good software design. Many seem to differ and vote for designing as an abstract intellectual exercise. I don't want to impose my belief and conclude this entry, I'll update this entry with opinions from my friends and fellow developers.

Tuesday, September 13, 2005

A thought about Spring

I started reading the book "J2EE Design and Development" by Rod Johnson. I should have read this much earlier. It is very interesting and thought provoking book. Intrigued by the reading, I wanted to try out Spring and feel the "IoC". Downloaded the spring framework and started coding my first bean. After gettimg my feet wet, I realized the power of IoC. A very cool concept. Hail Spring!!!

Friday, September 09, 2005

Role of an System Analyst

I have an impressive designation with my employer - System Analyst. Had been chatting with a friend about the roles and responsibilites of a System Analyst, the topic somehow spurred interest and we decided to come up with a summary on what is expected of a (true) System Analyst and later juxtapose it with our current roles.


We chose to explore the job sites and identify the requirements specified by the companies for a System Analyst profile. The following is the (exhaustive)summary we have come up with:
1. Domain
------------
a) Filtering final system requirements, from a free flowing discussion in business terminology.
b) Explaining constraints of technologies chosen to Business Analysts/Domainexperts.
c) Explaining constraints of business requirements to Development team.
d) Conducting process facilitation with clients to identify
organizational,information and integration requirements.
e) Capturing pertinent problem domain information from domain Expert review
sessions.
f) Reviewing system requirements for problem domain completeness.
g) Promoting interoperability of business and technology. Acts as the bridge
between the understanding of the problem domain and the technology requirements.

2. Technical
-------------
a) Developing standards, templates, and procedures to expedite the development
b) Contributing to company wide methodologies.
c) Responsibility for a collection of Use Cases.
d) Disseminating system requirements to the development team.
e) Monitoring the activity within the Online Communities, asking questions
where necessary to support the needs of the project.
f) Assisting the test team to develop test plans and test cases.
g) Has worked extensively as a developer.

3. Management
--------------
a) Assisting in developing project proposals and comprehensive project budgets.
b) Working with Technical Architect and Project Manager to balance business
requirements, technical requirements, and costs.
c) Assisting project management in the understanding and control of Scope.
d) Working independently on strategic issues with client.

Additional good to have Qualities:
----------------------------------
Broad knowledge of business issues and processes such as Strategic Planning, Business Re-Engineering as well as IT resources and enabling technologies.

After reviewing the notes, I wondered if any company hiring system analysts really provides the chaps with good challenging work or is it just an august sounding title.
I must admit that my (little) experience doesn't match the above requirements. Way to go along the long road, buddy!

Thursday, August 11, 2005

SQL for Java Objects

I googled for something and (fortunately) hit upon this. They claim that this library enables querying objects in a collection using a syntax similar to SQL syntax. I tried a few examples and found it living upto the claim. There is another similar open source product from Apache by name JXPath, that uses XPATH syntax instead of SQL. Hmmmm.. some pabulum (atlast!)

Tuesday, July 12, 2005

Importance of equals() and hashCode() ...

An interesting point has been blogged on my friend's blog. It indeed gave some insight into using the equals() and hasCode() methods for objects used in HashMap and the rest java.util.Hash* Collections. One related link in this regard:
http://www.mindprod.com/jgloss/hashtable.html

Tuesday, July 05, 2005

Reading... Reading... and Reading...

Oflate, I've been reading a lot of stuff mostly articles written by Martin Fowler and the nice work on the Thoughtworks website. I chanced to read the article OO Principles and Patterns by Robert C Martin and I liked it very much.
There is a nice book by name "Refactoring to Pattenrs" by Joshua Kerievsky that explains how design patterns can be used to refactor code. I believe that people in the roles of software designers and architects must have a look at these articles.
An interesting quote from one of the Martin Fowler's articles:
"When you no longer code not just can you miss out on changes that occur with this technological flux, you also lose the respect of those who do code."