Jonathan Hart | aaa5657 | 2015-01-28 21:56:35 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Jonathan Hart | aaa5657 | 2015-01-28 21:56:35 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Madan Jampani | f4c8850 | 2016-01-21 12:35:36 -0800 | [diff] [blame] | 16 | package org.onosproject.store.primitives.impl; |
Jonathan Hart | aaa5657 | 2015-01-28 21:56:35 -0800 | [diff] [blame] | 17 | |
Jonathan Hart | 34f1e38 | 2015-02-24 16:52:23 -0800 | [diff] [blame] | 18 | import com.google.common.base.MoreObjects; |
Madan Jampani | 3d76c94 | 2015-06-29 23:37:10 -0700 | [diff] [blame] | 19 | import com.google.common.collect.ImmutableMap; |
Madan Jampani | ee35d55 | 2016-04-26 16:07:40 -0700 | [diff] [blame] | 20 | |
Jonathan Hart | aaa5657 | 2015-01-28 21:56:35 -0800 | [diff] [blame] | 21 | import org.onosproject.cluster.NodeId; |
Jonathan Hart | aaa5657 | 2015-01-28 21:56:35 -0800 | [diff] [blame] | 22 | |
| 23 | import java.util.Map; |
Madan Jampani | 29f52a3 | 2016-04-18 15:20:52 -0700 | [diff] [blame] | 24 | |
Jonathan Hart | aaa5657 | 2015-01-28 21:56:35 -0800 | [diff] [blame] | 25 | import static com.google.common.base.Preconditions.checkNotNull; |
| 26 | |
| 27 | /** |
| 28 | * Anti-entropy advertisement message for eventually consistent map. |
| 29 | */ |
| 30 | public class AntiEntropyAdvertisement<K> { |
| 31 | |
| 32 | private final NodeId sender; |
Madan Jampani | 3d76c94 | 2015-06-29 23:37:10 -0700 | [diff] [blame] | 33 | private final Map<K, MapValue.Digest> digest; |
Jonathan Hart | aaa5657 | 2015-01-28 21:56:35 -0800 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Creates a new anti entropy advertisement message. |
| 37 | * |
| 38 | * @param sender the sender's node ID |
Madan Jampani | 3d76c94 | 2015-06-29 23:37:10 -0700 | [diff] [blame] | 39 | * @param digest for map entries |
Jonathan Hart | aaa5657 | 2015-01-28 21:56:35 -0800 | [diff] [blame] | 40 | */ |
| 41 | public AntiEntropyAdvertisement(NodeId sender, |
Madan Jampani | 3d76c94 | 2015-06-29 23:37:10 -0700 | [diff] [blame] | 42 | Map<K, MapValue.Digest> digest) { |
Jonathan Hart | aaa5657 | 2015-01-28 21:56:35 -0800 | [diff] [blame] | 43 | this.sender = checkNotNull(sender); |
Madan Jampani | 3d76c94 | 2015-06-29 23:37:10 -0700 | [diff] [blame] | 44 | this.digest = ImmutableMap.copyOf(checkNotNull(digest)); |
Jonathan Hart | aaa5657 | 2015-01-28 21:56:35 -0800 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Returns the sender's node ID. |
| 49 | * |
| 50 | * @return the sender's node ID |
| 51 | */ |
| 52 | public NodeId sender() { |
| 53 | return sender; |
| 54 | } |
| 55 | |
| 56 | /** |
Madan Jampani | 3d76c94 | 2015-06-29 23:37:10 -0700 | [diff] [blame] | 57 | * Returns the digest for map entries. |
Jonathan Hart | aaa5657 | 2015-01-28 21:56:35 -0800 | [diff] [blame] | 58 | * |
Madan Jampani | 3d76c94 | 2015-06-29 23:37:10 -0700 | [diff] [blame] | 59 | * @return mapping from key to associated digest |
Jonathan Hart | aaa5657 | 2015-01-28 21:56:35 -0800 | [diff] [blame] | 60 | */ |
Madan Jampani | 3d76c94 | 2015-06-29 23:37:10 -0700 | [diff] [blame] | 61 | public Map<K, MapValue.Digest> digest() { |
| 62 | return digest; |
Jonathan Hart | aaa5657 | 2015-01-28 21:56:35 -0800 | [diff] [blame] | 63 | } |
Jonathan Hart | 34f1e38 | 2015-02-24 16:52:23 -0800 | [diff] [blame] | 64 | |
| 65 | @Override |
| 66 | public String toString() { |
| 67 | return MoreObjects.toStringHelper(getClass()) |
Madan Jampani | 3d76c94 | 2015-06-29 23:37:10 -0700 | [diff] [blame] | 68 | .add("sender", sender) |
| 69 | .add("totalEntries", digest.size()) |
Jonathan Hart | 34f1e38 | 2015-02-24 16:52:23 -0800 | [diff] [blame] | 70 | .toString(); |
| 71 | } |
Jonathan Hart | aaa5657 | 2015-01-28 21:56:35 -0800 | [diff] [blame] | 72 | } |