Jonathan Hart | aaa5657 | 2015-01-28 21:56:35 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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 | */ |
Jonathan Hart | 77bdd26 | 2015-02-03 09:07:48 -0800 | [diff] [blame] | 16 | package org.onosproject.store.ecmap; |
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; |
Jonathan Hart | aaa5657 | 2015-01-28 21:56:35 -0800 | [diff] [blame] | 19 | import org.onosproject.cluster.NodeId; |
| 20 | import org.onosproject.store.Timestamp; |
| 21 | |
| 22 | import java.util.Map; |
| 23 | |
| 24 | import static com.google.common.base.Preconditions.checkNotNull; |
| 25 | |
| 26 | /** |
| 27 | * Anti-entropy advertisement message for eventually consistent map. |
| 28 | */ |
| 29 | public class AntiEntropyAdvertisement<K> { |
| 30 | |
| 31 | private final NodeId sender; |
| 32 | private final Map<K, Timestamp> timestamps; |
| 33 | private final Map<K, Timestamp> tombstones; |
| 34 | |
| 35 | /** |
| 36 | * Creates a new anti entropy advertisement message. |
| 37 | * |
| 38 | * @param sender the sender's node ID |
| 39 | * @param timestamps map of item key to timestamp for current items |
| 40 | * @param tombstones map of item key to timestamp for removed items |
| 41 | */ |
| 42 | public AntiEntropyAdvertisement(NodeId sender, |
| 43 | Map<K, Timestamp> timestamps, |
| 44 | Map<K, Timestamp> tombstones) { |
| 45 | this.sender = checkNotNull(sender); |
| 46 | this.timestamps = checkNotNull(timestamps); |
| 47 | this.tombstones = checkNotNull(tombstones); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Returns the sender's node ID. |
| 52 | * |
| 53 | * @return the sender's node ID |
| 54 | */ |
| 55 | public NodeId sender() { |
| 56 | return sender; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Returns the map of current item timestamps. |
| 61 | * |
| 62 | * @return current item timestamps |
| 63 | */ |
| 64 | public Map<K, Timestamp> timestamps() { |
| 65 | return timestamps; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Returns the map of removed item timestamps. |
| 70 | * |
| 71 | * @return removed item timestamps |
| 72 | */ |
| 73 | public Map<K, Timestamp> tombstones() { |
| 74 | return tombstones; |
| 75 | } |
| 76 | |
| 77 | // For serializer |
| 78 | @SuppressWarnings("unused") |
| 79 | private AntiEntropyAdvertisement() { |
| 80 | this.sender = null; |
| 81 | this.timestamps = null; |
| 82 | this.tombstones = null; |
| 83 | } |
Jonathan Hart | 34f1e38 | 2015-02-24 16:52:23 -0800 | [diff] [blame] | 84 | |
| 85 | @Override |
| 86 | public String toString() { |
| 87 | return MoreObjects.toStringHelper(getClass()) |
| 88 | .add("timestampsSize", timestamps.size()) |
| 89 | .add("tombstonesSize", tombstones.size()) |
| 90 | .toString(); |
| 91 | } |
Jonathan Hart | aaa5657 | 2015-01-28 21:56:35 -0800 | [diff] [blame] | 92 | } |