Tuesday, November 24, 2009

Thanks Congress for giving BJP what they wanted... An Issue

Burdens of past should not drag the wishes of future. Ram Temple is a similar issue that has become a playground to gain political mileage. Its in the news again and of course thanks to Congress for giving BJP an issue, once again. You would be politically naive to believe BJP leadership had no knowledge of plans of bringing the disputed structure down while in power in the state where it happened. Level of involvement of its leaders could be debatable but their ignorance is something that can not be believed. It can not be believed in a similar way as if the structure was a center of any relevance in the middle of a Temple town, the birth place of Ram. The disputed structure was less of a religious importance to Muslims in India than being a relic of the history. It neither represented Islamic culture nor an icon of introduction of Islam in India other than a thumping sign of Victory of a Muslim King over the local Hindu rulers. The place also called Masjid-i-Janmasthan was a place where till late 19th century Hindus and Muslims prayed together peacefully. Today more than a few centuries later we have a constitution to respect and abide by that is key to the survival of Indian democracy and is also the life line of our individual identities. BJP who championed the cause of reconstruction of Ram temple, after losing a series of recent political battles and thoroughly rejected by people sees this issue as a life source of its own existence. This is what BJP wanted and so does the Samajwadi Party who got rejected by its own traditional Muslim electorate in the recent elections. BJP is not for Hindus, so not SP for Muslims and Congress is no champion of secularism either. So it is now up to the common mass to scream and let them know that one of the most pious places of Hindu religion can't be used to spill blood of any fellow Indians irrespective of their religious beliefs or its bloody past.

Sunday, November 15, 2009

The clouds from above

मैं क्या कहूँ इन बादलों को देख कर यूँ अब?
लगें नीचे से नम आँखें और ऊपर से मेरे सपने।
सुनहरे सुर्ख फूलों कि ये लम्बी नर्म सी चादर,
बिछी इक छाओं सी ऊपर चाहे ये हमे ढंकने।
या शायद है ये इक नदिया बहे जो यूँ तूफानी सी,
और पानी हैं मेरे सपने जो बादल बन सदा बरसें।

Friday, November 13, 2009

My Name with ditaa

Sunday, November 01, 2009

Functional Programming with Coherence

If you come across the following, don't get surprised. Its called Functional programming.

