Merge "Updated RpcRegistry to accept a list of route identifiers while adding or...
[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
34         public static class ContainsBucket implements Serializable {
35             final private Bucket bucket;
36
37             public ContainsBucket(Bucket bucket){
38                 Preconditions.checkArgument(bucket != null, "bucket can not be null");
39                 this.bucket = bucket;
40             }
41
42             public Bucket getBucket(){
43                 return bucket;
44             }
45
46         }
47
48         public static class UpdateBucket extends ContainsBucket implements Serializable {
49             public UpdateBucket(Bucket bucket){
50                 super(bucket);
51             }
52         }
53
54         public static class GetLocalBucketReply extends ContainsBucket implements Serializable {
55             public GetLocalBucketReply(Bucket bucket){
56                 super(bucket);
57             }
58         }
59
60         public static class GetAllBuckets implements Serializable{}
61
62         public static class GetBucketsByMembers implements Serializable{
63             private Set<Address> members;
64
65             public GetBucketsByMembers(Set<Address> members){
66                 Preconditions.checkArgument(members != null, "members can not be null");
67                 this.members = members;
68             }
69
70             public Set<Address> getMembers() {
71                 return new HashSet<>(members);
72             }
73         }
74
75         public static class ContainsBuckets implements Serializable{
76             private Map<Address, Bucket> buckets;
77
78             public ContainsBuckets(Map<Address, Bucket> buckets){
79                 Preconditions.checkArgument(buckets != null, "buckets can not be null");
80                 this.buckets = buckets;
81             }
82
83             public Map<Address, Bucket> getBuckets() {
84                 Map<Address, Bucket> copy = new HashMap<>(buckets.size());
85
86                 for (Map.Entry<Address, Bucket> entry : buckets.entrySet()){
87                     //ignore null entries
88                     if ( (entry.getKey() == null) || (entry.getValue() == null) )
89                         continue;
90                     copy.put(entry.getKey(), entry.getValue());
91                 }
92                 return new HashMap<>(copy);
93             }
94         }
95
96         public static class GetAllBucketsReply extends ContainsBuckets implements Serializable{
97             public GetAllBucketsReply(Map<Address, Bucket> buckets) {
98                 super(buckets);
99             }
100         }
101
102         public static class GetBucketsByMembersReply extends ContainsBuckets implements Serializable{
103             public GetBucketsByMembersReply(Map<Address, Bucket> buckets) {
104                 super(buckets);
105             }
106         }
107
108         public static class GetBucketVersions implements Serializable{}
109
110         public static class ContainsBucketVersions implements Serializable{
111             Map<Address, Long> versions;
112
113             public ContainsBucketVersions(Map<Address, Long> versions) {
114                 Preconditions.checkArgument(versions != null, "versions can not be null or empty");
115
116                 this.versions = versions;
117             }
118
119             public Map<Address, Long> getVersions() {
120                 return Collections.unmodifiableMap(versions);
121             }
122
123         }
124
125         public static class GetBucketVersionsReply extends ContainsBucketVersions implements Serializable{
126             public GetBucketVersionsReply(Map<Address, Long> versions) {
127                 super(versions);
128             }
129         }
130
131         public static class UpdateRemoteBuckets extends ContainsBuckets implements Serializable{
132             public UpdateRemoteBuckets(Map<Address, Bucket> buckets) {
133                 super(buckets);
134             }
135         }
136     }
137
138     public static class GossiperMessages{
139         public static class Tick implements Serializable {}
140
141         public static final class GossipTick extends Tick {}
142
143         public static final class GossipStatus extends ContainsBucketVersions implements Serializable{
144             private Address from;
145
146             public GossipStatus(Address from, Map<Address, Long> versions) {
147                 super(versions);
148                 this.from = from;
149             }
150
151             public Address from() {
152                 return from;
153             }
154         }
155
156         public static final class GossipEnvelope extends ContainsBuckets implements Serializable {
157             private final Address from;
158             private final Address to;
159
160             public GossipEnvelope(Address from, Address to, Map<Address, Bucket> buckets) {
161                 super(buckets);
162                 Preconditions.checkArgument(to != null, "Recipient of message must not be null");
163                 this.to = to;
164                 this.from = from;
165             }
166
167             public Address from() {
168                 return from;
169             }
170
171             public Address to() {
172                 return to;
173             }
174         }
175     }
176 }