blob: 033a1de75cc14e007fc604c9603ae1ce1bfec3e7 [file] [log] [blame]
Yuta HIGUCHIc057c632014-10-06 18:38:14 -07001package org.onlab.onos.store.common.impl;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -07002
Yuta HIGUCHI533ec322014-09-30 13:29:52 -07003import java.util.Map;
4import java.util.Set;
5
6import org.onlab.onos.cluster.NodeId;
7import org.onlab.onos.store.device.impl.VersionedValue;
8
9import com.google.common.collect.ImmutableMap;
10import com.google.common.collect.ImmutableSet;
11
Yuta HIGUCHIeeb75a02014-09-30 15:58:08 -070012/**
13 * Anti-Entropy reply message.
14 * <p>
15 * Message to send in reply to advertisement or another reply.
16 * Suggest to the sender about the more up-to-date data this node has,
17 * and request for more recent data that the receiver has.
18 */
Madan Jampani890bc352014-10-01 22:35:29 -070019public class AntiEntropyReply<ID, V extends VersionedValue<?>> {
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070020
21 private final NodeId sender;
Yuta HIGUCHId76830b2014-09-30 19:08:40 -070022 private final ImmutableMap<ID, V> suggestion;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070023 private final ImmutableSet<ID> request;
24
25 /**
26 * Creates a reply to anti-entropy message.
27 *
28 * @param sender sender of this message
29 * @param suggestion collection of more recent values, sender had
30 * @param request Collection of identifiers
31 */
32 public AntiEntropyReply(NodeId sender,
Yuta HIGUCHId76830b2014-09-30 19:08:40 -070033 Map<ID, V> suggestion,
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070034 Set<ID> request) {
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070035 this.sender = sender;
36 this.suggestion = ImmutableMap.copyOf(suggestion);
37 this.request = ImmutableSet.copyOf(request);
38 }
39
40 public NodeId sender() {
41 return sender;
42 }
43
Yuta HIGUCHId76830b2014-09-30 19:08:40 -070044 /**
45 * Returns collection of values, which the recipient of this reply is likely
46 * to be missing or has outdated version.
47 *
48 * @return
49 */
50 public ImmutableMap<ID, V> suggestion() {
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070051 return suggestion;
52 }
53
Yuta HIGUCHId76830b2014-09-30 19:08:40 -070054 /**
55 * Returns collection of identifier to request.
56 *
57 * @return collection of identifier to request
58 */
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070059 public ImmutableSet<ID> request() {
60 return request;
61 }
62
Yuta HIGUCHId76830b2014-09-30 19:08:40 -070063 /**
64 * Checks if reply contains any suggestion or request.
65 *
66 * @return true if nothing is suggested and requested
67 */
68 public boolean isEmpty() {
69 return suggestion.isEmpty() && request.isEmpty();
70 }
71
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070072 // Default constructor for serializer
73 protected AntiEntropyReply() {
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070074 this.sender = null;
75 this.suggestion = null;
76 this.request = null;
77 }
78}