Friday, September 28, 2007

Coherence - A reminder to self

Coherence is not about speed. It is about (horizontal) scalability and a very predictable performance. And, its system of records is the cache. The rest are reactive components.

The horoscope of the day

As I continue to not believe in horoscopes, here is one I saw which made me curious how the heck does he/she know?
" This is a good day to start listening to your body, ASHISH. You tend to push yourself very hard. It's quite possible that you always feel a little tired or run down. This could be for one simple reason. You need more sleep! If you are used to sleeping only six hours a night, start scheduling eight hours. Your body might need more time each night to repair and rid itself of toxins."

Thursday, September 27, 2007

Kids misadventure and a reunion

The pretext of the story is we had lost communication with a good friend of ours (Ex-Sun too), when he decided not to respond to our voice mails or emails. It was not just for me but to the entire friend circle and we had the suspicion of this being deliberate. The reasons known only to him.

Today, My Mom calls me from home asking if I had called her. It was already night and I thought it was some advertising solicitation call. I checked on the website and the number was (508). Coincidence, this week I am in Boston too where the call came from. Hmm, somebody might be trying to reach me I thought and called that number back which I rarely do unless there is a voicemail. Found, he has moved to Boston, has bought a house and his kid had "accidentally" dialed the number. After a few embarrassing moments and a few lame excuses he invited to visit his place. It will be fun to visit him and see him "caught".

Tuesday, September 25, 2007

Coherence Contd. Listening the cluster

