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;
12 import java.io.Serializable;
13 import java.util.Collections;
14 import java.util.HashMap;
15 import java.util.HashSet;
18 import org.opendaylight.controller.remote.rpc.registry.gossip.Messages.BucketStoreMessages.ContainsBucketVersions;
19 import org.opendaylight.controller.remote.rpc.registry.gossip.Messages.BucketStoreMessages.ContainsBuckets;
23 * These messages are used by {@link org.opendaylight.controller.remote.rpc.registry.gossip.BucketStore} and
24 * {@link org.opendaylight.controller.remote.rpc.registry.gossip.Gossiper} actors.
26 public class Messages {
28 public static class BucketStoreMessages{
30 public static class GetAllBuckets implements Serializable {
31 private static final long serialVersionUID = 1L;
34 public static class GetBucketsByMembers implements Serializable{
35 private static final long serialVersionUID = 1L;
36 private final Set<Address> members;
38 public GetBucketsByMembers(Set<Address> members){
39 Preconditions.checkArgument(members != null, "members can not be null");
40 this.members = members;
43 public Set<Address> getMembers() {
44 return new HashSet<>(members);
48 public static class ContainsBuckets implements Serializable{
49 private static final long serialVersionUID = 1L;
50 private final Map<Address, Bucket> buckets;
52 public ContainsBuckets(Map<Address, Bucket> buckets){
53 Preconditions.checkArgument(buckets != null, "buckets can not be null");
54 this.buckets = buckets;
57 public Map<Address, Bucket> getBuckets() {
58 Map<Address, Bucket> copy = new HashMap<>(buckets.size());
60 for (Map.Entry<Address, Bucket> entry : buckets.entrySet()){
62 if ( (entry.getKey() == null) || (entry.getValue() == null) ) {
65 copy.put(entry.getKey(), entry.getValue());
71 public static class GetAllBucketsReply extends ContainsBuckets implements Serializable{
72 private static final long serialVersionUID = 1L;
73 public GetAllBucketsReply(Map<Address, Bucket> buckets) {
78 public static class GetBucketsByMembersReply extends ContainsBuckets implements Serializable{
79 private static final long serialVersionUID = 1L;
80 public GetBucketsByMembersReply(Map<Address, Bucket> buckets) {
85 public static class GetBucketVersions implements Serializable {
86 private static final long serialVersionUID = 1L;
89 public static class ContainsBucketVersions implements Serializable{
90 private static final long serialVersionUID = 1L;
91 Map<Address, Long> versions;
93 public ContainsBucketVersions(Map<Address, Long> versions) {
94 Preconditions.checkArgument(versions != null, "versions can not be null or empty");
96 this.versions = versions;
99 public Map<Address, Long> getVersions() {
100 return Collections.unmodifiableMap(versions);
105 public static class GetBucketVersionsReply extends ContainsBucketVersions implements Serializable{
106 private static final long serialVersionUID = 1L;
107 public GetBucketVersionsReply(Map<Address, Long> versions) {
112 public static class UpdateRemoteBuckets extends ContainsBuckets implements Serializable{
113 private static final long serialVersionUID = 1L;
114 public UpdateRemoteBuckets(Map<Address, Bucket> buckets) {
120 public static class GossiperMessages{
121 public static class Tick implements Serializable {
122 private static final long serialVersionUID = 1L;
125 public static final class GossipTick extends Tick {
126 private static final long serialVersionUID = 1L;
129 public static final class GossipStatus extends ContainsBucketVersions implements Serializable{
130 private static final long serialVersionUID = 1L;
131 private final Address from;
133 public GossipStatus(Address from, Map<Address, Long> versions) {
138 public Address from() {
143 public static final class GossipEnvelope extends ContainsBuckets implements Serializable {
144 private static final long serialVersionUID = 1L;
145 private final Address from;
146 private final Address to;
148 public GossipEnvelope(Address from, Address to, Map<Address, Bucket> buckets) {
150 Preconditions.checkArgument(to != null, "Recipient of message must not be null");
155 public Address from() {
159 public Address to() {