2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.remote.rpc.registry.gossip;
10 import akka.actor.Address;
11 import com.google.common.base.Preconditions;
13 import java.io.Serializable;
14 import java.util.Collections;
15 import java.util.HashMap;
16 import java.util.HashSet;
20 import static org.opendaylight.controller.remote.rpc.registry.gossip.Messages.BucketStoreMessages.ContainsBucketVersions;
21 import static org.opendaylight.controller.remote.rpc.registry.gossip.Messages.BucketStoreMessages.ContainsBuckets;
25 * These messages are used by {@link org.opendaylight.controller.remote.rpc.registry.gossip.BucketStore} and
26 * {@link org.opendaylight.controller.remote.rpc.registry.gossip.Gossiper} actors.
28 public class Messages {
30 public static class BucketStoreMessages{
32 public static class GetLocalBucket implements Serializable {
33 private static final long serialVersionUID = 1L;
36 public static class ContainsBucket implements Serializable {
37 private static final long serialVersionUID = 1L;
38 final private Bucket bucket;
40 public ContainsBucket(Bucket bucket){
41 Preconditions.checkArgument(bucket != null, "bucket can not be null");
45 public Bucket getBucket(){
51 public static class UpdateBucket extends ContainsBucket implements Serializable {
52 private static final long serialVersionUID = 1L;
53 public UpdateBucket(Bucket bucket){
58 public static class GetLocalBucketReply extends ContainsBucket implements Serializable {
59 private static final long serialVersionUID = 1L;
60 public GetLocalBucketReply(Bucket bucket){
65 public static class GetAllBuckets implements Serializable {
66 private static final long serialVersionUID = 1L;
69 public static class GetBucketsByMembers implements Serializable{
70 private static final long serialVersionUID = 1L;
71 private Set<Address> members;
73 public GetBucketsByMembers(Set<Address> members){
74 Preconditions.checkArgument(members != null, "members can not be null");
75 this.members = members;
78 public Set<Address> getMembers() {
79 return new HashSet<>(members);
83 public static class ContainsBuckets implements Serializable{
84 private static final long serialVersionUID = 1L;
85 private Map<Address, Bucket> buckets;
87 public ContainsBuckets(Map<Address, Bucket> buckets){
88 Preconditions.checkArgument(buckets != null, "buckets can not be null");
89 this.buckets = buckets;
92 public Map<Address, Bucket> getBuckets() {
93 Map<Address, Bucket> copy = new HashMap<>(buckets.size());
95 for (Map.Entry<Address, Bucket> entry : buckets.entrySet()){
97 if ( (entry.getKey() == null) || (entry.getValue() == null) )
99 copy.put(entry.getKey(), entry.getValue());
101 return new HashMap<>(copy);
105 public static class GetAllBucketsReply extends ContainsBuckets implements Serializable{
106 private static final long serialVersionUID = 1L;
107 public GetAllBucketsReply(Map<Address, Bucket> buckets) {
112 public static class GetBucketsByMembersReply extends ContainsBuckets implements Serializable{
113 private static final long serialVersionUID = 1L;
114 public GetBucketsByMembersReply(Map<Address, Bucket> buckets) {
119 public static class GetBucketVersions implements Serializable {
120 private static final long serialVersionUID = 1L;
123 public static class ContainsBucketVersions implements Serializable{
124 private static final long serialVersionUID = 1L;
125 Map<Address, Long> versions;
127 public ContainsBucketVersions(Map<Address, Long> versions) {
128 Preconditions.checkArgument(versions != null, "versions can not be null or empty");
130 this.versions = versions;
133 public Map<Address, Long> getVersions() {
134 return Collections.unmodifiableMap(versions);
139 public static class GetBucketVersionsReply extends ContainsBucketVersions implements Serializable{
140 private static final long serialVersionUID = 1L;
141 public GetBucketVersionsReply(Map<Address, Long> versions) {
146 public static class UpdateRemoteBuckets extends ContainsBuckets implements Serializable{
147 private static final long serialVersionUID = 1L;
148 public UpdateRemoteBuckets(Map<Address, Bucket> buckets) {
154 public static class GossiperMessages{
155 public static class Tick implements Serializable {
156 private static final long serialVersionUID = 1L;
159 public static final class GossipTick extends Tick {
160 private static final long serialVersionUID = 1L;
163 public static final class GossipStatus extends ContainsBucketVersions implements Serializable{
164 private static final long serialVersionUID = 1L;
165 private Address from;
167 public GossipStatus(Address from, Map<Address, Long> versions) {
172 public Address from() {
177 public static final class GossipEnvelope extends ContainsBuckets implements Serializable {
178 private static final long serialVersionUID = 1L;
179 private final Address from;
180 private final Address to;
182 public GossipEnvelope(Address from, Address to, Map<Address, Bucket> buckets) {
184 Preconditions.checkArgument(to != null, "Recipient of message must not be null");
189 public Address from() {
193 public Address to() {