BUG-7573: add BucketStore source monitoring
[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.Map;
16 import java.util.Set;
17 import org.opendaylight.controller.remote.rpc.registry.gossip.Messages.BucketStoreMessages.ContainsBucketVersions;
18 import org.opendaylight.controller.remote.rpc.registry.gossip.Messages.BucketStoreMessages.ContainsBuckets;
19
20 /**
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.
23  */
24 public class Messages {
25
26     public static class BucketStoreMessages {
27
28         public static final class GetAllBuckets implements Serializable {
29             private static final long serialVersionUID = 1L;
30         }
31
32         public static final class GetBucketsByMembers implements Serializable {
33             private static final long serialVersionUID = 1L;
34             private final Set<Address> members;
35
36             public GetBucketsByMembers(final Set<Address> members) {
37                 Preconditions.checkArgument(members != null, "members can not be null");
38                 this.members = ImmutableSet.copyOf(members);
39             }
40
41             public Set<Address> getMembers() {
42                 return members;
43             }
44         }
45
46         public static class ContainsBuckets<T extends BucketData<T>> implements Serializable {
47             private static final long serialVersionUID = -4940160367495308286L;
48
49             private final Map<Address, Bucket<T>> buckets;
50
51             protected ContainsBuckets(final Map<Address, Bucket<T>> buckets) {
52                 Preconditions.checkArgument(buckets != null, "buckets can not be null");
53                 this.buckets = ImmutableMap.copyOf(buckets);
54             }
55
56             public final Map<Address, Bucket<T>> getBuckets() {
57                 return buckets;
58             }
59         }
60
61         public static final class GetAllBucketsReply<T extends BucketData<T>> extends ContainsBuckets<T> {
62             private static final long serialVersionUID = 1L;
63
64             public GetAllBucketsReply(final Map<Address, Bucket<T>> buckets) {
65                 super(buckets);
66             }
67         }
68
69         public static final class GetBucketsByMembersReply<T extends BucketData<T>> extends ContainsBuckets<T>  {
70             private static final long serialVersionUID = 1L;
71
72             public GetBucketsByMembersReply(final Map<Address, Bucket<T>> buckets) {
73                 super(buckets);
74             }
75         }
76
77         public static final class GetBucketVersions implements Serializable {
78             private static final long serialVersionUID = 1L;
79         }
80
81         public static class ContainsBucketVersions implements Serializable {
82             private static final long serialVersionUID = -8172148925383801613L;
83
84             Map<Address, Long> versions;
85
86             public ContainsBucketVersions(final Map<Address, Long> versions) {
87                 Preconditions.checkArgument(versions != null, "versions can not be null or empty");
88
89                 this.versions = ImmutableMap.copyOf(versions);
90             }
91
92             public Map<Address, Long> getVersions() {
93                 return versions;
94             }
95         }
96
97         public static final class GetBucketVersionsReply extends ContainsBucketVersions {
98             private static final long serialVersionUID = 1L;
99
100             public GetBucketVersionsReply(final Map<Address, Long> versions) {
101                 super(versions);
102             }
103         }
104
105         public static final class UpdateRemoteBuckets<T extends BucketData<T>> extends ContainsBuckets<T> {
106             private static final long serialVersionUID = 1L;
107
108             public UpdateRemoteBuckets(final Map<Address, Bucket<T>> buckets) {
109                 super(buckets);
110             }
111         }
112
113         /**
114          * Message sent from the gossiper to its parent, therefore not Serializable, requesting removal
115          * of a bucket corresponding to an address.
116          */
117         public static final class RemoveRemoteBucket {
118             private final Address address;
119
120             public RemoveRemoteBucket(final Address address) {
121                 this.address = Preconditions.checkNotNull(address);
122             }
123
124             public Address getAddress() {
125                 return address;
126             }
127         }
128     }
129
130     public static class GossiperMessages {
131         public static class Tick implements Serializable {
132             private static final long serialVersionUID = -4770935099506366773L;
133         }
134
135         public static final class GossipTick extends Tick {
136             private static final long serialVersionUID = 5803354404380026143L;
137         }
138
139         public static final class GossipStatus extends ContainsBucketVersions {
140             private static final long serialVersionUID = -593037395143883265L;
141
142             private final Address from;
143
144             public GossipStatus(final Address from, final Map<Address, Long> versions) {
145                 super(versions);
146                 this.from = from;
147             }
148
149             public Address from() {
150                 return from;
151             }
152         }
153
154         public static final class GossipEnvelope<T extends BucketData<T>> extends ContainsBuckets<T> {
155             private static final long serialVersionUID = 8346634072582438818L;
156
157             private final Address from;
158             private final Address to;
159
160             public GossipEnvelope(final Address from, final Address to, final Map<Address, Bucket<T>> 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 }