Tuesday, March 30, 2010

Miscellaneous news and my take

  • US Health Care bill passed - Republicans, too much tea is not good for health.
  • Sania marrying Shoaib - Sad part is India could not produce a single Muslim hunk. Zaheer, Irfan, Yusuf et al, stop going around Bollywood actresses.
  • Ricky Martin is gay - Thanks Adam Lambert for being his inspiration.

Nerd vs Geek vs Dork

Thanks to www.greatwhiteshark.com and a re-tweet from Cameron Purdy here is the difference between Nerd, Geek and a Dork:

Sunday, March 28, 2010

Why blame Karzai?

In 1857 India rose against the British Empire which now is called its first war of Independence - Or at least most of India. After a few early successes the rebellion was crushed and the British were able to do so by keeping a corrupt few together and using them effectively. In the process they structured a new land they could effectively hold and what India became as a nation in 1947 when it eventually got its Freedom. No one knows how this nation could have churned out had the states that revolted against the then East India Company succeeded. But British did so in 1857 not because the Indians were happy under their rule or if they had an overwhelming power, but because they had corrupt friends in some princely states that had power to control. British also had a long term vision for this outpost of its Empire - A united India under one rule of law irrespective of how biased, undemocratic and in-humane that law was.
Afghanistan as it stands today has some roots in how India was a few centuries ago. Independent tribes under one Nation with local laws, customs and rules with no or little centralized control. Corruption in this phase of a nation's evolution could be a good tool if tied with a long term vision for the country. Hamid Karzai, the president of Afghanistan has been blamed for corruption in his government. Appointments not based on merit, a blind eye to Poppy cultivation and under hand deals with local tribal leaders. But if it is effective for not letting them defect to Taliban then what is wrong in it? In a state of chaos choosing a lesser evil sometimes is a path the process of evolution takes. I am in no way proposing a corrupt civil administration in Afghanistan or if he should not be under pressure to tackle it but Karzai still needs the support of the Free world because he has become a pillar for a stable country.

Saturday, March 20, 2010

Thursday, March 18, 2010

Coherence with Spring on OSGi - Oh My!

OSGi has gotten some real traction as an Enterprise services platform. For one of the projects I was involved in a viability study for Coherence with Spring on OSGi recently. Even though not all can be divulged here but we overcame some interesting challenges that are worth to blog about.

Why OSGi? Why Spring? and Why Coherence (Is that a question)?

  • OSGi - It has championed the modularity.
  • Spring - Dependency Injection probably is still its biggest strengths.
  • Coherence - Solves World Peace with simplicity, elegance and Powerful APIs.
  1. OSGi - It needs patience. Lots of it specially if you are just starting with it. You do not need to change the application code to be OSGi compliant. It requires a specific MANIFEST.MF that describes the bundle's attributes and packages it exports and imports with other bundle dependencies. Make sure you have BND handy. I would not recommend you writing the Manifest file your own. Let BND do it for you. Equinox and Knopflerfish are two very popular platforms. I used Equinox.
  2. Spring - Do not work with vanilla Spring APIs. You would need Spring Dynamic Modules that are Spring for OSGi. Also download Springsource Tool Suit. You would need some jars from it's STS to be installed. Also make sure you deploy the 3.0.0 version of the libraries. It will solve a lot of pain you would rather end up going through.
  3. Coherence - Coherence does not have an OSGi bundle off the shelf so you would need to create one. Creating an OSGi bundle for Coherence is fairly easy by using Eclipse IDE. File->New->Project->Plug-in from Existing jar Archives->Select coherence.jar and follow the rest of the instructions. Export the artifact. That's it. Watch out for serialization issues if multiple modules are involved.
Spring DMs:
Install the following modules in the same order (use appropriate start levels):
  1. com.springsource.org.aopalliance
  2. com.springsource.org.apache.commons.logging
  3. org.springframework.aop (3.0.0.RELEASE)
  4. org.springframework.asm ( 3.0.0.RELEASE)
  5. org.springframework.beans (3.0.0.RELEASE)
  6. org.springframework.context (3.0.0.RELEASE)
  7. org.springframework.core (3.0.0.RELEASE)
  8. org.springframework.expression (3.0.0.RELEASE)
  9. org.springframework.osgi.core (1.2.1)
  10. org.springframework.osgi.extender (1.2.1)
  11. org.springframework.osgi.io (1.2.1)
  12. org.springframework.transaction (3.0.0.RELEASE)
  13. com.tangosol.coherence (Or whatever name is given for the Coherence bundle created)
