Coder Social home page Coder Social logo

sweetcard / hazelcast-scala-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dvallejo/hazelcast-scala-example

0.0 2.0 0.0 168 KB

An example of an In-Memory Data Grid using Hazelcast, Spray and Akka

License: Other

Scala 56.42% HTML 43.58%

hazelcast-scala-example's Introduction

hazelcast-scala-example

Build Status

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...)

hazelcast-scala-example's People

Contributors

dvallejo avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.