blob: 2ad85f6b1f4992851417b8c7b8251bac39d8def1 [file] [log] [blame]
Jonathan Hartaaa56572015-01-28 21:56:35 -08001/*
Thomas Vachuskab6d31672018-07-27 17:03:46 -07002 * Copyright 2018-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 */
Thomas Vachuskab6d31672018-07-27 17:03:46 -070016package org.onosproject.store.atomix.primitives.impl;
Jonathan Hartaaa56572015-01-28 21:56:35 -080017
Jordan Halterman00e92da2018-05-22 23:05:52 -070018import java.util.Map;
19
Jonathan Hart34f1e382015-02-24 16:52:23 -080020import com.google.common.base.MoreObjects;
Madan Jampani3d76c942015-06-29 23:37:10 -070021import com.google.common.collect.ImmutableMap;
Jonathan Hartaaa56572015-01-28 21:56:35 -080022import org.onosproject.cluster.NodeId;
Jonathan Hartaaa56572015-01-28 21:56:35 -080023
Jonathan Hartaaa56572015-01-28 21:56:35 -080024import static com.google.common.base.Preconditions.checkNotNull;
25
26/**
27 * Anti-entropy advertisement message for eventually consistent map.
28 */
29public class AntiEntropyAdvertisement<K> {
30
31 private final NodeId sender;
Madan Jampani3d76c942015-06-29 23:37:10 -070032 private final Map<K, MapValue.Digest> digest;
Jonathan Hartaaa56572015-01-28 21:56:35 -080033
34 /**
35 * Creates a new anti entropy advertisement message.
36 *
37 * @param sender the sender's node ID
Madan Jampani3d76c942015-06-29 23:37:10 -070038 * @param digest for map entries
Jonathan Hartaaa56572015-01-28 21:56:35 -080039 */
40 public AntiEntropyAdvertisement(NodeId sender,
Madan Jampani3d76c942015-06-29 23:37:10 -070041 Map<K, MapValue.Digest> digest) {
Jonathan Hartaaa56572015-01-28 21:56:35 -080042 this.sender = checkNotNull(sender);
Madan Jampani3d76c942015-06-29 23:37:10 -070043 this.digest = ImmutableMap.copyOf(checkNotNull(digest));
Jonathan Hartaaa56572015-01-28 21:56:35 -080044 }
45
46 /**
47 * Returns the sender's node ID.
48 *
49 * @return the sender's node ID
50 */
51 public NodeId sender() {
52 return sender;
53 }
54
55 /**
Madan Jampani3d76c942015-06-29 23:37:10 -070056 * Returns the digest for map entries.
Jonathan Hartaaa56572015-01-28 21:56:35 -080057 *
Madan Jampani3d76c942015-06-29 23:37:10 -070058 * @return mapping from key to associated digest
Jonathan Hartaaa56572015-01-28 21:56:35 -080059 */
Madan Jampani3d76c942015-06-29 23:37:10 -070060 public Map<K, MapValue.Digest> digest() {
61 return digest;
Jonathan Hartaaa56572015-01-28 21:56:35 -080062 }
Jonathan Hart34f1e382015-02-24 16:52:23 -080063
64 @Override
65 public String toString() {
66 return MoreObjects.toStringHelper(getClass())
Madan Jampani3d76c942015-06-29 23:37:10 -070067 .add("sender", sender)
68 .add("totalEntries", digest.size())
Jonathan Hart34f1e382015-02-24 16:52:23 -080069 .toString();
70 }
Jonathan Hartaaa56572015-01-28 21:56:35 -080071}