object FP {
def doSomething (callback: () => Unit) {
def letsPrint() {
println ("Ha ha!");
def main (args: Array[String]) {
doSomething (letsPrint)
Functions in Scala are treated as Objects that can be passed around. The concept of Object has still not changed - Its a place holder of application state. So in Functional Programming Model, functions are states and if it is legal then why not manage them in a state repository like Oracle Coherence?

Problem Statement: Executing new Entry Processors without having to deploy them in the cluster and continue to achieve 100% up time?

In a simpler English it means how can I push new EntryProcessor(s) and execute them without having to bounce the cluster to deploy the new class. The solution lies in the concept of Functional Programming - Passing functions to the Executor but this time slightly in a different way. Lets again, begin with a cache configuration:
<!DOCTYPE cache-config SYSTEM "cache-config.dtd">




EPFeeder Cache is where we store the Functions (Implementations of process() method of the EntryProcessor) against the EP's class name. EPCache is a demo cache where your data resides and you would be executing new EPs against. Next Step is to see how the client code will look like:
public class DynaCUtilTest extends TestCase {
private String getEPImpl() {

StringBuffer sBuffer = new StringBuffer();
sBuffer.append("public Object process (Entry entry) {");
sBuffer.append ("System.out.println(\"In process\");");
sBuffer.append ("System.out.println(\"Key:\" + entry.getKey());");
sBuffer.append ("System.out.println(\"Value:\" + entry.getValue());");
sBuffer.append("return null;");

return sBuffer.toString();

public void testCreateEP()
String impl = getEPImpl();
String clzName = "EPClass_v1";
NamedCache eCache = CacheFactory.getCache("EPFeeder");
eCache.put(clzName, impl);

NamedCache nCache = CacheFactory.getCache("EPCache");
nCache.invoke("A", new EPClass_v1());
getEPImpl () is the implementation that we would replace the process() method with as we feed new EP classes, in this case the first version of it named EPClass_v1. So what happens next?
When a new implementation is put in the EPFeeder Cache, A Backing Map Listener picks up this event and creates a new class (EntryProcessor) on all the cluster members dynamically using an Invocation Service. This step achieves 100% up time for Coherence. The Backing Map Listener (EPListener) looks something like this:

public class EPListener extends MultiplexingMapListener {

public EPListener() {

protected void onMapEvent(MapEvent mapEvent) {
String key = ...;
String impl = ...;
InvocationService iS =
Invocable inv = new EPCreator (key, impl);
// -- Create a new Class on all nodes
Set set = CacheFactory.getCluster ().getMemberSet();
iS.query(inv, set);

The core of this listener is the magic EPCreator Invocable but before we look at the EPCreator let see an EPInterface:
import com.tangosol.util.InvocableMap;

public interface EPInterface extends InvocableMap.EntryProcessor {
The most critical piece of this puzzle is the Invocable and how it does its magic. The EPCreator executes the following in it's run() method. Lets put it in its own Util class (DynaCUtil):
    public static Class createEP(String clzName, String impl) {
ClassPool pool = ClassPool.getDefault();
Class clz = null;
CtClass eClass = null;
boolean shouldCreate = false;
try {
eClass = pool.get(clzName);
} catch (NotFoundException e) {
shouldCreate = true;
if (shouldCreate) {
eClass = pool.makeClass(clzName);
eClass.setInterfaces(new CtClass[] {
pool.makeClass("EPInterface") });
try {
} catch (CannotCompileException e) {
try {
eClass.addMethod(CtNewMethod.make(impl, eClass));
StringBuffer sBuffer = new StringBuffer ();
sBuffer.append ("public java.util.Map processAll(java.util.Set set) {");
sBuffer.append ("System.out.println(\"In processAll\");");
sBuffer.append ("return java.util.Collections.EMPTY_MAP;");
sBuffer.append ("}");
eClass.addMethod (CtNewMethod.make (sBuffer.toString(), eClass));

} catch (CannotCompileException e) {
try {
clz = eClass.toClass();
} catch (CannotCompileException e) {

What the heck was it? The Invocable uses JavaAssist to create a new EntryProcessor on the fly. Now the last question is as Coherence is a self-healing system where new nodes can join and leave anytime, how to make sure new EP Classes are available to the new nodes? And the answer is a Custom NamedCache which also is the last piece in the puzzle. The class would look something like the following:

public class DynaEPCache extends WrapperNamedCache {

public Object invoke(Object oKey, InvocableMap.EntryProcessor agent) {
String name = agent.getClass().getName();
createEP (name, (String) CacheFactory.getCache("EPFeeder").get (name));
return super.invoke(oKey, agent);

public Map invokeAll(Collection collKeys, EntryProcessor agent) {

private void createEP (String name, String impl) {
if (impl == null) {
throw new RuntimeException ("EntryProcessor not created yet!");
DynaCUtil.createEP(name, impl);

A much more advanced implementation is sitting on my laptop that a pieces I will soon upload to http://sites.google.com/site/miscellaneouscomponents/Home. In the meantime just Enjoy!

Why should I pay a single penny for Windows 7 upgrade from Vista?

I bought a Sony Vaio with Vista Home premium edition about a year ago. It looked good with new Apple-type interface and I brought it home. It did not take me long to find this was the worst OS Microsoft has ever produced. The most irks I got to find out that I could not VPN to my work network as it failed to connect. With no Vista support offered by my Company I was stuck and had to continue with my other very bulky Dell with XP. This weekend I had a chance to look at Windows(7) at a local BestBuy. It did not feel even a little different from Vista. Now Microsoft is asking for $129 upgrade fee for it. Why? When did I ever use my Vista properly at the first place? You sell me a buggy, practically non-working OS and then asking for a fee to get it fixed, if they have? Isn't this keeping Vista users hostage? Unless I shelve another $129 on top of a costly purchase that we already had made they do not have any other options. For me Windows(7) has already failed in the first week of its launch.