Saturday, December 13, 2008

GGBLOG – Dynamic Distributed Data Clustering on OSGi

If you’ve followed some of my past posts you’ll notice I try to keep my examples small and as simple as they need to be. If I were to describe my programming style its very much back to basics and I’m a huge proponent of simplicity.

I’ve whipped up a small example of how you can distribute data dynamically on OSGi using Hazelcast 1.4. I’ve really only scratched the surface of what you can do with this but thought I’d write up my first experiences with this light weight simple yet powerful framework.

Running the Example.

Download the cluster.zip example source code from:

https://sourceforge.net/project/showfiles.php?group_id=228168&package_id=302726&release_id=647048

Unzip the cluster.zip and start up 2 instances of eclipse 3.4. Open up the node1 and node2 directories in different instances of eclipse.

Click run light weight cluster in both instances of eclipse and Jetty should start up on port 9091 and 9092.

Open up two web browsers and in the first browser paste the following URL which will set cVal in a distributed Map on the first node.

http://localhost:9091/sample?cVal=Glenn

In the second browser paste the following:

http://localhost:9092/sample?check=true

If you see the following you have successfully setup a dynamically distributed data cluster.

Where’s the magic?

If you have a look at SampleServlet.java the magic is on line 27 and 32 where we get the map and set a value. Hazelcast makes it look like we are dealing with an ordinary map but the reality is that it possesses extraordinary distributed capability.

If you have any questions on the demo feel free to drop me a line (glenn.galang@gmail.com) or head on over to hazelcast.com.

1 comment:

Alan said...

good stuff. I agree the hazelcast stuff is great. Did you see it was just open sourced today under the apache license (http://code.google.com/p/hazelcast/)

The ability to build a simple shared transaction shared storage that works between web apps (even with a different name) and stand alone servers / applications (ie. admin consoles) is great.