361f5b7e1c07bf4b3cf07539a58bdf421cf177bb
[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 com.google.common.collect.ImmutableMap;
13 import com.google.common.collect.ImmutableSet;
14 import java.io.Serializable;
15 import java.util.Collections;
16 import java.util.HashMap;
17 import java.util.Map;
18 import java.util.Set;
19 import org.opendaylight.controller.remote.rpc.registry.gossip.Messages.BucketStoreMessages.ContainsBucketVersions;
20 import org.opendaylight.controller.remote.rpc.registry.gossip.Messages.BucketStoreMessages.ContainsBuckets;
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 final class GetAllBuckets implements Serializable {
31             private static final long serialVersionUID = 1L;
32         }
33
34         public static final class GetBucketsByMembers implements Serializable {
35             private static final long serialVersionUID = 1L;
36             private final Set<Address> members;
37
38             public GetBucketsByMembers(final Set<Address> members) {
39                 Preconditions.checkArgument(members != null, "members can not be null");
40                 this.members = ImmutableSet.copyOf(members);
41             }
42
43             public Set<Address> getMembers() {
44                 return members;
45             }
46         }
47
48         public static class ContainsBuckets<T extends BucketData<T>> implements Serializable {
49             private static final long serialVersionUID = -4940160367495308286L;
50
51             private final Map<Address, Bucket<T>> buckets;
52
53             protected ContainsBuckets(final Map<Address, Bucket<T>> buckets) {
54                 Preconditions.checkArgument(buckets != null, "buckets can not be null");
55                 this.buckets = Collections.unmodifiableMap(new HashMap<>(buckets));
56             }
57
58             public final Map<Address, Bucket<T>> getBuckets() {
59                 return buckets;
60             }
61         }
62
63         public static final class GetAllBucketsReply<T extends BucketData<T>> extends ContainsBuckets<T> {
64             private static final long serialVersionUID = 1L;
65
66             public GetAllBucketsReply(final Map<Address, Bucket<T>> buckets) {
67                 super(buckets);
68             }
69         }
70
71         public static final class GetBucketsByMembersReply<T extends BucketData<T>> extends ContainsBuckets<T>  {
72             private static final long serialVersionUID = 1L;
73
74             public GetBucketsByMembersReply(final Map<Address, Bucket<T>> buckets) {
75                 super(buckets);
76             }
77         }
78
79         public static final class GetBucketVersions implements Serializable {
80             private static final long serialVersionUID = 1L;
81         }
82
83         public static class ContainsBucketVersions implements Serializable {
84             private static final long serialVersionUID = -8172148925383801613L;
85
86             Map<Address, Long> versions;
87
88             public ContainsBucketVersions(final Map<Address, Long> versions) {
89                 Preconditions.checkArgument(versions != null, "versions can not be null or empty");
90
91                 this.versions = ImmutableMap.copyOf(versions);
92             }
93
94             public Map<Address, Long> getVersions() {
95                 return versions;
96             }
97         }
98
99         public static final class GetBucketVersionsReply extends ContainsBucketVersions {
100             private static final long serialVersionUID = 1L;
101
102             public GetBucketVersionsReply(final Map<Address, Long> versions) {
103                 super(versions);
104             }
105         }
106
107         public static final class UpdateRemoteBuckets<T extends BucketData<T>> extends ContainsBuckets<T> {
108             private static final long serialVersionUID = 1L;
109
110             public UpdateRemoteBuckets(final Map<Address, Bucket<T>> buckets) {
111                 super(buckets);
112             }
113         }
114
115         /**
116          * Message sent from the gossiper to its parent, therefore not Serializable, requesting removal
117          * of a bucket corresponding to an address.
118          */
119         public static final class RemoveRemoteBucket {
120             private final Address address;
121
122             public RemoveRemoteBucket(final Address address) {
123                 this.address = Preconditions.checkNotNull(address);
124             }
125
126             public Address getAddress() {
127                 return address;
128             }
129         }
130     }
131
132     public static class GossiperMessages {
133         public static class Tick implements Serializable {
134             private static final long serialVersionUID = -4770935099506366773L;
135         }
136
137         public static final class GossipTick extends Tick {
138             private static final long serialVersionUID = 5803354404380026143L;
139         }
140
141         public static final class GossipStatus extends ContainsBucketVersions {
142             private static final long serialVersionUID = -593037395143883265L;
143
144             private final Address from;
145
146             public GossipStatus(final Address from, final 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<T extends BucketData<T>> extends ContainsBuckets<T> {
157             private static final long serialVersionUID = 8346634072582438818L;
158
159             private final Address from;
160             private final Address to;
161
162             public GossipEnvelope(final Address from, final Address to, final Map<Address, Bucket<T>> buckets) {
163                 super(buckets);
164                 Preconditions.checkArgument(to != null, "Recipient of message must not be null");
165                 this.to = to;
166                 this.from = from;
167             }
168
169             public Address from() {
170                 return from;
171             }
172
173             public Address to() {
174                 return to;
175             }
176         }
177     }
178 }