Don't shy away by restarting the Equinox a few times - you may need it.

Lets build a service: Say we want to build a service that puts a String key and a String value in a given data source.

public interface IPut {
public void put (String ds, String key, String value);

For an ability to replace Coherence as a Datasource with another lets use a Template that can be injected by Spring later with Application remaining agnostic to the data source provider.

public interface ITemplate {
public void put(String ds, String key, String val);

Even though IPut and ITemplate are similar it doesn't have to be. IPut represents the exposed service and ITemplate is for persistence.


public class Putter implements IPut {
private ITemplate template;

public Putter(ITemplate template) {
this.template = template;

public void put (String ds, String key, String value) {
if (template != null) {
template.put(ds, key, value);


public class CoherenceTemplate implements ITemplate {

public CoherenceTemplate() {

public void put (String cacheName, String key, String value) {
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
ClassLoader newLoader = com.tangosol.net.CacheFactory.class.getClassLoader();
NamedCache nCache = CacheFactory.getCache (cacheName);
nCache.put (key, value);



Make sure you do have appropriate coherence-cache-config.xml deployed.

Spring beans.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"

<bean name="template" class="CoherenceTemplate" scope="prototype">

<bean name="daoService" class="Putter">
<constructor-arg ref="template"/>


That's not it. We need another configuration to expose this service for OSGi:

<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">
<osgi:service id="daoOSGiService" ref="daoService"

It's also important to place these two configurations under META-INF/spring directory.

What about the MANIFEST.MF?
Use bundlor to generate the MANIFEST.MF for you. You will have to copy the manifest back to the project and then re-bundle the final artifact jar.

Once you have it all together thats all you need to deploy this application on OSGi.

What about the Client now?
Client would be another OSGi bundle and the process of developing it is similar. As it is still all Spring driven make sure the services are appropriately injected.

First the OSGi configuration:

<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">
<osgi:reference id="daoService" interface="IPut"/>

Then for other beans:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean name="persister" class="MyClient"
init-method="start" destroy-method="stop">
<property name="putter" ref="daoService"/>

And the client is like any typical Spring client:

public class MyClient {
IPut putter;

public MyClient () {

public IPut getPutter() {
return putter;

public void setPutter(IPut putter) {
this.putter = putter;

public void start() throws Exception {
putter.put ("MyDataSource", "key", "Value");

public void stop() throws Exception {

Don't forget to use the BND again to generate the manifest and re-bundling it with the client artifact jar.

Now deploy the client jar and start it.


Monday, March 15, 2010

Development problems I hate to get into

Here are my pet peeves when it comes to Software development:

  1. Click New Project and select type 'X' in your Eclipse IDE
  2. Deploying unending Apache libraries
  3. Power-point driven Architectural directions without self-contained working prototypes.
  4. Helpless Component dependencies and NoClassDefFoundError
  5. Having to change standard J2SE modules to work in a specific platform.
  6. URLs in response to RFH that you have already been banging your head on.

Saturday, March 13, 2010

Chevy Malibu shares the Arjun Tank story

A little history - India in mid-70's realized a need of an indigenous MBT and embarked upon once seemed a never ending path. Today after three decades of ups and downs the development of Arjun has been completed as it now competes with world's other Main battle tanks. It will not be an exaggeration to say Arjun is one menacing beast but to no avail because its user has already taken a love route to Russian T-90s that India had purchased in mid 90's more so in panic. Today even though Arjun is a better tank its not going anywhere because folks it was built for have already made up their minds.
This story sounds so similar to what Chevy Malibu is today. I have rented so many cars in past many years and I can say for sure Malibu is one that has impressed me the most. But where does it stand against Toyota Camry and Honda Accord? Even with problems of Toyota if I have to buy one I would rather buy a Camry than a Malibu, renting could be another story. Its called a proven platform in the changing world. I will be ready to give Toyota a pass for its problems because I believe they are serious in delivering the same quality that it once was known for. With GM, no.