Saturday, January 31, 2009

My prediction of Super Bowl

Have a hunch - Its Cardinals. Arizona won't lose this election. Lets see!

Sunday, January 25, 2009

Why are Dev Patel and Frieda Pinto important?

Far far away by shady shores of Arabian Sea lies a reclusive industry called Bollywood. An industry that produces almost 1000 feature movies every year of which 95% go to trash. An industry that once provided a safe channel for under world mafia's to siphon off their black money. But its also an industry that produced some of the pearls of film industry, some we know about and most we don't. This Bollywood produced ever green singers like Kishore Kumar, Lata Mangeshkar, Md Rafi and Manna Dey who have sung some the most difficult songs in some of the most challenging Ragas. No, not much of Hollywood ever heard of them. A few names who once in a while popped up are the ones who were already in their late 30s or 40's. Aishwarya Rai, Om Puri and now Anil Kapoor have made some name but they are too old to carry on or be able to establish any platform for others to take advantage of. Anil Kapoor for example, this not so handsome actor has given some of the most bone chilling performances in Hindi Cinema but remained an unknown till Slumdog Millionaire gave him a role to appear. His performance in SDM is no means any extraordinaire but its about standing on a platform that everyone is looking at. And this platform is called Hollywood. That's why Dev Patel and Frieda Pinto are important. They have not only produced some good performances in an internationally known movie but their age is by their side. And they are known as Bollywood actors.

Happy Republic Day India

60 years ago when the world questioned the framework of India, when they talked about independence of princely states, when nations were created based on religious partitions and questioned the concept of one Bharath, India adopted a secular, democratic and republic constitution. A constitution that guaranteed equal rights to majority and minorities and to Men and Women. A constitution that gave freedom of religious practice, right to speak and right to vote and a constitution that abolished untouchability and titles. It reiterated that Bharath was always one nation be it south, north, east or west or composed of hundreds of quasi independent states. After 60 years we have to salute our visionary leaders that penned down one fact that its not the riches of a few, or one language or one religion and one culture but the real wealth of a nation is in the freedom of its people. The constitution of India was a slap on the face of those who talked about religious division and unilateralism, as Indians that we all should be proud of. A poem to salute the Indian constitution:

Toot ke jaane waale bikhar gaye aur bikhar rahe hain!
Azaad nisha ke Bharathwasi ek rahe the ek rahe hain!!

Monday, January 19, 2009

Has MLK's dreams fulfilled today?

This is a question almost everyone is asking today and many believe it. MLK's dreams were already fulfilled when you had a company's CEO of an African American decent. His dreams were already fulfilled when you talked about your illness to an African American Doctor. His dreams were already fulfilled when you had a business owned by an African American running next to one owned by a White man. Obama's election as the Commander-in-Chief is just the pinnacle and possibly the fruit of his dream. MLK's work reflects one from a similar political and social legend - Dr. B.R Ambedkar of India. Ambedkar's work towards social justice revolutionized India's social equations forever. But India saw leaders from the community which Dr. Ambedkar fought for, becoming State Chief Ministers and even the President of India years ago. But has the struggle stopped? Is social justice achieved? Is the dream already fulfilled? No, Only its face has. The struggle is still on. Unfortunately In India today it has become a tool to play power games. It has become a number game to exploit the Democracy. So the dreams of social justice is not fulfilled when you end up with a President or a Prime Minister, it is fulfilled when he or she makes all and everyone feel equal and the same. The dream is fulfilled not when you have just a black President but when Whites, Asians, Indians and every American looks up to him as his or her own leader. His dream is fulfilled not if the color of the President runs the office but when the Content of his character runs the nation. Obama feels like a sweet breeze and not only Americans but the entire world looks up to him. He stands today on top of MLK's legacy. The legacy that talks not about the color of the skin but the strength of the character. America is proud to elect Obama as it's President now the onus wrests with him to keep all the residents of American nation proud and then only MLK's dream would be really fulfilled.

Sunday, January 18, 2009

Implementing JMS Queue on top of Oracle Coherence

In this series about building JMS on top of reliable and fast Oracle Coherence data grid, I added the functionality of a JMS Queue. Projects like ezMQ re-iterates a fact to perceive Coherence data grid as a high availability System of Record not mere a Cache Provider. The solution to build a JMS Queue is a little tricky compared to implementing a JMS Topic on top of Oracle Coherence. The reason is inherent behavior of Coherence to broadcast the cache events to all Map Listeners. The solution revolves around the following method:

