- 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.
Tuesday, March 30, 2010
Miscellaneous news and my take
Posted by Ashish at 10:44 AM 0 comments
Labels: humor
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:
Posted by Ashish at 10:36 AM 0 comments
Labels: humor
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.
Posted by Ashish at 2:10 PM 0 comments
Labels: Politics
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.
- 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.
- 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.
- 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.
Install the following modules in the same order (use appropriate start levels):
- com.springsource.org.aopalliance
- com.springsource.org.apache.commons.logging
- org.springframework.aop (3.0.0.RELEASE)
- org.springframework.asm ( 3.0.0.RELEASE)
- org.springframework.beans (3.0.0.RELEASE)
- org.springframework.context (3.0.0.RELEASE)
- org.springframework.core (3.0.0.RELEASE)
- org.springframework.expression (3.0.0.RELEASE)
- org.springframework.osgi.core (1.2.1)
- org.springframework.osgi.extender (1.2.1)
- org.springframework.osgi.io (1.2.1)
- org.springframework.transaction (3.0.0.RELEASE)
- com.tangosol.coherence (Or whatever name is given for the Coherence bundle created)
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.
Implementations:
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);
}
}
}
And,
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();
Thread.currentThread().setContextClassLoader(newLoader);
NamedCache nCache = CacheFactory.getCache (cacheName);
nCache.put (key, value);
Thread.currentThread().setContextClassLoader(oldLoader);"
}
}
Make sure you do have appropriate coherence-cache-config.xml deployed.
Configurations:
Spring beans.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd>
<bean name="template" class="CoherenceTemplate" scope="prototype">
</bean>
<bean name="daoService" class="Putter">
<constructor-arg ref="template"/>
</bean>
</beans>
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"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgi="http://www.springframework.org/schema/osgi"
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"
interface="IPut"></osgi:service>
</beans>
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"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgi="http://www.springframework.org/schema/osgi"
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"/>
</beans>
Then for other beans:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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"/>
</bean>
</beans>
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 {
System.out.println("Goodbye");
}
}
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.
Enjoy!
Posted by Ashish at 5:06 PM 0 comments
Monday, March 15, 2010
Development problems I hate to get into
Here are my pet peeves when it comes to Software development:
- Click New Project and select type 'X' in your Eclipse IDE
- Deploying unending Apache libraries
- Power-point driven Architectural directions without self-contained working prototypes.
- Helpless Component dependencies and NoClassDefFoundError
- Having to change standard J2SE modules to work in a specific platform.
- URLs in response to RFH that you have already been banging your head on.
Posted by Ashish at 6:51 PM 0 comments
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.
Posted by Ashish at 12:51 PM 0 comments
Labels: Misc