blob: 9bc095e60928b81dbfdc16b189a99063885f0c17 [file] [log] [blame]
Yuta HIGUCHI533ec322014-09-30 13:29:52 -07001package org.onlab.onos.store.cluster.messaging;
2
3import static org.onlab.onos.store.cluster.messaging.MessageSubject.AE_REPLY;
4
5import java.util.Map;
6import java.util.Set;
7
8import org.onlab.onos.cluster.NodeId;
9import org.onlab.onos.store.device.impl.VersionedValue;
10
11import com.google.common.collect.ImmutableMap;
12import com.google.common.collect.ImmutableSet;
13
Yuta HIGUCHIeeb75a02014-09-30 15:58:08 -070014/**
15 * Anti-Entropy reply message.
16 * <p>
17 * Message to send in reply to advertisement or another reply.
18 * Suggest to the sender about the more up-to-date data this node has,
19 * and request for more recent data that the receiver has.
20 */
Yuta HIGUCHId76830b2014-09-30 19:08:40 -070021public class AntiEntropyReply<ID, V extends VersionedValue<?>> extends ClusterMessage {
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070022
23 private final NodeId sender;
Yuta HIGUCHId76830b2014-09-30 19:08:40 -070024 private final ImmutableMap<ID, V> suggestion;
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070025 private final ImmutableSet<ID> request;
26
27 /**
28 * Creates a reply to anti-entropy message.
29 *
30 * @param sender sender of this message
31 * @param suggestion collection of more recent values, sender had
32 * @param request Collection of identifiers
33 */
34 public AntiEntropyReply(NodeId sender,
Yuta HIGUCHId76830b2014-09-30 19:08:40 -070035 Map<ID, V> suggestion,
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070036 Set<ID> request) {
37 super(AE_REPLY);
38 this.sender = sender;
39 this.suggestion = ImmutableMap.copyOf(suggestion);
40 this.request = ImmutableSet.copyOf(request);
41 }
42
43 public NodeId sender() {
44 return sender;
45 }
46
Yuta HIGUCHId76830b2014-09-30 19:08:40 -070047 /**
48 * Returns collection of values, which the recipient of this reply is likely
49 * to be missing or has outdated version.
50 *
51 * @return
52 */
53 public ImmutableMap<ID, V> suggestion() {
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070054 return suggestion;
55 }
56
Yuta HIGUCHId76830b2014-09-30 19:08:40 -070057 /**
58 * Returns collection of identifier to request.
59 *
60 * @return collection of identifier to request
61 */
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070062 public ImmutableSet<ID> request() {
63 return request;
64 }
65
Yuta HIGUCHId76830b2014-09-30 19:08:40 -070066 /**
67 * Checks if reply contains any suggestion or request.
68 *
69 * @return true if nothing is suggested and requested
70 */
71 public boolean isEmpty() {
72 return suggestion.isEmpty() && request.isEmpty();
73 }
74
Yuta HIGUCHI533ec322014-09-30 13:29:52 -070075 // Default constructor for serializer
76 protected AntiEntropyReply() {
77 super(AE_REPLY);
78 this.sender = null;
79 this.suggestion = null;
80 this.request = null;
81 }
82}