private void dispatchQueueEvent(MapEvent mapEvent) {
EventListener[] eList =
m_listenerSupport.getListeners(AlwaysFilter.INSTANCE).listeners();
int size = eList.length;
MapListener mListener = (MapListener) eList[Base.getRandom().nextInt(size)];
mapEvent.dispatch(mListener);
}
The method collects all the registered Listeners on that Cache node, picks one from the list randomly and dispatches the Map Event to it. Second component is a Custom NamedCache that extends Coherence's WrapperNamedCache. The key method is it's addMapListener ().
    public void addMapListener(MapListener listener, Filter filter, boolean fLite) {
if (singleListener == null) {
singleListener = new InternalListener();
}
m_listenerSupport.addListener(listener, AlwaysFilter.INSTANCE, false);
super.addMapListener(singleListener, filter, fLite);
}
And then at the end an EntryProcessor that makes sure even if Listeners are distributively registered one and only one of those Listeners receive the message. This is done by setting an event dispatch state that every thread checks against before dispatching the event. The class is pretty simple as well:

private class MLSEntryProcessor implements InvocableMap.EntryProcessor, Serializable {

private MapEvent mapEvent;

public MLSEntryProcessor(MapEvent mapEvent) {
this.mapEvent = mapEvent;
}

public Object process(InvocableMap.Entry entry) {
String state = (String) entry.getValue();
if (state == null) {
try {
dispatchQueueEvent(mapEvent);
entry.setValue(STATE.DISPATCHED.name(), true);
} catch (Exception exp) {
exp.printStackTrace();
}
}
return null;
}

public Map processAll(Set set) {
return Collections.EMPTY_MAP;
}

}
More details with more source code has been provided at http://sites.google.com/site/miscellaneouscomponents/Home/ezmq
Enjoy!

Friday, January 16, 2009

Do not forget Mahatma Gandhi

Einstein once said the following on Mahatma Gandhi - "Mahatma Gandhi’s life achievement stands unique in political history. He has invented a completely new and humane means for the liberation war of an oppressed country, and practiced it with greatest energy and devotion. The moral influence he had on the consciously thinking human being of the entire civilized world will probably be much more lasting than it seems in our time with its overestimation of brutal violent forces....
We may all be happy and grateful that destiny gifted us with such an enlightened contemporary, a role model for the generations to come". It seems today we are already forgetting him. Martin Luther King achieved an almost impossible dream following Gandhian Principles and so did Nelson Mandela. Faith in yourself is the first thing that Guns kill. As the world burns today, path that Gandhiji, MLK, Mandela and numerous other leaders who championed non-violent means are being burned as well. Let us remember this January two stalwarts of this era and hope we re-learn the ways they showed our generation and coming ones.

Monday, January 12, 2009

Bush - India loves me

Bush says see India loves me. Yes Sir we do. If 10 terrorist hold the entire Mumbai and the nation hostage for three days and not even a single missile was fired to where they came from or invaded the country then Yes we wished if we had a President like you. Who doesn't love wars? We love retaliations. Why to sit on table to resolve issues and talk and arm twist politically and cut aids and put international pressure to choke hell of their breathing when we can just settle it on the ground with Guns and Missiles? Would we be the first to do so? Romans did it. Alexander did it all the time. Our history is full of it. Europe is built on top of wars. Did we forget our own history? Don't we know what works and what does not? If political drama would have worked why United Nations had sucked so much? World wars were fought and the major actors became super powers. War is good. It makes you a super power. At least it makes you feel like one. So what if you lose moral standings, you lose economy, you lose 401K but you should never lose the pride of showing your muscles. After all Men are meant to fight. Yes Sir we love you. Can we outsource our Presidency?

Saturday, January 10, 2009

Integrating Oracle Coherence with Twitter

Months ago I wrote a program to integrate Calendar with Twitter. This time I integrated Twitter with Coherence data grid. Programmatically this is no brainer - data are being put in a Coherence Cache and then there is a cache listener that publishes the data (message) to twitter. I am a big fan of Twitter. Simple interface, Revolutionary idea and an Awesome channel. So what I did is expanded my implementation of JMS Subscriber for Oracle Coherence and added an interface to tweet the JMS Message. Read more about ezMQ here.... Following is a sample code that is a subscriber of Coherence Topic and a Publisher to Twitter:

public class Subscriber implements MessageListener {

private String un = "<your_twitter_account_id>";
private String pw = "<your_twitter_password>";

public Subscriber() {
}

private void twitter (String message) throws MalformedURLException,
IOException {
String credentials =
new BASE64Encoder ().encode ((un + ":" + pw).getBytes());
URL url = new URL ("http://twitter.com/statuses/update.xml");
URLConnection uC = url.openConnection();
uC.setDoOutput(true);
uC.setRequestProperty("Authorization", "Basic " + credentials);
OutputStreamWriter wR = new OutputStreamWriter (uC.getOutputStream());
wR.write("&status=" + message);
wR.flush();
wR.close();

// -- Get the response back
BufferedReader bR =
new BufferedReader (new InputStreamReader (uC.getInputStream()));
String line = null;
while ((line = bR.readLine()) != null) {
System.out.println(line);
}
bR.close ();
}

public static void main(String[] args)
throws Exception {
Subscriber s = new Subscriber ();
InitialContext ctx = new InitialContext();

// -- Create
TopicConnectionFactory factory =
(TopicConnectionFactory) ctx.lookup("TopicConnectionFactory");

// -- Connecting to Proxy
TopicConnection connection = factory.createTopicConnection();

// -- This is a NamedCache
Topic topic = (Topic) ctx.lookup("Topic");

TopicSession subSession =
connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
TopicSubscriber subscriber = subSession.createSubscriber(topic);
subscriber.setMessageListener(s);

System.out.println("Click to end");
System.in.read();
}

public void onMessage(Message message) {
try {
TextMessage tMsg = (TextMessage) message;
String text = tMsg.getText();
// -- Send the message to Twitter
twitter(text);

} catch (JMSException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace ();
} catch (IOException e) {
e.printStackTrace ();
}
}
}
Enjoy!

