Sunday, December 28, 2008

Congratulations Kashmir

Congratulations for reaffirming democratic values in the state of Kashmir. After the height of militancy the first elections saw 10% of turnout, this time it was 63% well over the national average across states. Its not about being pro-India or pro-Pakistan or pro-freedom. Not all democracies of the world are pro-India and not all Islamic nations are pro-Pakistan but it was important for Kashmir to show that they still cherish the democratic system and its values. Mere the fact that majority has rejected the Jehadi color of the movement is a victory of Kashmiri people that has been strengthened by a call of introspection from the separatist leaders like Sajjad Lone and Mirwaiz. A strong showing of BJP in Jammu is also a reminder to the state legislation not to ignore this region and be used in pity politics. Congratulations to the young chief minister of the state Omar Abdullah as well for bringing in welcome change overdue to the state of Kashmir.

Friday, December 26, 2008

Don't we just love Pakistani Foreign Ministry?

01. Elements in Pakistan abetted, trained and sent terrorists to Orchestrate Mumbai massacre.
02. Refuses to accept the lone captured terrorist is from Faridkot Pakistan.
03. Refuses to accept the plea of that terrorist for legal help.
04. Cordons off the village from media where the captured terrorist hails from.
05. No concrete steps to punish responsible groups and closing the terror camps.
06. Creates war hysteria.
07. Blames India for Lahore blast which with in days claimed by a Pro-Taliban group.
08. After international pressure black mailing the world by mobilizing troops from Afghanistan to Indian border (Has been their trump card for years).
09. Their Airforce running low sorties creating panic among Pakistani people and building anti-India sentiments.
10. And, their national leaders passing inflammatory comments against India.
So commit the crime and then scream you were a victim. BS! And what the world is doing? Sleeping?

Wednesday, December 24, 2008

Please save this kid Tiger

A two and a half year old Tiger has been ordered to be shot dead by UP Govt, India. Reason? He has turned a man eater. This Tiger had sneaked out of it's habitat about a month ago and has been meticulously avoiding any effort to nab him since. Sadly he killed one teenager last week in search for food. If a lethal bullet can be fired so can a tranquilizer. This is a plea to wild life officials to not kill this magnificent animal. If we do not have guts to kill the hyenas who masterminded killings in Mumbai, why can't we have mercy on this little four legged Terrorist who has no guns? Be a human not an animal.

Tuesday, December 23, 2008

Coyotes in back yard

Sunday, December 21, 2008

Discovering Processor in Coherence - Part (II)

In the part (I) of this blog I touched a concept of managing the processing components in Coherence cache. In part (II) I am introducing a half-cooked implementation where agents can be looked up and downloaded in Coherence. The idea is to construct an infrastructure where Enterprise components can advertise their services on a lookup service and these services can then be downloaded and executed in Coherence grid. This implementation uses Jini with Oracle Coherence. The component targeted is EntryProcessor with some customization to manage java.rmi.Remote requirement for Jini and keeping it away from Coherence. I have uploaded probably a 70%ish implementation on Miscellanous Components site. The project is built using jDeveloper11g and requires coherence.jar and Jini2_1 libraries. It is still incomplete from where it has to go but has ample food for thoughts.
Components used:

  1. A Custom Cache
  2. Jini2_1 for discovery
  3. InvocableMap APIs to customize EntryProcessor
  4. And Coherence Infrastructure

Sunday, December 14, 2008

In defence of Bush

Being disliked at home and getting thrown a pair of shoes in Iraq - the focal point of his foreign policy, I am sure are enough reasons for any common man to go in depression and of course with depressed economy it is not good to be George Bush. But as human nature goes we forget the intangibles. Once we get a Wii to play with we forget what effort it took to get one. Look around people. Some parts of the world live under constant fear of terrorism. What happened in Mumbai is a reminder that we are not safe yet. Only stupid will question the intent, resolve and wish of organizations that attacked us to do it again. Lets not forget not a single terrorist attack has occurred in past seven years on the soil of United States of America. And don't you think that credit goes to Bush? In wave of our own anger lets not forget what good this Man has done for us. I am sure the Guy who threw shoes at Bush must have forgotten what if he had done the same to Saddam. Whether we like Bush or not but he does not deserve this hatred either by an American or an Iraqi. I hope he is remembered in history as a man of resolve who cared about his country more than he cared about himself.

Friday, December 12, 2008

Softer part of Software Architecture

