Hazelcast 1.0: Distributed Queue, Set, Map, and Lock
Ads by DZone
Hazelcast, clustering and highly scalable data distribution platform for Java, is now ready to rock and roll! Features:
- Distributed implementations of java.util.{Queue, Set, List, Map}
- Distributed locks via java.util.concurrency.locks.Lock
- Support for cluster info and membership events
- Dynamic discovery
- Dynamic scaling to hundreds of servers
- Dynamic partitioning with backups
- Dynamic fail-over
Superness:
- Super simple to use; include a single jar.
- Super fast; thousands of operations per sec.
- Super small; less than a MB.
- Super efficient; very nice to CPU and RAM.
Where to use it:
- share data/state among many servers
- cache your data (distributed cache)
- cluster your application
- partition your in-memory data
- distribute workload onto many servers
- provide fail-safe data management
Code Samples:
//distributed queue sample..
java.util.Queue q = Hazelcast.getQueue("tasks");
q.offer(myobj);
Object myobj = q.poll();
//distributed hash map sample
java.util.Map mapCustomers = Hazelcast.getMap("customers");
mapCustomers.put("1", new Customer("Joe", "Smith"));
mapCustomers.put("2", new Customer("Ali", "Selam"));
mapCustomers.put("3", new Customer("Avi", "Noyan"));
Iterator itValues = mapCustomers.values().iterator();
while (itValues.hasNext()){
Customer customer = (Customer) itValues.next();
itValues.remove();
}
//distributed hash set sample
java.util.Set set = Hazelcast.getSet("IBM-Quote-History");
set.add(new Price(10, time1));
set.add(new Price(11, time2));
set.add(new Price(12, time3));
set.add(new Price(11, time4));
//....
Iterator it = set.iterator();
while (it.hasNext()) {
Price price = (Price) it.next();
//analyze
}
//distributed locks
java.util.concurrent.locks.Lock lock = Hazelcast.getLock (new MyObject());
lock.lock ();
try {
// do some stuff here..
} finally {
lock.unlock();
}
if (lock.tryLock (5000, TimeUnit.MILLISECONDS)) {
try {
// do some stuff here..
} finally {
lock.unlock();
}
}
//cluster interface sample
Cluster cluster = Hazelcast.getCluster();
cluster.addMembershipListener(new MembershipListener(){
public void memberAdded(MembershipEvent membershipEvent) {
System.out.println("MemberAdded " + membershipEvent);
}
public void memberRemoved(MembershipEvent membershipEvent) {
System.out.println("MemberRemoved " + membershipEvent);
}
});
Blog: http://jroller.com/talipozturk
Website: http://www.hazelcast.com
- Login or register to post comments
- 2634 reads
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)










Comments
Peter Strand replied on Wed, 2008/07/02 - 7:06am
Where are the docs for this API ?
Not in the download - and not on the website ?
Specifically, I wanted to know if is possible to avoid multicasting as a discovery tool ? If you want to run this in Amazon EC2, multicast'ing is not really an option
Talip Ozturk replied on Wed, 2008/07/02 - 7:31am
Unfortunately there is not much docs on Hazelcast yet. Information at hazelcast.com and jroller.com/talipozturk is all we got so far. But you are right, it needs to be better documented. I will start working on it.
Many people asked for non-multicast discovery support so Hazelcast-1.1 will have it.
Thanks for the feedback.
-talip
Talip Ozturk replied on Mon, 2008/11/03 - 10:14am
in response to: hrstrand
Hazelcast (as of 1.1) now can work in none-multicast environments. I am actually testing Hazelcast on Amazon EC2.
Regards,
-talip
Peter Strand replied on Mon, 2008/11/03 - 3:33pm
Talip,
how cool!! -- I'll try it out
thanks,
Peter