blob: 3914ffd2fcb0455db0d27f28105e49c50d6f8cb1 [file] [log] [blame]
Jonathan Hartaaa56572015-01-28 21:56:35 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
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;
Jonathan Hartaaa56572015-01-28 21:56:35 -080020import org.onosproject.cluster.NodeId;
Jonathan Hartaaa56572015-01-28 21:56:35 -080021
22import java.util.Map;
Madan Jampani29f52a32016-04-18 15:20:52 -070023
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
Madan Jampani29f52a32016-04-18 15:20:52 -070031 private final long creationTime;
Jonathan Hartaaa56572015-01-28 21:56:35 -080032 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) {
Madan Jampani29f52a32016-04-18 15:20:52 -070043 this.creationTime = System.currentTimeMillis();
Jonathan Hartaaa56572015-01-28 21:56:35 -080044 this.sender = checkNotNull(sender);
Madan Jampani3d76c942015-06-29 23:37:10 -070045 this.digest = ImmutableMap.copyOf(checkNotNull(digest));
Jonathan Hartaaa56572015-01-28 21:56:35 -080046 }
47
48 /**
Madan Jampani29f52a32016-04-18 15:20:52 -070049 * Returns the ad creation time.
50 *
51 * @return ad creation time
52 */
53 public long creationTime() {
54 return creationTime;
55 }
56
57 /**
Jonathan Hartaaa56572015-01-28 21:56:35 -080058 * Returns the sender's node ID.
59 *
60 * @return the sender's node ID
61 */
62 public NodeId sender() {
63 return sender;
64 }
65
66 /**
Madan Jampani3d76c942015-06-29 23:37:10 -070067 * Returns the digest for map entries.
Jonathan Hartaaa56572015-01-28 21:56:35 -080068 *
Madan Jampani3d76c942015-06-29 23:37:10 -070069 * @return mapping from key to associated digest
Jonathan Hartaaa56572015-01-28 21:56:35 -080070 */
Madan Jampani3d76c942015-06-29 23:37:10 -070071 public Map<K, MapValue.Digest> digest() {
72 return digest;
Jonathan Hartaaa56572015-01-28 21:56:35 -080073 }
Jonathan Hart34f1e382015-02-24 16:52:23 -080074
75 @Override
76 public String toString() {
77 return MoreObjects.toStringHelper(getClass())
Madan Jampani3d76c942015-06-29 23:37:10 -070078 .add("sender", sender)
79 .add("totalEntries", digest.size())
Jonathan Hart34f1e382015-02-24 16:52:23 -080080 .toString();
81 }
Jonathan Hartaaa56572015-01-28 21:56:35 -080082}