Or the harder part the way you look at it. Almost 90% of applications does the following in some form or the other.

  1. Bring message (data) from one system to another.
  2. Transform the data in a form that your system recognizes.
  3. Process the data
  4. Making it available for reference
  5. Send it to another system
  6. Archive it
Critical things to consider:
  • How many components do we introduce between each of these steps?
  • How much latency does each component introduce?
  • How many jars/libraries would you need to get this system to work?
  • Can I upgrade one layer without affecting others?
  • How many systems do you need to configure?
  • If one system is unavailable can others survive?
  • How platform independent is one system from another?
  • Can we have single script/single click deployment process?
  • How many people would you need and of what different skill set?

Tuesday, December 09, 2008

Discovering Processor in Coherence - Part (I)

Besides a strong support for event driven architecture Oracle Coherence has a concept of processors running inside the grid. One construct that makes Coherence programming a little different is its ability to invoke light weight processes inside the grid instead of bring data over the wire and then processing it. To do so the application has to pass an agent to the cache that gets executed on the data. It is not necessarily required to pass a fully implemented one though.
Problem statement: To have an ability to change the implementation of the processor on the fly and without having to re-deploy it.
Following approach is inspired by Coherence's Command Pattern but lets start from the beginning. We need to create a common interface that all commands need to implement:

public interface Command extends Serializable {
public Object process (Object object);
}

These are the commands that will be looked up instead of being passed an instance of. Lets have a few implementations:
public class MyLogger implements Command {...} and,
public class MyProcessor implements Command {...}

We need a place to put these commands in.
<!DOCTYPE cache-config SYSTEM "cache-config.dtd">
<cache-config>
<caching-scheme-mapping>
<cache-mapping>
<cache-name>Command</cache-name>
<scheme-name>distributed-scheme</scheme-name>
</cache-mapping>
</caching-scheme-mapping>
<caching-schemes>
<distributed-scheme>
<scheme-name>distributed-scheme</scheme-name>
<service-name>DistributedCache</service-name>
<backing-map-scheme>
<local-scheme></local-scheme>
</backing-map-scheme>
<autostart>true </distributed-scheme>
</caching-schemes>
</cache-config>

Now how to execute these commands in such a way that execution logic can be changed but executor does not? I like Map Listeners because it can be attached to a cache in multiple ways and also provides a framework for auto-processing.
For the sake of simplicity lets implement the following logic: For each entry put in the cache run a process on that entry but process that can be changed. Listener will look something like:
public class DiscoveryListener implements MapListener {
private String cacheName;
private static NamedCache dCache;

static {
dCache = CacheFactory.getCache ("Command");
}

public DiscoveryListener(String cacheName) {
this.cacheName = cacheName;
}

public void entryInserted(MapEvent mapEvent) {
Command command = (Command)dCache.get (cacheName);
Object value = mapEvent.getNewValue();
if (command != null) {
command.process (value);
}
}
....
}

And of course load the processors in the command cache:

NamedCache cCache = CacheFactory.getCache ("Command");
cCache.put ("cache1", new MyLogger ());
cCache.put ("cache2", new MyProcessor ());

And, depending on the cache the listener is attached to it will run the corresponding command. What it gives you an ability is to change the MyLogger () to SomeProcessor () for a cache on the fly and the rest of the application remains agnostic.
What's next?
Problem statement has still not been fully implemented.
  1. We still need to deploy all the processor classes and has to be available at the deployment time. This has to change.
  2. Why to use the Command interface? Could it be something else?
  3. Who puts the Commands in the Command cache? Can we have a Command feeder? An external controller that dictates what gets executed?

Saturday, December 06, 2008

Why using static block for Singleton will not work in all cases

Probably everyone has used Singleton pattern and following is a typical implementation:


public class Single {
private static Single single;

// -- Rule#1: Make sure no one outside the class could call new
private Single () {
}

// -- Rule#2: Provide another channel to get an instance
public static Single getInstance () {
if (single == null) {
synchronized (Single.class) {
if (single == null) {
single = new Single ();
}
}
}
return single;
}
}
I came across another implementation that to be frank I never thought was used to implement singletons.

public class Single {
private static Single sing;

static {
sing = new Single ();
}

private Single () {
}

public static Single getInstance () {
return sing;
}
}
Even though its a tricky way but bluntly this is a wrong implementation for one simple reason: It does not work if the class is lazily loaded (Class.forName ("Single");) and constructor takes a parameter. So I would rather continue to stay with a good old implementation.