Yuta HIGUCHI | c057c63 | 2014-10-06 18:38:14 -0700 | [diff] [blame] | 1 | package org.onlab.onos.store.common.impl; |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 2 | |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 3 | import java.util.Map; |
| 4 | import java.util.Set; |
| 5 | |
| 6 | import org.onlab.onos.cluster.NodeId; |
| 7 | import org.onlab.onos.store.device.impl.VersionedValue; |
| 8 | |
| 9 | import com.google.common.collect.ImmutableMap; |
| 10 | import com.google.common.collect.ImmutableSet; |
| 11 | |
Yuta HIGUCHI | eeb75a0 | 2014-09-30 15:58:08 -0700 | [diff] [blame] | 12 | /** |
| 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 Jampani | 890bc35 | 2014-10-01 22:35:29 -0700 | [diff] [blame] | 19 | public class AntiEntropyReply<ID, V extends VersionedValue<?>> { |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 20 | |
| 21 | private final NodeId sender; |
Yuta HIGUCHI | d76830b | 2014-09-30 19:08:40 -0700 | [diff] [blame] | 22 | private final ImmutableMap<ID, V> suggestion; |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 23 | 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 HIGUCHI | d76830b | 2014-09-30 19:08:40 -0700 | [diff] [blame] | 33 | Map<ID, V> suggestion, |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 34 | Set<ID> request) { |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 35 | 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 HIGUCHI | d76830b | 2014-09-30 19:08:40 -0700 | [diff] [blame] | 44 | /** |
| 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 HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 51 | return suggestion; |
| 52 | } |
| 53 | |
Yuta HIGUCHI | d76830b | 2014-09-30 19:08:40 -0700 | [diff] [blame] | 54 | /** |
| 55 | * Returns collection of identifier to request. |
| 56 | * |
| 57 | * @return collection of identifier to request |
| 58 | */ |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 59 | public ImmutableSet<ID> request() { |
| 60 | return request; |
| 61 | } |
| 62 | |
Yuta HIGUCHI | d76830b | 2014-09-30 19:08:40 -0700 | [diff] [blame] | 63 | /** |
| 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 HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 72 | // Default constructor for serializer |
| 73 | protected AntiEntropyReply() { |
Yuta HIGUCHI | 533ec32 | 2014-09-30 13:29:52 -0700 | [diff] [blame] | 74 | this.sender = null; |
| 75 | this.suggestion = null; |
| 76 | this.request = null; |
| 77 | } |
| 78 | } |