Merge "Fix raw use of Gauge"
[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
13 import java.io.Serializable;
14 import java.util.Collections;
15 import java.util.HashMap;
16 import java.util.HashSet;
17 import java.util.Map;
18 import java.util.Set;
19
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;
22
23
24 /**
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.
27  */
28 public class Messages {
29
30     public static class BucketStoreMessages{
31
32         public static class GetLocalBucket implements Serializable {
33             private static final long serialVersionUID = 1L;
34         }
35
36         public static class ContainsBucket implements Serializable {
37             private static final long serialVersionUID = 1L;
38             final private Bucket bucket;
39
40             public ContainsBucket(Bucket bucket){
41                 Preconditions.checkArgument(bucket != null, "bucket can not be null");
42                 this.bucket = bucket;
43             }
44
45             public Bucket getBucket(){
46                 return bucket;
47             }
48
49         }
50
51         public static class UpdateBucket extends ContainsBucket implements Serializable {
52             private static final long serialVersionUID = 1L;
53             public UpdateBucket(Bucket bucket){
54                 super(bucket);
55             }
56         }
57
58         public static class GetLocalBucketReply extends ContainsBucket implements Serializable {
59             private static final long serialVersionUID = 1L;
60             public GetLocalBucketReply(Bucket bucket){
61                 super(bucket);
62             }
63         }
64
65         public static class GetAllBuckets implements Serializable {
66             private static final long serialVersionUID = 1L;
67         }
68
69         public static class GetBucketsByMembers implements Serializable{
70             private static final long serialVersionUID = 1L;
71             private Set<Address> members;
72
73             public GetBucketsByMembers(Set<Address> members){
74                 Preconditions.checkArgument(members != null, "members can not be null");
75                 this.members = members;
76             }
77
78             public Set<Address> getMembers() {
79                 return new HashSet<>(members);
80             }
81         }
82
83         public static class ContainsBuckets implements Serializable{
84             private static final long serialVersionUID = 1L;
85             private Map<Address, Bucket> buckets;
86
87             public ContainsBuckets(Map<Address, Bucket> buckets){
88                 Preconditions.checkArgument(buckets != null, "buckets can not be null");
89                 this.buckets = buckets;
90             }
91
92             public Map<Address, Bucket> getBuckets() {
93                 Map<Address, Bucket> copy = new HashMap<>(buckets.size());
94
95                 for (Map.Entry<Address, Bucket> entry : buckets.entrySet()){
96                     //ignore null entries
97                     if ( (entry.getKey() == null) || (entry.getValue() == null) )
98                         continue;
99                     copy.put(entry.getKey(), entry.getValue());
100                 }
101                 return new HashMap<>(copy);
102             }
103         }
104
105         public static class GetAllBucketsReply extends ContainsBuckets implements Serializable{
106             private static final long serialVersionUID = 1L;
107             public GetAllBucketsReply(Map<Address, Bucket> buckets) {
108                 super(buckets);
109             }
110         }
111
112         public static class GetBucketsByMembersReply extends ContainsBuckets implements Serializable{
113             private static final long serialVersionUID = 1L;
114             public GetBucketsByMembersReply(Map<Address, Bucket> buckets) {
115                 super(buckets);
116             }
117         }
118
119         public static class GetBucketVersions implements Serializable {
120             private static final long serialVersionUID = 1L;
121         }
122
123         public static class ContainsBucketVersions implements Serializable{
124             private static final long serialVersionUID = 1L;
125             Map<Address, Long> versions;
126
127             public ContainsBucketVersions(Map<Address, Long> versions) {
128                 Preconditions.checkArgument(versions != null, "versions can not be null or empty");
129
130                 this.versions = versions;
131             }
132
133             public Map<Address, Long> getVersions() {
134                 return Collections.unmodifiableMap(versions);
135             }
136
137         }
138
139         public static class GetBucketVersionsReply extends ContainsBucketVersions implements Serializable{
140             private static final long serialVersionUID = 1L;
141             public GetBucketVersionsReply(Map<Address, Long> versions) {
142                 super(versions);
143             }
144         }
145
146         public static class UpdateRemoteBuckets extends ContainsBuckets implements Serializable{
147             private static final long serialVersionUID = 1L;
148             public UpdateRemoteBuckets(Map<Address, Bucket> buckets) {
149                 super(buckets);
150             }
151         }
152     }
153
154     public static class GossiperMessages{
155         public static class Tick implements Serializable {
156             private static final long serialVersionUID = 1L;
157         }
158
159         public static final class GossipTick extends Tick {
160             private static final long serialVersionUID = 1L;
161         }
162
163         public static final class GossipStatus extends ContainsBucketVersions implements Serializable{
164             private static final long serialVersionUID = 1L;
165             private Address from;
166
167             public GossipStatus(Address from, Map<Address, Long> versions) {
168                 super(versions);
169                 this.from = from;
170             }
171
172             public Address from() {
173                 return from;
174             }
175         }
176
177         public static final class GossipEnvelope extends ContainsBuckets implements Serializable {
178             private static final long serialVersionUID = 1L;
179             private final Address from;
180             private final Address to;
181
182             public GossipEnvelope(Address from, Address to, Map<Address, Bucket> buckets) {
183                 super(buckets);
184                 Preconditions.checkArgument(to != null, "Recipient of message must not be null");
185                 this.to = to;
186                 this.from = from;
187             }
188
189             public Address from() {
190                 return from;
191             }
192
193             public Address to() {
194                 return to;
195             }
196         }
197     }
198 }