Fix FindBugs warnings in sal-remoterpc-connector and enable enforcement
[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<T extends Copier<T>> implements Serializable {
49             private static final long serialVersionUID = -4940160367495308286L;
50
51             private final Map<Address, Bucket<T>> buckets;
52
53             public ContainsBuckets(Map<Address, Bucket<T>> buckets) {
54                 Preconditions.checkArgument(buckets != null, "buckets can not be null");
55                 this.buckets = buckets;
56             }
57
58             public Map<Address, Bucket<T>> getBuckets() {
59                 Map<Address, Bucket<T>> copy = new HashMap<>(buckets.size());
60
61                 for (Map.Entry<Address, Bucket<T>> entry : buckets.entrySet()) {
62                     //ignore null entries
63                     if ( entry.getKey() == null || entry.getValue() == null ) {
64                         continue;
65                     }
66                     copy.put(entry.getKey(), entry.getValue());
67                 }
68                 return copy;
69             }
70         }
71
72         public static class GetAllBucketsReply<T extends Copier<T>> extends ContainsBuckets<T> {
73             private static final long serialVersionUID = 1L;
74
75             public GetAllBucketsReply(Map<Address, Bucket<T>> buckets) {
76                 super(buckets);
77             }
78         }
79
80         public static class GetBucketsByMembersReply<T extends Copier<T>> extends ContainsBuckets<T>  {
81             private static final long serialVersionUID = 1L;
82
83             public GetBucketsByMembersReply(Map<Address, Bucket<T>> buckets) {
84                 super(buckets);
85             }
86         }
87
88         public static class GetBucketVersions implements Serializable {
89             private static final long serialVersionUID = 1L;
90         }
91
92         public static class ContainsBucketVersions implements Serializable {
93             private static final long serialVersionUID = -8172148925383801613L;
94
95             Map<Address, Long> versions;
96
97             public ContainsBucketVersions(Map<Address, Long> versions) {
98                 Preconditions.checkArgument(versions != null, "versions can not be null or empty");
99
100                 this.versions = versions;
101             }
102
103             public Map<Address, Long> getVersions() {
104                 return Collections.unmodifiableMap(versions);
105             }
106
107         }
108
109         public static class GetBucketVersionsReply extends ContainsBucketVersions {
110             private static final long serialVersionUID = 1L;
111
112             public GetBucketVersionsReply(Map<Address, Long> versions) {
113                 super(versions);
114             }
115         }
116
117         public static class UpdateRemoteBuckets<T extends Copier<T>> extends ContainsBuckets<T> {
118             private static final long serialVersionUID = 1L;
119
120             public UpdateRemoteBuckets(Map<Address, Bucket<T>> buckets) {
121                 super(buckets);
122             }
123         }
124     }
125
126     public static class GossiperMessages {
127         public static class Tick implements Serializable {
128             private static final long serialVersionUID = -4770935099506366773L;
129         }
130
131         public static final class GossipTick extends Tick {
132             private static final long serialVersionUID = 5803354404380026143L;
133         }
134
135         public static final class GossipStatus extends ContainsBucketVersions {
136             private static final long serialVersionUID = -593037395143883265L;
137
138             private final Address from;
139
140             public GossipStatus(Address from, Map<Address, Long> versions) {
141                 super(versions);
142                 this.from = from;
143             }
144
145             public Address from() {
146                 return from;
147             }
148         }
149
150         public static final class GossipEnvelope<T extends Copier<T>> extends ContainsBuckets<T> {
151             private static final long serialVersionUID = 8346634072582438818L;
152
153             private final Address from;
154             private final Address to;
155
156             public GossipEnvelope(Address from, Address to, Map<Address, Bucket<T>> buckets) {
157                 super(buckets);
158                 Preconditions.checkArgument(to != null, "Recipient of message must not be null");
159                 this.to = to;
160                 this.from = from;
161             }
162
163             public Address from() {
164                 return from;
165             }
166
167             public Address to() {
168                 return to;
169             }
170         }
171     }
172 }