PageRenderTime 9ms CodeModel.GetById 2ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/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
18<sect1 xml:id="MultiMap" version='5.0' xmlns='http://docbook.org/ns/docbook'
19       xmlns:xi="http://www.w3.org/2001/XInclude"
20       xmlns:xlink="http://www.w3.org/1999/xlink"
21       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22       xsi:schemaLocation="http://docbook.org/ns/docbook http://www.docbook.org/xml/5.0/xsd/docbook.xsd
23      http://www.w3.org/1999/xlink http://www.w3.org/1999/xlink.xsd">
24    <title>Distributed MultiMap</title>
25    <para>
26        <literal>MultiMap</literal>
27        is a specialized map where you can associate a key with multiple values.
28        Just like any other distributed data structure implementation in Hazelcast,
29        <literal>MultiMap</literal>
30        is distributed/partitioned and thread-safe.
31
32        <programlisting language="java"><![CDATA[import com.hazelcast.core.MultiMap;
33import com.hazelcast.core.Hazelcast;
34import java.util.Collection;
35import com.hazelcast.config.Config;
36
37Config cfg = new Config();
38HazelcastInstance hz = Hazelcast.newHazelcastInstance(cfg);
39
40// a multimap to hold <customerId, Order> pairs
41MultiMap<String, Order> mmCustomerOrders = hz.getMultiMap("customerOrders");
42mmCustomerOrders.put("1", new Order ("iPhone", 340));
43mmCustomerOrders.put("1", new Order ("MacBook", 1200));
44mmCustomerOrders.put("1", new Order ("iPod", 79));
45
46// get orders of the customer with customerId 1.
47Collection<Order> colOrders = mmCustomerOrders.get ("1");
48for (Order order : colOrders) {
49    // process order
50}
51
52// remove specific key/value pair
53boolean removed = mmCustomerOrders.remove("1", new Order ("iPhone", 340));
54]]></programlisting>
55
56    </para>
57</sect1>