Book Image

Getting Started with Hazelcast, Second Edition

By : Matthew Johns
Book Image

Getting Started with Hazelcast, Second Edition

By: Matthew Johns

Overview of this book

Table of Contents (19 chapters)
Getting Started with Hazelcast Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Many things at a time


We have previously seen that Hazelcast provides us with a generic key-value map. However, this capability is popularly used to create a key/list-of-values map. While there is nothing stopping us from defining these ourselves using the standard Java generics, we will have to manually handle the initialization of each key entry. Hazelcast has luckily gone out of its way to make our lives easier by handling this case for us by using the specialized MultiMap collection.

Let's have a look at the following example:

public class MultiMapExample {
  public static void main(String[] args) {
    HazelcastInstance hz = Hazelcast.newHazelcastInstance();

    Map<String, List<String>> manualCities =
      hz.getMap("manualCities");

    List<String> gbCities = new ArrayList<String>();
    manualCities.put("GB", gbCities);

    gbCities = manualCities.get("GB");
    gbCities.add("London");
    manualCities.put("GB", gbCities);

    gbCities = manualCities.get...