This post originated from an RSS feed registered with Java Buzz
by Talip Ozturk.
Original Post: Introducing Distributed MultiMap
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.
Don't you love Google Collections MultiMap stuff? I love it. Apache Collections also have it. It is great for one to many relations. If you've never heard of it, you should definitely check it out. MultiMap is a specialized map where you can associate each key with multiple values. One-to-Many!
So we thought it would be really cool to have a distributed version of it. Here we go... Hazelcast Distributed MultiMap:
import com.hazelcast.core.MultiMap;
import com.hazelcast.core.Hazelcast;
import java.util.Collection;
// a multimap to hold customerId-Order pairs
MultiMap mmCustomerOrders = Hazelcast.getMultiMap("customerOrders");
mmCustomerOrders.put("1", new Order ("iPhone", 440));
mmCustomerOrders.put("1", new Order ("MacBook Pro", 2400));
mmCustomerOrders.put("1", new Order ("iPod", 79));
// get orders of the customer with customerId 1.
Collection colOrders = mmCustomerOrders.get ("1");
for (Order order : colOrders) {
// process order
}
// remove specific key/value pair
boolean removed = mmCustomerOrders.remove("1", new Order ("iPhone", 440));