I am assuming my other blogs related to Coherence has been read. The nodes in a cluster are also called Members. Like Cache events, cluster also generates events when a Member joins, leaving or left. Say, if we need to clear some of the resources if a Member leaves or dynamically increase the pool size of a resource when additional members join in (I don't know, I am just making the requirements up!). Here is a sample code showing where and how to do it:

NamedCache nCache = CacheFactory.getCache ("Cache");
nCache.getCacheService ().addMemberListener (new MemberListener () {
final Member local = nCache.getCacheService ().getCluster ().getLocalMember ();
public void memberJoined (MemberEvent evt) {
// -- The Member which the event is associated to
Member eM = evt.getMember ();
// -- Do the fancy stuff

public void memberLeaving (MemberEvent evt) {

public void memberLeft (MemberEvent evt) {

And thats it again!

Sunday, September 23, 2007

Is this an end of Sachin and Ganguly era?

Cricket has a new form - The Twenty20: Fast, exciting and rapid fire. T20 tournament has been a success and is seems the future of the world cricket. This form of the game has also exposed some of the weeknesses of Aussies, the undisputed champions otherwise. For India, Dhoni and Yuvi have led the team to excellence. There is a new blood, new enthusiasm and the killer instinct which had died after Chappel took the reigns. T20 finals is also a message to not write off this sub-continent yet. For India, a win in the finals will be bugle of a new young team and an opportunity for stalwarts like Sachin and Ganguly to retire from the active ODI duty.

Thursday, September 20, 2007

The Presidential Candidates

Hillary - Buy one get one (Bill) free.
Obama - I am sick, I am sick, I am sick.
Romney - So what if I look rich?
McCain - Atleast listen to me!
Giuliani - Presidentship is scope creep.
Edwards - Hang on, the rest will falter.

Wednesday, September 19, 2007

Tell me why?

BBC ran a story on the ever elusive Green card. Here are some scripts:

**When Pankaj Kakkar sang the American national anthem on the Capitol Hill lawns,
Congressman Jim McDermott commented: "Son, you sing it better than me."

Unfortunately, this compliment does not take Mr Kakkar, a computer professional
working for Google, any closer to the Green Card dream he has been chasing for the
past 11 years.

**Meenal Sinha says not having a Green Card means you have to stick with the same
company that got you a work visa - and that means fewer promotions and salary rises.

"We have given the most productive years of our careers to this country. We have
always played by rules, yet this endless delay," she says.

**"It's so embarrassing when our peers ask, 'You don't have a Green Card yet?',"
says Niti

**A study by Harvard University warns of "increasing frustration among skilled
immigrants who have to wait for years for a permanent residency".

Thursday, September 13, 2007

Coherence Contd.. Some more things

Oracle Coherence is all about [Fast access to Coherent] data. Having said that lets dive a little deeper. I came across a funny definition - It is the costliest implementation of java.util.Map. Coherence is also a Data Grid. Its a Data Cluster solution. The nodes in a cluster can partition data among themselves and provide access to it. It won't be possible to use any off-the-shelf Map's implementation in particular partitioned cache strategy. Why? Take the fastest data-structure for Map.. Its java.util.HashMap. To access data from it we either need a key or iterate through it. You can not Query the data like SQL does on database tables. Its also an event-less data structure. Wouldn't you like to receive events if the data has been updated or Inserted or removed? HashMap could not do that. There are also concurrency issues in a Clustered environment. Hmm, it so sounds like a database table. Even though logically but actually it is. When we talk about data in a networked environment, we should also talk about latency. One of the strongest features of Java is to move the code/processor to where the data are. Anyone remember Java Applets? Instead of passing data to the processor, the Code can be downloaded to where the data are. What does it buy us? Ask the System Administrators who manage hundreds of nodes spread across slow and unreliable network. The network latency kills applications.
Now lets talk about Coherence' most important APIs. If you had read my earlier Coherence blogs: this and this you already know how to use NamedCache. implements java.util.Map. Why? Because its a Cache and you would need functionalities like get and put. But, here is the difference - it also implements other interfaces like:

  • com.tangosol.util.QueryMap

  • com.tangosol.util.ConcurrentMap

  • com.tangosol.util.ObservableMap and,

  • com.tangosol.util.InvocableMap.

Rang a bell yet? Aren't these features required in a Clustered data grid? Thats what makes Coherence' NamedCache the costliest implementation of java.util.Map. Costly in a sense for features you would like to pay for.
I tend to blabber much before the real thing. So You already know how to use the Cache and Query the cache. If you have followed my sample codes before you know how to populate data in the cache. We have Objects in the Cache now, and we need to use it isn't it? What do you use data for? Just to access it? Yes but not necessarily always. You want to do computation on it. You may want to do some mathematical operations on the Objects or its' attributes. Lets take an example of a Student database. You may wanna know whats the average age or height or weight of your students. And why not? You may want to compete against the strongest football team in the league and you have to know these stats before you sign up. To do these computations, Coherence provides an API called Aggregator. The concept is simple, provide a set or a subset of data to your Aggregator to do computation on. Oracle Coherence provides a ton of off-the-shelf implementations for AbstractAggregator. The following sample code uses one of them - A AbstractDoubleAggregator.

Lets say, your Serializable Object is the following:

#SClass - Student's class
public class SClass implements ExternalizableLite {
private int height;
private String name;

public SClass() {

public void setName(String a) { = a;

public String getName() {
return name;

public String toString() {
return name;

public void readExternal(DataInput dataInput) throws IOException {
height = ExternalizableHelper.readInt(dataInput);
name = ExternalizableHelper.readSafeUTF(dataInput);

public void writeExternal(DataOutput dataOutput) throws IOException {
ExternalizableHelper.writeInt(dataOutput, height);
ExternalizableHelper.writeSafeUTF(dataOutput, name);

public void setHeight(int height) {
this.height = height;

public int getHeight() {
return height;

So, if you want to take a Sum of the heights of your class for the students with name starting letter [A]... What do you do? You know it. You create a Filter...

NamedCache nCache = CacheFactory.getCache ("Students");
// -- Populate the data
Filter filter = new LikeFilter ("getName", "A%");
Set keySet = nCache.keySet (filter);
// -- Now what? The keySet has a Set of Students with names starting with A
Double result = (Double) nCache.aggregate (keySet, new CacheAggregator ());

Now, what is this CacheAggregator? CacheAggregator is the implementation of
AbstractDoubleAggregator and here is its code:

import ....
public class CacheAggregator extends AbstractDoubleAggregator {
public CacheAggregator() {

protected void init(boolean b) {
m_dflResult = 0.0;

protected void process(Object object, boolean b) {
if (b) {
// -- What the heck is this? Scroll down for the explanation
m_dflResult += ((Double)object).doubleValue();

} else {
SClass sC = (SClass)object;
// -- Keep on adding the Heights
m_dflResult += sC.getHeight ();

protected Object finalizeResult(boolean b) {
return new Double(m_dflResult);

So, what does it do? When the aggregate () method is invoked on a Cache, the process () method is called for each Cache Entry in the keySet. The example is a little tricky. Why? Usually the input and output types for an Aggregator are the same. You provide a Student and you get a Student. In this case, you are providing a Student but at the end you are expecting is its' height. Input is SClass but output is a Double.

And here you go.. By using this example you can build more complex Computations on on your data Objects.

The issue of Adam's Bridge or Ram Sethu

A new issue has been cropping up in India around the historic Adam's bridge or Ram Sethu between Southern India and Sri Lanka. There was a myth (?) that to fight off an evil King Ravana, Lord/King Rama and his army built a floating bridge over the ocean. That myth seemed right when NASA took some pictures and found a similar structure submerged in water. Indian government however has been working on a new maritime route for past few years which will require to destroy "that" structure. Archaeological Survey of India has given a new statement recently that on Historic grounds existence of Lord Rama can not be established. The books like Valamiki Ramayana and Tulsidas' Ramcharit-Manas can not be considered as historic artifacts. I am not sure what can be considered a historic artifact? Geographically, story of Rama has spanned from North to all the way to Southern India. The temples and other places of evidence found are so interconnected that its highly impossible that this being mere an imaginative story. The numbers could be wrong. It may not be even a bridge or not built around the same era, or a natural extension of the Earth mass, even the concept of a "Year" could be wrong but I don't think there should be any question regarding the existence of an Aryan King Rama which Hindus consider an Avatar of Vishnu. We should be dealing with these issues the other way round though. Instead of asking if Rama existed, prove that he did not. If can not then the beliefs of millions of people should be respected. Destroying the structure will not negate the importance of Rama in Indian social and religious lives but keeping it will only strengthen it. And besides, don't give the political parties an opportunity to make this a national issue.

Monday, September 10, 2007

Single liners

1. If Barack does not succeed then Romney has already won.
2. Want a BMW? Get your car detailed. You can keep your dreams alive this way.
3. Its better to struggle with technology than with products.
4. If you call a Horse a donkey and a Mule a horse, what would you call an ass?
5. I even tried with the jar twice in the CLASSPATH.
6. Don't keep the bread runners unfed.
7. If your Dog wants to say something then listen to him.
8. If he was that stupid why was he elected twice?
9. Dye Osama dye.
10.Don't tip your manager for his/her work. He already earns more than you do.

Saturday, September 08, 2007

The irony of Osama's videos

The numerous videos released by Osama in past 6 years have gone down from Horror documentaries to Comic skits. From "Oh My Gosh, he released a new Threat" his messages have transformed to "What the heck is he saying now?" or "Darn is he still alive?". His new call for Americans to convert and relating it to the Iraqi war is not only ridiculously insane but hysterically funny. I am not sure if he asked the 19 of his terrorists to count the number of Muslims in the WTC before realizing their heinous crime. Somebody please tell him, the combined earnings of NFL and NBA players of Muslim faith is far more than the GDP of most of the countries his organization operates from. The only irony is even after six years of 9/11 and billions of dollars spent, he has still managed to buy a shit load of magnetic tapes, a video camera and a few packs of hair dye.

Thursday, September 06, 2007

Coherence Contd.. Querying Cache

One of the features of Coherence is that it provides a "Queryeable" data structure. So if you followed my last blog you already know how to populate data in a Cache. A Cache is typically like a Database table and only one "type" of values should be stored. Even though a Cartesan product can be implemented (Storing two types of data in the same table) but should be avoided. Assuming the Cache service is running and has data in it, the following class shows how to use Filters to make a Query. It is important that the Cache does have data in it and not expired before the query can be run against it.

package com.ezduck.coherence;


import com.tangosol.util.Filter;
import com.tangosol.util.filter.LikeFilter;

import java.util.Map;
import java.util.Set;
import java.util.Iterator;

public class QueryCache {

private static NamedCache nCache;

static {
nCache = CacheFactory.getCache("Name");

public QueryCache() {

public static void main(String[] args) {
QueryCache queryCache = new QueryCache();
// -- Look for Names which starts with A
Filter filter = new LikeFilter ("getName", "A%");
Set set = nCache.entrySet(filter);

Iterator iter = set.iterator();
while (iter.hasNext()) {
System.out.println ("Val: " + ((Map.Entry);


And Thats it!

Tuesday, September 04, 2007

Hamare Hockey mein Chhakke nahi hote

A must watch movie for Bollywood lovers - "Chak de India"

Monday, September 03, 2007

CPI, Please explain

After opposing the Indo-US nuclear deal, the CPI and its isotopes are now opposing a joint Naval exercise in the Bay of Bengal with the Quad members which includes India, US, Japan and Australia along with Singaporean presence. Now, Could CPI explain this action? Why do their nerves get ticked when it comes to China? Do they report to 1450 Kms west or 3200 Kms North? And for their own records, just a few months back India and China conducted a joint naval exercise.

Sunday, September 02, 2007

Problem with Google's algorithm

Here is a Google Ad that appears on my Blog on Barack Obama. The Ad is exactly opposite and demeaning to what I write about him. All of my blogs on Obama has mostly praises and appreciations with some constructive criticism on him. So, instead of similar sentiments, what does the automated Google Ad show? "Obama exposed!". Is their Grammar analysis tool all screwed up? I think their Researchers are missing the point with counting words and index driven popularity rankings. They are efficient in analyzing single Sentences but seems failing miserably on how Sentences join to create one Sentiment. How difficult is to implement the following?

Read the text (Like the blog(s))
Find the Subject (Like a Person)
Break the text in individual sentences
Create Two maps - Positive and Negative
Analyze each Sentence, Rank the words and fill the maps.
Look for words like "All I said", "Aforementioned", "Contrary to what I said", etc
and add a weight to the Map entries.
Count the entries in the map.
If one is higher than the other by 80%, then find a Positive Ad or vice-versa.