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 = -4940160367495308286L;
51 private final Map<Address, Bucket> buckets;
53 public ContainsBuckets(Map<Address, Bucket> buckets){
54 Preconditions.checkArgument(buckets != null, "buckets can not be null");
55 this.buckets = buckets;
58 public Map<Address, Bucket> getBuckets() {
59 Map<Address, Bucket> copy = new HashMap<>(buckets.size());
61 for (Map.Entry<Address, Bucket> entry : buckets.entrySet()){
63 if ( (entry.getKey() == null) || (entry.getValue() == null) ) {
66 copy.put(entry.getKey(), entry.getValue());
72 public static class GetAllBucketsReply extends ContainsBuckets implements Serializable{
73 private static final long serialVersionUID = 1L;
74 public GetAllBucketsReply(Map<Address, Bucket> buckets) {
79 public static class GetBucketsByMembersReply extends ContainsBuckets implements Serializable{
80 private static final long serialVersionUID = 1L;
81 public GetBucketsByMembersReply(Map<Address, Bucket> buckets) {
86 public static class GetBucketVersions implements Serializable {
87 private static final long serialVersionUID = 1L;
90 public static class ContainsBucketVersions implements Serializable{
91 private static final long serialVersionUID = -8172148925383801613L;
93 Map<Address, Long> versions;
95 public ContainsBucketVersions(Map<Address, Long> versions) {
96 Preconditions.checkArgument(versions != null, "versions can not be null or empty");
98 this.versions = versions;
101 public Map<Address, Long> getVersions() {
102 return Collections.unmodifiableMap(versions);
107 public static class GetBucketVersionsReply extends ContainsBucketVersions implements Serializable{
108 private static final long serialVersionUID = 1L;
109 public GetBucketVersionsReply(Map<Address, Long> versions) {
114 public static class UpdateRemoteBuckets extends ContainsBuckets implements Serializable{
115 private static final long serialVersionUID = 1L;
116 public UpdateRemoteBuckets(Map<Address, Bucket> buckets) {
122 public static class GossiperMessages{
123 public static class Tick implements Serializable {
124 private static final long serialVersionUID = -4770935099506366773L;
127 public static final class GossipTick extends Tick {
128 private static final long serialVersionUID = 5803354404380026143L;
131 public static final class GossipStatus extends ContainsBucketVersions implements Serializable{
132 private static final long serialVersionUID = -593037395143883265L;
134 private final Address from;
136 public GossipStatus(Address from, Map<Address, Long> versions) {
141 public Address from() {
146 public static final class GossipEnvelope extends ContainsBuckets implements Serializable {
147 private static final long serialVersionUID = 8346634072582438818L;
149 private final Address from;
150 private final Address to;
152 public GossipEnvelope(Address from, Address to, Map<Address, Bucket> buckets) {
154 Preconditions.checkArgument(to != null, "Recipient of message must not be null");
159 public Address from() {
163 public Address to() {