Merge "Fix test case mis-spelling."
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / registry / gossip / Messages.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.remote.rpc.registry.gossip;
9
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;
16 import java.util.Map;
17 import java.util.Set;
18 import org.opendaylight.controller.remote.rpc.registry.gossip.Messages.BucketStoreMessages.ContainsBucketVersions;
19 import org.opendaylight.controller.remote.rpc.registry.gossip.Messages.BucketStoreMessages.ContainsBuckets;
20
21
22 /**
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.
25  */
26 public class Messages {
27
28     public static class BucketStoreMessages{
29
30         public static class GetAllBuckets implements Serializable {
31             private static final long serialVersionUID = 1L;
32         }
33
34         public static class GetBucketsByMembers implements Serializable{
35             private static final long serialVersionUID = 1L;
36             private final Set<Address> members;
37
38             public GetBucketsByMembers(Set<Address> members){
39                 Preconditions.checkArgument(members != null, "members can not be null");
40                 this.members = members;
41             }
42
43             public Set<Address> getMembers() {
44                 return new HashSet<>(members);
45             }
46         }
47
48         public static class ContainsBuckets implements Serializable{
49             private static final long serialVersionUID = 1L;
50             private final Map<Address, Bucket> buckets;
51
52             public ContainsBuckets(Map<Address, Bucket> buckets){
53                 Preconditions.checkArgument(buckets != null, "buckets can not be null");
54                 this.buckets = buckets;
55             }
56
57             public Map<Address, Bucket> getBuckets() {
58                 Map<Address, Bucket> copy = new HashMap<>(buckets.size());
59
60                 for (Map.Entry<Address, Bucket> entry : buckets.entrySet()){
61                     //ignore null entries
62                     if ( (entry.getKey() == null) || (entry.getValue() == null) ) {
63                         continue;
64                     }
65                     copy.put(entry.getKey(), entry.getValue());
66                 }
67                 return copy;
68             }
69         }
70
71         public static class GetAllBucketsReply extends ContainsBuckets implements Serializable{
72             private static final long serialVersionUID = 1L;
73             public GetAllBucketsReply(Map<Address, Bucket> buckets) {
74                 super(buckets);
75             }
76         }
77
78         public static class GetBucketsByMembersReply extends ContainsBuckets implements Serializable{
79             private static final long serialVersionUID = 1L;
80             public GetBucketsByMembersReply(Map<Address, Bucket> buckets) {
81                 super(buckets);
82             }
83         }
84
85         public static class GetBucketVersions implements Serializable {
86             private static final long serialVersionUID = 1L;
87         }
88
89         public static class ContainsBucketVersions implements Serializable{
90             private static final long serialVersionUID = 1L;
91             Map<Address, Long> versions;
92
93             public ContainsBucketVersions(Map<Address, Long> versions) {
94                 Preconditions.checkArgument(versions != null, "versions can not be null or empty");
95
96                 this.versions = versions;
97             }
98
99             public Map<Address, Long> getVersions() {
100                 return Collections.unmodifiableMap(versions);
101             }
102
103         }
104
105         public static class GetBucketVersionsReply extends ContainsBucketVersions implements Serializable{
106             private static final long serialVersionUID = 1L;
107             public GetBucketVersionsReply(Map<Address, Long> versions) {
108                 super(versions);
109             }
110         }
111
112         public static class UpdateRemoteBuckets extends ContainsBuckets implements Serializable{
113             private static final long serialVersionUID = 1L;
114             public UpdateRemoteBuckets(Map<Address, Bucket> buckets) {
115                 super(buckets);
116             }
117         }
118     }
119
120     public static class GossiperMessages{
121         public static class Tick implements Serializable {
122             private static final long serialVersionUID = 1L;
123         }
124
125         public static final class GossipTick extends Tick {
126             private static final long serialVersionUID = 1L;
127         }
128
129         public static final class GossipStatus extends ContainsBucketVersions implements Serializable{
130             private static final long serialVersionUID = 1L;
131             private final Address from;
132
133             public GossipStatus(Address from, Map<Address, Long> versions) {
134                 super(versions);
135                 this.from = from;
136             }
137
138             public Address from() {
139                 return from;
140             }
141         }
142
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;
147
148             public GossipEnvelope(Address from, Address to, Map<Address, Bucket> buckets) {
149                 super(buckets);
150                 Preconditions.checkArgument(to != null, "Recipient of message must not be null");
151                 this.to = to;
152                 this.from = from;
153             }
154
155             public Address from() {
156                 return from;
157             }
158
159             public Address to() {
160                 return to;
161             }
162         }
163     }
164 }