/hazelcast-documentation/src/main/docbook/manual/content/dds/MultiMap.xml

https://bitbucket.org/gabral6_gmailcom/hazelcast · XML · 57 lines · 35 code · 7 blank · 15 comment · 0 complexity · 497d57f0f4718568307b3a2b5e542e46 MD5 · raw file

  1. <?xml version='1.0' encoding='UTF-8'?>
  2. <!--
  3. ~ Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
  4. ~
  5. ~ Licensed under the Apache License, Version 2.0 (the "License");
  6. ~ you may not use this file except in compliance with the License.
  7. ~ You may obtain a copy of the License at
  8. ~
  9. ~ http://www.apache.org/licenses/LICENSE-2.0
  10. ~
  11. ~ Unless required by applicable law or agreed to in writing, software
  12. ~ distributed under the License is distributed on an "AS IS" BASIS,
  13. ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. ~ See the License for the specific language governing permissions and
  15. ~ limitations under the License.
  16. -->
  17. <sect1 xml:id="MultiMap" version='5.0' xmlns='http://docbook.org/ns/docbook'
  18. xmlns:xi="http://www.w3.org/2001/XInclude"
  19. xmlns:xlink="http://www.w3.org/1999/xlink"
  20. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  21. xsi:schemaLocation="http://docbook.org/ns/docbook http://www.docbook.org/xml/5.0/xsd/docbook.xsd
  22. http://www.w3.org/1999/xlink http://www.w3.org/1999/xlink.xsd">
  23. <title>Distributed MultiMap</title>
  24. <para>
  25. <literal>MultiMap</literal>
  26. is a specialized map where you can associate a key with multiple values.
  27. Just like any other distributed data structure implementation in Hazelcast,
  28. <literal>MultiMap</literal>
  29. is distributed/partitioned and thread-safe.
  30. <programlisting language="java"><![CDATA[import com.hazelcast.core.MultiMap;
  31. import com.hazelcast.core.Hazelcast;
  32. import java.util.Collection;
  33. import com.hazelcast.config.Config;
  34. Config cfg = new Config();
  35. HazelcastInstance hz = Hazelcast.newHazelcastInstance(cfg);
  36. // a multimap to hold <customerId, Order> pairs
  37. MultiMap<String, Order> mmCustomerOrders = hz.getMultiMap("customerOrders");
  38. mmCustomerOrders.put("1", new Order ("iPhone", 340));
  39. mmCustomerOrders.put("1", new Order ("MacBook", 1200));
  40. mmCustomerOrders.put("1", new Order ("iPod", 79));
  41. // get orders of the customer with customerId 1.
  42. Collection<Order> colOrders = mmCustomerOrders.get ("1");
  43. for (Order order : colOrders) {
  44. // process order
  45. }
  46. // remove specific key/value pair
  47. boolean removed = mmCustomerOrders.remove("1", new Order ("iPhone", 340));
  48. ]]></programlisting>
  49. </para>
  50. </sect1>