Friday, January 09, 2009

An Open letter to United CEO

Hello Sir,
I have been flying United for a number of years and chose this Airlines in hope of a good and on-time service. My friends call me crazy for the level of travel I have done and my body has adapted to it. My work typically requires me to take long flights and of course to places where time difference matters. It gets frustrating when the flights are delayed for hours as it not only disturbs my schedule but puts a lot of pressure on my body. I am not talking of delays due to weather or Air traffic control. Lately it has been happening due to technical failures of the aircraft. Take an example, reaching at 2AM and then sleeping at 4 does no good to me to be at work next morning at 9. Reaching home late spoils the entire next day too. I am no President of United States but my time is precious as well. Clients do not care if my flights were delayed and I hope you understand it. I do not want to leave the kind of work I am doing because United Airlines is adding more stress than I already get myself into. Remember, I have a choice too.

Regards,

Wednesday, January 07, 2009

Implementing JMS with Oracle Coherence

I have come across many applications that use JMS infrastructure to pass messages from one system to another. If you are already using Oracle Coherence or thinking of employing one then for many scenarios you do not need to have another messaging provider. ezMQ is an effort to provide a JMS implementation on top of Oracle Coherence. Do not confuse this project with Coherence's Incubator Messaging Pattern. The scope and target use cases are different even though it can be easily integrated. So if you are fed up with additional licenses for a JMS provider for straight forward usecases or looking to consolidate the infrastructure, the project ezMQ lets you keep your current application unchanged and gets it integrated with Coherence infrastructure by replacing and deploying just a few configuration files. The project is a stab to address this unique problem space and even though does not guarantee to work in all scenarios but the code is available for free download, make updates to and share it further. More details on ezMQ can be found at http://sites.google.com/site/miscellaneouscomponents/Home/ezmq
If you have an application similar to the following then you can use Oracle Coherence as the JMS provider by using ezMQ APIs. The only change set the jndi.properties or the Context.PROVIDER_URL.

public class Client implements MessageListener {
public void someMethod () {
Properties env = new Properties();
env.setProperty(Context.PROVIDER_URL, "...");
InitialContext ctx = new InitialContext(env);

TopicConnectionFactory factory =
(TopicConnectionFactory) ctx.lookup("TopicConnectionFactory");
TopicConnection connection = factory.createTopicConnection();
Topic topic = (Topic) ctx.lookup("Topic");

addSubscriber(connection, topic);
publishMessage(connection, topic);
}

private void publishMessage(TopicConnection connection, Topic topic)
throws JMSException {
TopicSession pubSession =
connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
TopicPublisher publisher = pubSession.createPublisher(topic);
TextMessage message = pubSession.createTextMessage();
message.setText("Ashish");
publisher.publish(message);
}

private void addSubscriber(TopicConnection connection, Topic topic)
throws JMSException {
TopicSession subSession =
connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
TopicSubscriber subscriber = subSession.createSubscriber(topic);
subscriber.setMessageListener(this);

}

public void onMessage(Message message) {
try {
TextMessage tMsg = (TextMessage) message;
String text = tMsg.getText();
System.out.println("On Message: " + text);
} catch (JMSException e) {
e.printStackTrace();
}
}
}
This version of ezMQ is pretty basic and does not implement all the bells and whistles of other popular JMS providers but it works beautifully and provides a platform to expand.
How is it implememted? There are two aspects of creating a JMS implementation:
  1. Taking care of JNDI
    • Context (EzContext)
    • Context Factory (EzContextFactory)
  2. Taking care of JMS
    • Topic (EzTopic)
    • TopicConnection (EzTopicConnection)
    • TopicConnectionFactory (EzTopicConnectionFactory
    • TopicSession (EzTopicSession)
    • TopicPublisher (EzTopicPublisher)
    • TopicSubscriber (EzTopicSubscriber)
    • TextMessage (EzMessage)
So take a look and enjoy!

Saturday, January 03, 2009

A bug in Ojc

And is likely to be fixed soon... An illegal construct that gets compiled by Ojc:

public interface IA {
public void doSomething ();
}
public interface IAExtend extends IA {
public void doSomething () throws IOException; // -- Illegal
}
Ojc compiles it fine that should have failed.