hazelcast-scala-example

所属分类:其他
开发工具:Scala
文件大小:0KB
下载次数:0
上传日期:2014-06-06 10:55:43
上 传 者sh-1993
说明:  使用Hazelcast、Spray和Akka的内存数据网格的示例,
(An example of an In-Memory Data Grid using Hazelcast, Spray and Akka,)

文件列表:
.travis.yml (159, 2014-06-06)
LICENSE.txt (519, 2014-06-06)
activator.properties (173, 2014-06-06)
build.sbt (361, 2014-06-06)
project/ (0, 2014-06-06)
project/build.properties (18, 2014-06-06)
src/ (0, 2014-06-06)
src/main/ (0, 2014-06-06)
src/main/scala/ (0, 2014-06-06)
src/main/scala/hazelcast/ (0, 2014-06-06)
src/main/scala/hazelcast/ApiActor.scala (1180, 2014-06-06)
src/main/scala/hazelcast/ChildActor.scala (707, 2014-06-06)
src/main/scala/hazelcast/Main.scala (457, 2014-06-06)
src/main/scala/hazelcast/Messages.scala (207, 2014-06-06)
src/main/scala/hazelcast/MomActor.scala (674, 2014-06-06)
tutorial/ (0, 2014-06-06)
tutorial/index.html (2770, 2014-06-06)

hazelcast-scala-example ======================= [![Build Status](https://travis-ci.org/dvallejo/hazelcast-scala-example.svg?branch=master)](https://travis-ci.org/dvallejo/hazelcast-scala-example) # What is Hazelcast? Hazelcast is an in-memory data grid technology. By using Hazelcast, in-memory distributed data structures can be easily implemented. This kind of structures are very useful for sharing key data among several hosts, among other uses. The example in this template implements a server and a client that share an IMap (distributed map). This map will represent a shopping list. One instance, aka the mother, can add and remove items from the list. The other instance, aka the child, can only read the elements in the list. Let's see how this is implemented. # Hazelcast Server In order to create an IMap, a Hazelcast instance must be created first: ``` val hazelcastInstance = Hazelcast.newHazelcastInstance(new Config()) ``` Afterwards, an IMap named "shoppingList" is created. This map contains the name of the item of the shopping-list and the number of items of that type: ``` val shoppingList = hazelcastInstance.getMap[String, Int]("shoppingList") ``` The logic for adding new items to the map is implemented in the following piece of code: ``` shoppingList.put(item, amount) ``` For removing items from the list, the following code is used: ``` shoppingList.remove(item) ``` # Hazelcast Client In order to obtain an IMap, a Hazelcast client instance must be created first: ``` val hazelcastClient = HazelcastClient.newHazelcastClient(new ClientConfig()) ``` For obtaining the map, the next action is performed: ``` val shoppingList = hazelcastClient.getMap[String, Int]("shoppingList") ``` Finally, the items of the map can be extracted by means of their keys and corresponding values. # How can I test it? An API has been created for testing the functionality of the example: ApiActor. For simulating the behaviour of the child and reading the shopping list, you can access to the URL : ``` 0.0.0.0:5000/child/list ``` For simulating the addition of an element (done by the mother instance), a POST request must be performed. For example, if you want to add three oranges, you should send a POST request to: ``` 0.0.0.0:5000/mom/list/orange?n=3 ``` For simulating the removal of all the items of a product (all oranges, all apples...), a DELETE request must be performed to : ``` 0.0.0.0:5000/mom/list/product_name ``` where product_name is substituted by the name of the product (apple, orange...)

近期下载者

相关文件


收藏者