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;
21 * These messages are used by {@link org.opendaylight.controller.remote.rpc.registry.gossip.BucketStore} and
22 * {@link org.opendaylight.controller.remote.rpc.registry.gossip.Gossiper} actors.
24 public class Messages {
26 public static class BucketStoreMessages{
28 public static class GetLocalBucket implements Serializable{}
30 public static class ContainsBucket implements Serializable {
31 final private Bucket bucket;
33 public ContainsBucket(Bucket bucket){
34 Preconditions.checkArgument(bucket != null, "bucket can not be null");
38 public Bucket getBucket(){
44 public static class UpdateBucket extends ContainsBucket implements Serializable {
45 public UpdateBucket(Bucket bucket){
50 public static class GetLocalBucketReply extends ContainsBucket implements Serializable {
51 public GetLocalBucketReply(Bucket bucket){
56 public static class GetAllBuckets implements Serializable{}
58 public static class GetBucketsByMembers implements Serializable{
59 private Set<Address> members;
61 public GetBucketsByMembers(Set<Address> members){
62 Preconditions.checkArgument(members != null, "members can not be null");
63 this.members = members;
66 public Set<Address> getMembers() {
67 return new HashSet<>(members);
71 public static class ContainsBuckets implements Serializable{
72 private Map<Address, Bucket> buckets;
74 public ContainsBuckets(Map<Address, Bucket> buckets){
75 Preconditions.checkArgument(buckets != null, "buckets can not be null");
76 this.buckets = buckets;
79 public Map<Address, Bucket> getBuckets() {
80 Map<Address, Bucket> copy = new HashMap<>(buckets.size());
82 for (Map.Entry<Address, Bucket> entry : buckets.entrySet()){
84 if ( (entry.getKey() == null) || (entry.getValue() == null) )
86 copy.put(entry.getKey(), entry.getValue());
88 return new HashMap<>(copy);
92 public static class GetAllBucketsReply extends ContainsBuckets implements Serializable{
93 public GetAllBucketsReply(Map<Address, Bucket> buckets) {
98 public static class GetBucketsByMembersReply extends ContainsBuckets implements Serializable{
99 public GetBucketsByMembersReply(Map<Address, Bucket> buckets) {
104 public static class GetBucketVersions implements Serializable{}
106 public static class ContainsBucketVersions implements Serializable{
107 Map<Address, Long> versions;
109 public ContainsBucketVersions(Map<Address, Long> versions) {
110 Preconditions.checkArgument(versions != null, "versions can not be null");
111 this.versions = versions;
114 public Map<Address, Long> getVersions() {
115 return Collections.unmodifiableMap(versions);
120 public static class GetBucketVersionsReply extends ContainsBucketVersions implements Serializable{
121 public GetBucketVersionsReply(Map<Address, Long> versions) {
126 public static class UpdateRemoteBuckets extends ContainsBuckets implements Serializable{
127 public UpdateRemoteBuckets(Map<Address, Bucket> buckets) {
133 public static class GossiperMessages{
134 public static class Tick implements Serializable {}
136 public static final class GossipTick extends Tick {}
138 public static final class GossipStatus extends BucketStoreMessages.ContainsBucketVersions implements Serializable{
139 private Address from;
141 public GossipStatus(Address from, Map<Address, Long> versions) {
146 public Address from() {
151 public static final class GossipEnvelope extends BucketStoreMessages.ContainsBuckets implements Serializable {
152 private final Address from;
153 private final Address to;
155 public GossipEnvelope(Address from, Address to, Map<Address, Bucket> buckets) {
161 public Address from() {
165 public Address to() {