blob: 373273c9910bbf1ef0be372488bad3d04c27ffbc [file] [log] [blame]
Jonathan Hartaaa56572015-01-28 21:56:35 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Jonathan Hartaaa56572015-01-28 21:56:35 -08003 *
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 Jampanif4c88502016-01-21 12:35:36 -080016package org.onosproject.store.primitives.impl;
Jonathan Hartaaa56572015-01-28 21:56:35 -080017
Jonathan Hart34f1e382015-02-24 16:52:23 -080018import com.google.common.base.MoreObjects;
Madan Jampani3d76c942015-06-29 23:37:10 -070019import com.google.common.collect.ImmutableMap;
Madan Jampaniee35d552016-04-26 16:07:40 -070020
Jonathan Hartaaa56572015-01-28 21:56:35 -080021import org.onosproject.cluster.NodeId;
Jonathan Hartaaa56572015-01-28 21:56:35 -080022
23import java.util.Map;
Madan Jampani29f52a32016-04-18 15:20:52 -070024
Jonathan Hartaaa56572015-01-28 21:56:35 -080025import static com.google.common.base.Preconditions.checkNotNull;
26
27/**
28 * Anti-entropy advertisement message for eventually consistent map.
29 */
30public class AntiEntropyAdvertisement<K> {
31
32 private final NodeId sender;
Madan Jampani3d76c942015-06-29 23:37:10 -070033 private final Map<K, MapValue.Digest> digest;
Jonathan Hartaaa56572015-01-28 21:56:35 -080034
35 /**
36 * Creates a new anti entropy advertisement message.
37 *
38 * @param sender the sender's node ID
Madan Jampani3d76c942015-06-29 23:37:10 -070039 * @param digest for map entries
Jonathan Hartaaa56572015-01-28 21:56:35 -080040 */
41 public AntiEntropyAdvertisement(NodeId sender,
Madan Jampani3d76c942015-06-29 23:37:10 -070042 Map<K, MapValue.Digest> digest) {
Jonathan Hartaaa56572015-01-28 21:56:35 -080043 this.sender = checkNotNull(sender);
Madan Jampani3d76c942015-06-29 23:37:10 -070044 this.digest = ImmutableMap.copyOf(checkNotNull(digest));
Jonathan Hartaaa56572015-01-28 21:56:35 -080045 }
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 Jampani3d76c942015-06-29 23:37:10 -070057 * Returns the digest for map entries.
Jonathan Hartaaa56572015-01-28 21:56:35 -080058 *
Madan Jampani3d76c942015-06-29 23:37:10 -070059 * @return mapping from key to associated digest
Jonathan Hartaaa56572015-01-28 21:56:35 -080060 */
Madan Jampani3d76c942015-06-29 23:37:10 -070061 public Map<K, MapValue.Digest> digest() {
62 return digest;
Jonathan Hartaaa56572015-01-28 21:56:35 -080063 }
Jonathan Hart34f1e382015-02-24 16:52:23 -080064
65 @Override
66 public String toString() {
67 return MoreObjects.toStringHelper(getClass())
Madan Jampani3d76c942015-06-29 23:37:10 -070068 .add("sender", sender)
69 .add("totalEntries", digest.size())
Jonathan Hart34f1e382015-02-24 16:52:23 -080070 .toString();
71 }
Jonathan Hartaaa56572015-01-28 21:56:35 -080072}