所需积分/C币:50 2014-02-28 15:37:37 1.54MB PDF
收藏 收藏

Hazelcast 是面向 Java 的缓存、集群及数据分发解决方案。特性包括:提供java.util.{Queue,Set,List,Map}分布式实现。提供java.util.concurrency.locks.Lock分布式实现
Table of contents Introduction I.I. Getting Started (Tutorial) 2. Distributed Data structu 2.1. Distributed Queue 2. 2. Distributed Topic........... 2.3. Distributed map… 2. 1. Backups 2.3.2.EⅤ iction. 456789 2.3.3. Persistence 2.3.4. Query.... 2. 3.5. Near Cache 13 2.3.6. Entry Statistics ·· 2.3.7.Ind 15 2. 4. Distributed MultiMap......... 15 2.5. Distributed set 2. 6. Distributed list 16 2.7. Distributed lock 16 2. 8. Distributed events 17 3. Elastic Memory (Enterprise Edition Only) .· 18 4. Security (Enterprise Edition Only) 19 19 42. Cluster module 20 4.3. Cluster Member Security 4. 4. Native client st 4. 4.1. Authentication 22 4. 4.2. Authorization 4.4.3. Permissions∴ 24 5. Data Affinity ·········“····· ··“········*····· 申非 ·······*···· 28 6. Monitoring with JMX 7. Cluster Utilities 7.1. Cluster Interface 33 7. 2. Cluste Generator 7.3. LiteMember……… 33 8. Transactions 34 8. 1. Transaction Interface 8.2.J2 FE Integration….… 8.2.1. Resource Adapter Configuration 35 8.2.2. Sample glassfish v3 Web Application Configuration 36 8.2.3. Sample JBoss Web Application Configuration 36 9. Distributed Executor 37 9. 1. Distributed execution ..37 9. 2. Execution Cancellation 38 93. Exccution Callback 39 10. Ittp s Clustering with hlazelcastwm 11. WAN Rep 44 12. Configuration 46 12. 1. Creating Separate Cluste 47 12.2. Network Configuration 48 12.2. 1. Configuring TCP/IP Cluster 48 12. 2. 2. Specifying Network Interfaces 48 12.2.3. EC2 Auto dise 12.2.4. Network Partitioning(Split-Brain Syndrome) 49 12.2.5.SSL 12.2.6.EI 52 12.2.7.S ntercept Hazelcast documentation 12. 2.8. IPv6 Support 12.3. Partition group configuration 55 12.4. Listener Configurations…… 56 12.5. Wildcard Configuration 12.6. Advanced Configuration Properties 60 12.7, Logging Configuration…… 62 12.8 Setting License Key (Enterprise Edition Only 63 13. Hibernate Second Level Cache 14. Spring Integration ........ 7 14. 1. Configuration 67 14.2. Spring Managed Context 69 14.3. Spring cache… 14.4. Hibernate2 nd Level Cache Config…..,..,.,,…,… 14.5. Spring data-JPA 14.6. Spring Data-MongoDB 15. Clients∴ i5. Native client 75 76 15.1.2. CSharp Client (Entcrprise Edition Only) .76 15,2, Memcache client∴…………78 15.3. Rest client∴ 79 16. Internals 16.1. Internals 2. serialization 80 16.2. Internals 3: Cluster Membership 8 16.3. Internals4: Distributed Map…… 82 17. Management Center…,……,… 17.1. Introduction 17.1.1. Installatic ············· 17. 1.2. User Administration 17.13. Tool Overview 17. 2. Maps 85 17.2.1. Monitoring Maps 85 17.2.2. Map Browser 86 Map configuration… 86 17.3. Queues 86 17.4. Topics.…,…,…,…,,…,…,87 I7. 5. Members +++++ 87 ng 88 17.5.2. Operations… 88 17.6. System Logs… 88 17.7. Scripting 89 17. 8. Time travel 89 17.9. Console 18. Miscellaneous 18.1. Common Gotchas 18.2. Testing Cluster 18.3. Planned Features 95 18.4. Release notes 1V List of tables 12. 1. Properties Table Chapter 1 Introduction Hazelcast is a clustering and highly scalable data distribution platform for Java. Hazelcast helps architects and developers to easily design and develop faster, highly scalable and reliable applications for their businesses Distributed implementations of java.util.Queuer Set, list, Nap) Distributed implementation of java. util. concurrent. ExecutorService Distributed implementation of java. util. concurrency. locks.Lock Distributed Topic for publish/ subscribe messaging Transaction support and J2EE container integration via JCA Distributed listeners and events Support for cluster info and membership events Dynamic Http session clustering Dynamic clustering Dynamic scaling to hundreds of servers Dynamic partitioning with backups Dynamic fail-over 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 To install hazelcast: Downloadhazelcast-version.zipfromwww.hazelcast.com[http://www.hazelcast.com] Unzip hazelcast- version. zip file Add hazelcast jar file into your classpath Hazelcast is pure Java JVMS that are running Hazelcast will dynamically cluster. Although by default hazelcast will use multicast for discovery, it can also be configured to only use TCP/IP for environments where multicast is not available or preferred ( Click here for more info). Communication among cluster members is always TCP/IP with Java NIO beauty Default configuration comes with 1 backup so if one node fails, no data will be lost. It is as simple as usingjava. util [Queue, Set, List, Map). Just add the hazelcast. jar into your classpath and start coding 1.1. Getting Started (Tutorial) In this short tutorial, we will create simple Java application using Hazelcast distributed map and queue. Then we will run our application twice to have two nodes (Jvms)clustered and finalize this tutorial with connecting to our cluster from another Java application by using Hlazelcast Native Java Client API DownloadthelatestHazelcastzip[http://www.hazclcast.com/downloads.jsp] Unzip it and add the lib/hazelcast. jar to your class path. Introduction Create a Java class and import hazelcast libraries Following code will start the first node and create and use customers map and queue. import com. hazelcas-. core. Hazelcasti import java. util. Map; import java.util. Queue public class GettingStarted I public static void main(string[] args)( Map<Integer, String> mapCustomers Ilazelcast getMap("customers") na cUstomers put(,"Joe") mapCustomers.put(2,Ali)i mapCustomers. put(,Avi )i printin("Customer with key cUstomers get(1))i out println(Map Size: mapCustomers size())i QueuecString> queueCustomers Hazelcast getQueue("customers") of=er("Tom queueCustomers.ofFer("Mary)i queueCus omers of=er("Jane")i System. out. println("First customer: -queueCustomers poll())i System. out. println("Second customer queueCust omers peek()) System. out. println(Queue size: queueCustomers size()) Run this class second time to get the second node started Have you seen they formed a cluster? You should see something like this Members [2]t Member[] Member[]this Connecting hazelcast Cluster with Java Client API Besides hazelcast. jar you should also add hazelcast-client. jar to your classpath Following code will start a llazelcast Client, connect to our two node cluster and print the size of our customers a package com. hazelcast cesti import com. hazelcast,client. ClientCon-igi import com. hazelcast. client. Hazelcastclient import com. hazelcas= core. Hazelcastinstance import com. hazelcast. core. IMap; public class GetingStartedclient public static void main(String[] args)( ClientConfig client Config= new ClientConfig()i clien-Config. addAddress("127.0.0. 1: 5701) Ha.zelcastInstance client HazelcastClient newHazeicastC-ient(clientconfig) IMap map- client getMap("customers") System. out. println('May Size: I map size())i When you run it, you will see the client properly connects to the cluster and print the map size as 3 Introduction What is Next? Youcanbrowsedocumentation[http://www.hazelcast.com/docs.jspandresourcesfordetailedfeaturesandexamples YoucanemailyourquestionstoHazelcastmailgroup[http:iigroups.googlecom/group/hazelcast] YoucanbrowseHazelcastsourcecode[http:icode.google.com/p/hazelcast/source/browse/#svn/trunk] Chapter 2. Distributed Data Structures Common Features of all hazelcast data Structures Data in the cluster is almost evenly distributed (partitioned) across all nodes. So each node carries(1/n* total-data)+ backups, n being the number of nodes in the cluster If a member goes down, its backup replica that also holds the same data, will dynamically redistribute the data including the ownership and locks on them to remaining live nodes. As a result, no data will get lost When a new node joins the cluster, new node takes ownership(responsibility) and load of-some -of the entire data n the cluster. Eventually the new node will carry almost(1/n total-data)+ backups and becomes the new partition reducing the load on others There is no single cluster master or something that can cause single point of failure. Every node in the cluster has equal rights and responsibilities. No-one is superior and no dependency on external 'serveror master kind of concept Here is how you can retrieve existing data structure instances(map, queue, set, lock, topic, etc )and how you can listen for instance events to get notified when an instance is created or destroyed import ava. util. Collectioni Hazelcast import ccm, hazelcast core Ins tance; import ccm. hazelcast. core. Instancelistener public class sample implements Instancelistener I public static void main(String[] args)( e azelcast. addInstancelistener(sample)i Collection<Instance> instances Haze_cast. getIrstances(i for (Instance instance System. out.printin(instance. getInstanceType()+ ,"+ instance getId() public void instanceCreated(InstanceEvent evert)( Instance instance event getinstance(i System. cut. println("Created t instance. getTrstanceType()t t instance getTo() ublic void d(TnstanceFvent event) i Instance instance event getInstance( System. out. println(" Destroyed instance getIrstancelype()+",+ instance. ge=Id()i 2.1. Distributed Queue Hazelcast distributed queue is an implementation ofjava.util. concurrent. BlockincQueue import ava.util. concurrent. BlockingQueu BlockingQueue<MyTask> q= Hazeicast. getQueue("tasks")i g put (new MyTask()) take( boolean c=fered- g c=fer(new MyTask(), 15, TimeUrit SECONDS)i cas< =gpoll(5, TimeUnit SECONDS )i f(t 4 Distributed Data Structures If you have 10 million tasks in yourtasks"queue and you are running that code over 10 JVMs(or servers ), then each server carries 1 million task objects(plus backups ). FIFO ordering will apply to all queue operations cluster-wide User objects(such as My k in the example above), that are(en/de)queued have to beserializable Maximum capacity per JVM and the ttl (Time to Live) for a queue can be configured Distributed queues are backed by distributed maps. Thus, queues can have custom backup counts and persistent storage Hazelcast will generate cluster-wide unique id for each element in the queue Sample configuration hazelcast> <queue name="tasks"> MaximUm e of the queue. When a UVM's Iocal queue size reaches the maximun, ail put/offer operations will get blocked until the queue size of the uvM goes down below the maximum Any integer bet ween s and Integer. MAX VALUF. 0 means Integer. MAX VATUF. De fault is o ize-per-ivm>10000</max-size-per-ivm> ame of the map configuration that will be used for the backing distributed mao Iar this queue ret queue> t>l</backup-cou <map-store enabled="true"> <class-name >com. your, company. storage. DBMapStore</class-name> <write-delay-seconds></write-de lay-secords> </map-store> </hazelcast> If the backing map has no map-etore defined then your distributed queue will be in-memory only If the backing map has a map-store defined then Hazelcast will call your Map Store implementation to persist queue elements. Even if you reboot your cluster Hazelcast will rebuild the queue with its content. When implementing a Mapstore for the backing map, note that type of the key is always Long and values are the elements you place into the queue. So make sure Mapstore loadAllKeys returns Set<long> for instance To learn about wildcard configuration feature see wildcard Configuration page. 2.2. Distributed Topic Hazelcast provides distribution mechanism for publishing messages that are delivered to multiple subscribers which is also known as publish/subscribe (pub/sub) messaging model Publish and subscriptions are cluster-wide. When a member subscribes for a topic, it is actually registering for messages published by any member in the cluster, including the new members joined after you added the listener. Messages are ordered, meaning, listeners( subscribers ) will process the messages in the order they are actually published. If cluster member M publishes messages ml, m2, m3. mn to topic T, then hazelcast makes sure that all of the subscribers of topic t will receive and process ml, m2, m3.mn in order. Therefore there is only single thread invoking onMessage. The user shouldn 't keep the thread busy and preferably dispatch it via an executor This will increase the performance of the topic

试读 106P hazelcast-原版文档
立即下载 低至0.43元/次 身份认证VIP会员低至7折
xiaoxiaozhiqiang 文档是真的 , 感觉这个种技术有点落伍了
  • 分享宗师

关注 私信
hazelcast-原版文档 50积分/C币 立即下载

试读结束, 可继续阅读

50积分/C币 立即下载 >