This post originated from an RSS feed registered with Java Buzz
by Talip Ozturk.
Original Post: Hazelcast 1.4: Distributed Events and more
Feed Title: Shared Memory
Feed URL: http://www.jroller.com/talipozturk/feed/entries/rss
Feed Description: about java, jcache, jini, javaspaces, distributed data structures and a little bit of me and life.
For the new readers of this blog, Hazelcast is a 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 I would like to introduce you the Distributed Topic here in this entry. 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 (oztalip at gmail dot com).