Hazelcast: Java分布式内存网格框架
hazelcast是一个开放源码集群和高度可扩展的数据分发平台,这是为Java:
1. 快如闪电;数以千计的运算/秒。
2. 故障安全;崩溃后没有丢失数据。
3. 作为新服务器的动态调整 。
4. 超级简单的使用 ,包括一个单独的jar。
Hazelcast与各种分布式数据结构,分布式缓存功能,弹性的性质,memcache的支持,与Spring和Hibernate的集成,更重要的是这么多的快乐用户,是功能丰富,企业的准备和开发人员友好的内存数据网格解决方案。
Hazelcast是一个Java的开源分布式内存实现,它具有以下特性:
01 Distributed implementations of java.util.{Queue, Set, List, Map}
02 Distributed implementation of java.util.concurrent.ExecutorService
03 Distributed implementation of java.util.concurrency.locks.Lock
04 Distributed Topic for publish/subscribe messaging
05 Transaction support and J2EE container integration via JCA
06 Distributed listeners and events
07 Support for cluster info and membership events
08 Dynamic HTTP session clustering
09 Dynamic clustering
10 Dynamic scaling to hundreds of servers
11 Dynamic partitioning with backups
12 Dynamic fail-over
13 Super simple to use; include a single jar
14 Super fast; thousands of operations per sec.
15 Super small; less than a MB
16 Super efficient; very nice to CPU and RAM
安装也非常方便:
1 Download hazelcast-version.zip from www.hazelcast.com
2 Unzip hazelcast-version.zip file
3 Add hazelcast.jar file into your classpath
要使用分布式的Map,只需要以下代码即可实现:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
import
com.hazelcast.core.Hazelcast;
import
java.util.Map;
import
java.util.Collection;
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”));
Collection colCustomers = mapCustomers.values();
for
(Customer customer : colCustomers) {
//
process customer
}
Hazelcast的官网上面有一个非常直观的视频:http://www.hazelcast.com/screencast.jsp,建议有兴趣的朋友花10分钟时间看看。
还有一份PDF可以参考:http://roma.javaday.it/javaday2010/sites/default/files/ClusteringHazelcast-javaday.pdf。
Hazelcast作为一款与ZooKeeper类似的开源实现,我在网上找了一篇相关的文章:http://blog.armstrongconsulting.com/?p=132 在这篇文章中有一段这样写道:
I had occasional hangs with Hazelcast 1.8.4 which caused me to switch to Zookeeper. As expected, Zookeeper was a lot harder to use than Hazelcast – you need Zookeeper installed on 3 servers. There’s no official java client, just some recipes and I found an implementation of Zookeeper locks called Cages on google code. For a java developer, Hazelcast is obviously way easier to use.
另外,在Hazelcast的官方文档中,提到了Hazelcast的集群机制:
If there is no existing node, then the node will be the first member of the cluster. If multicast is enabled then it will start a multicast listener so that it can respond to incoming join requests. Otherwise it will listen for join request coming via TCP/IP.
If there is an existing cluster already, then the oldest member in the cluster will receive the join request and check if the request is for the right group. If so, the oldest member in the cluster will start the join process.
In the join process, the oldest member will:
send the new member list to all members
tell members to sync data in order to balance the data load
Every member in the cluster has the same member list in the same order. First member is the oldest member so if the oldest member dies, second member in the list becomes the first member in the list and the new oldest member.
从上边的文字来看,它的这种集群机制是内置的。可以拿来直接使用。
它分好几种版本:
hazelcast企业版
hazelcast企业版(EE)商业授权版的Hazelcast。 它有附加功能,如弹性记忆和安全。
hazelcast弹性记忆
默认情况下,,Hazelcast商店的分布式数据(映射条目,队列中的项目)这是垃圾收集的Java堆。 为您