Monday, August 20, 2007

StreamCruncher 2.2 Beta

Over the past few weeks I've been meddling with the Correlation engine inside StreamCruncher. The 2.2 Release is a result of that ongoing work. "Ongoing" - thus the Beta status. Nevertheless, this release includes changes to the Correlation code (alert..using..when.. clause), with rather drastic changes, in that the Kernel no longer requires the use of the Database to perform Pattern matching! Thereby, increasing performance and decreasing latency several fold.

A new TestCase has been added - CorrelationPerfTest, that demonstrates this wonderful improvement. In this TestCase, there are 4 Streams of Events that are monitored by 3 different Queries, each looking for a distinct Pattern. Since each Query runs in its own group of Threads, the Test scales well on Multi-Core/CPU systems. This Test also generates and consumes large amounts of data and thus serves as a Stress Test too.

Since this is an interim release, there are a few features that are still being developed - like the "case...when.." clause that used to work in previous releases. Now that the Database is no longer being used for Pattern matching, those features that were freely available in the Database are yet to be replicated by the Kernel.

Thursday, August 16, 2007

Instantiate and initialize a HashMap in one statement

There must've been quite a few occasions when you found yourself writing an Interface for your project that stored all the Constants - a centralized place for all the names and values.

In my case, I've had to store not just a bunch of names, but associate some additional descriptions with the names as well. So, how do you do it if you are using an Interface to store these Constants and at the same time initialize them?

Well.. there's a way of creating a HashMap and initializing it with values in a single Statement. All it needs is an Anonymous Inner Class that extends the HashMap and an unnamed code block between Curly Braces. Don't mistake this for the Static code block that we use to load JDBC Drivers. This unnamed block is executed after the instance is created (i.e after the HashMap's Constructor is invoked)

This is how you do it:
[Updated Apr 12, 2012]

public interface ProjectConstants {
    /* Remember, all constants in an interface 
       are "public static final" so you don't have 
       to declare it. */

    Map<String, String> NAMES = 
            Collections.unmodifiableMap(
                    /* This is really an anonymous 
                       inner class - a sub-class of j.u.HashMap */ 
                    new HashMap<String, String>() {
                        {
                            //Unnamed init block.
                            put("homer", "simpson");
                            put("mickey", "mouse");
                            put("eric", "cartman");
                        }

                    });

    .. .. .. .. more constants .. 

    int HIGHEST_ALLOWED_VALUE = 37;
}

Who is James Randi?

James Randi is a world renowned rationalist and skeptic. A "MacArthur Genius Grant" winner, famous for his debunking of Uri Geller, Homeopathy, Auras, Psychics, Faith Healers, Psychic Crimes solvers ... the list goes on. Here's an entertaining list of Videos on YouTube where he does all these.