Talip has posted 10 posts at DZone. View Full User Profile

Hazelcast 1.4: Distributed Events

11.03.2008
| 7297 views |
  • submit to reddit
Hazelcast is a free distributed/partitioned queue, map, set, list, lock and executorservice implementation for Java. 1.4 release focuses on distributed events and messaging.

What is new:

  • Add, remove and update events for queue, map, set and list
  • Distributed Topic for pub/sub messaging
  • Integration with J2EE transactions via JCA complaint resource adapter
  • ExecutionCallback interface for distributed tasks
  • Cluster-wide unique id generator

Hazelcast documentation covers all these new features already but lets go over the Distributed Topic feature together. No configuration is needed to run the following code. Just download the zip, add the hazelcast.jar into your project, and run the following code on 5 JVM instances. You have cluster of 5 JVMs for pub/sub messaging! No config, no nothing...

 

 import com.hazelcast.core.Topic;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.MessageListener;

public class Sample implements MessageListener {

	public static void main(String[] args) { 
		Sample sample = new Sample();
		Topic topic = Hazelcast.getTopic ("default");  
		topic.addMessageListener(sample); 		
		topic.publish ("my-message-object");
	}  
	 
	public void onMessage(Object msg) {
		System.out.println("Message received = " + msg);
	} 
}
 

I hope the new Topic is simple and functional enough. Remember that topic operations are cluster-wide. If you add a MessageListener from member M, you will receive all messages published by any member in the cluster, including the new members joined after you added the listener.

Listeners will process the events/messages in the order they are actually fired/published. If event A occurred before event B on cluster member M, then it is guaranteed that all of the listeners of these events in the cluster will process event A before B.

Documentation at hazelcast.com covers all these new stuff with code samples so please visit the site for details.

What is next? Extending the Queue implementation to java.util.concurrent.BlockingQueue and some other cool stuff. Complete list of planned features can be found here. Got interesting feature in mind, let me know.

Website: http://www.hazelcast.com

Weblog: http://www.jroller.com/talipozturk

Group  : http://groups.google.com/group/hazelcast

 

0
Published at DZone with permission of its author, Talip Ozturk.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)