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{}
34 public static class ContainsBucket implements Serializable {
35 final private Bucket bucket;
37 public ContainsBucket(Bucket bucket){
38 Preconditions.checkArgument(bucket != null, "bucket can not be null");
42 public Bucket getBucket(){
48 public static class UpdateBucket extends ContainsBucket implements Serializable {
49 public UpdateBucket(Bucket bucket){
54 public static class GetLocalBucketReply extends ContainsBucket implements Serializable {
55 public GetLocalBucketReply(Bucket bucket){
60 public static class GetAllBuckets implements Serializable{}
62 public static class GetBucketsByMembers implements Serializable{
63 private Set<Address> members;
65 public GetBucketsByMembers(Set<Address> members){
66 Preconditions.checkArgument(members != null, "members can not be null");
67 this.members = members;
70 public Set<Address> getMembers() {
71 return new HashSet<>(members);
75 public static class ContainsBuckets implements Serializable{
76 private Map<Address, Bucket> buckets;
78 public ContainsBuckets(Map<Address, Bucket> buckets){
79 Preconditions.checkArgument(buckets != null, "buckets can not be null");
80 this.buckets = buckets;
83 public Map<Address, Bucket> getBuckets() {
84 Map<Address, Bucket> copy = new HashMap<>(buckets.size());
86 for (Map.Entry<Address, Bucket> entry : buckets.entrySet()){
88 if ( (entry.getKey() == null) || (entry.getValue() == null) )
90 copy.put(entry.getKey(), entry.getValue());
92 return new HashMap<>(copy);
96 public static class GetAllBucketsReply extends ContainsBuckets implements Serializable{
97 public GetAllBucketsReply(Map<Address, Bucket> buckets) {
102 public static class GetBucketsByMembersReply extends ContainsBuckets implements Serializable{
103 public GetBucketsByMembersReply(Map<Address, Bucket> buckets) {
108 public static class GetBucketVersions implements Serializable{}
110 public static class ContainsBucketVersions implements Serializable{
111 Map<Address, Long> versions;
113 public ContainsBucketVersions(Map<Address, Long> versions) {
114 Preconditions.checkArgument(versions != null, "versions can not be null or empty");
116 this.versions = versions;
119 public Map<Address, Long> getVersions() {
120 return Collections.unmodifiableMap(versions);
125 public static class GetBucketVersionsReply extends ContainsBucketVersions implements Serializable{
126 public GetBucketVersionsReply(Map<Address, Long> versions) {
131 public static class UpdateRemoteBuckets extends ContainsBuckets implements Serializable{
132 public UpdateRemoteBuckets(Map<Address, Bucket> buckets) {
138 public static class GossiperMessages{
139 public static class Tick implements Serializable {}
141 public static final class GossipTick extends Tick {}
143 public static final class GossipStatus extends ContainsBucketVersions implements Serializable{
144 private Address from;
146 public GossipStatus(Address from, Map<Address, Long> versions) {
151 public Address from() {
156 public static final class GossipEnvelope extends ContainsBuckets implements Serializable {
157 private final Address from;
158 private final Address to;
160 public GossipEnvelope(Address from, Address to, Map<Address, Bucket> buckets) {
162 Preconditions.checkArgument(to != null, "Recipient of message must not be null");
167 public Address from() {
171 public Address to() {