tom

Fixed equals methods for better efficiency.

Cleaned up ClusterService API.
Showing 31 changed files with 148 additions and 23 deletions
...@@ -8,7 +8,7 @@ import org.onlab.onos.event.AbstractEvent; ...@@ -8,7 +8,7 @@ import org.onlab.onos.event.AbstractEvent;
8 public class ClusterEvent extends AbstractEvent<ClusterEvent.Type, ControllerInstance> { 8 public class ClusterEvent extends AbstractEvent<ClusterEvent.Type, ControllerInstance> {
9 9
10 /** 10 /**
11 - * Type of device events. 11 + * Type of cluster-related events.
12 */ 12 */
13 public enum Type { 13 public enum Type {
14 /** 14 /**
...@@ -24,14 +24,13 @@ public class ClusterEvent extends AbstractEvent<ClusterEvent.Type, ControllerIns ...@@ -24,14 +24,13 @@ public class ClusterEvent extends AbstractEvent<ClusterEvent.Type, ControllerIns
24 /** 24 /**
25 * Signifies that a cluster instance became active. 25 * Signifies that a cluster instance became active.
26 */ 26 */
27 - INSTANCE_ACTIVE, 27 + INSTANCE_ACTIVATED,
28 28
29 /** 29 /**
30 * Signifies that a cluster instance became inactive. 30 * Signifies that a cluster instance became inactive.
31 */ 31 */
32 - INSTANCE_INACTIVE 32 + INSTANCE_DEACTIVATED
33 } 33 }
34 - // TODO: do we need to fix the verv/adjective mix? discuss
35 34
36 /** 35 /**
37 * Creates an event of a given type and for the specified instance and the 36 * Creates an event of a given type and for the specified instance and the
......
1 +package org.onlab.onos.cluster;
2 +
3 +import org.onlab.onos.event.EventListener;
4 +
5 +/**
6 + * Entity capable of receiving device cluster-related events.
7 + */
8 +public interface ClusterEventListener extends EventListener<ClusterEvent> {
9 +}
...@@ -21,9 +21,19 @@ public interface ClusterService { ...@@ -21,9 +21,19 @@ public interface ClusterService {
21 * @return availability state 21 * @return availability state
22 */ 22 */
23 ControllerInstance.State getState(ControllerInstance instance); 23 ControllerInstance.State getState(ControllerInstance instance);
24 - // TODO: determine if this would be better attached to ControllerInstance directly
25 24
25 + /**
26 + * Adds the specified cluster event listener.
27 + *
28 + * @param listener the cluster listener
29 + */
30 + void addListener(ClusterEventListener listener);
26 31
27 - // addListener, removeListener 32 + /**
33 + * Removes the specified cluster event listener.
34 + *
35 + * @param listener the cluster listener
36 + */
37 + void removeListener(ClusterEventListener listener);
28 38
29 } 39 }
......
1 package org.onlab.onos.cluster; 1 package org.onlab.onos.cluster;
2 2
3 +import java.util.Objects;
4 +
5 +import static com.google.common.base.MoreObjects.toStringHelper;
6 +
3 /** 7 /**
4 * Controller cluster identity. 8 * Controller cluster identity.
5 */ 9 */
6 -public interface InstanceId { 10 +public class InstanceId {
11 +
12 + private final String id;
13 +
14 + // Default constructor for serialization
15 + protected InstanceId() {
16 + id = null;
17 + }
18 +
19 + /**
20 + * Creates a new cluster instance identifier from the specified string.
21 + *
22 + * @param id string identifier
23 + */
24 + public InstanceId(String id) {
25 + this.id = id;
26 + }
27 +
28 + @Override
29 + public int hashCode() {
30 + return Objects.hash(id);
31 + }
32 +
33 + @Override
34 + public boolean equals(Object obj) {
35 + if (this == obj) {
36 + return true;
37 + }
38 + if (obj instanceof InstanceId) {
39 + final InstanceId other = (InstanceId) obj;
40 + return Objects.equals(this.id, other.id);
41 + }
42 + return false;
43 + }
44 +
45 + @Override
46 + public String toString() {
47 + return toStringHelper(this).add("id", id).toString();
48 + }
49 +
7 } 50 }
......
...@@ -6,5 +6,4 @@ import org.onlab.onos.event.EventListener; ...@@ -6,5 +6,4 @@ import org.onlab.onos.event.EventListener;
6 * Entity capable of receiving device mastership-related events. 6 * Entity capable of receiving device mastership-related events.
7 */ 7 */
8 public interface MastershipListener extends EventListener<MastershipEvent> { 8 public interface MastershipListener extends EventListener<MastershipEvent> {
9 -
10 } 9 }
......
...@@ -38,14 +38,14 @@ public interface MastershipService { ...@@ -38,14 +38,14 @@ public interface MastershipService {
38 MastershipRole requestRoleFor(DeviceId deviceId); 38 MastershipRole requestRoleFor(DeviceId deviceId);
39 39
40 /** 40 /**
41 - * Adds the specified mastership listener. 41 + * Adds the specified mastership change listener.
42 * 42 *
43 * @param listener the mastership listener 43 * @param listener the mastership listener
44 */ 44 */
45 void addListener(MastershipListener listener); 45 void addListener(MastershipListener listener);
46 46
47 /** 47 /**
48 - * Removes the specified device listener. 48 + * Removes the specified mastership change listener.
49 * 49 *
50 * @param listener the mastership listener 50 * @param listener the mastership listener
51 */ 51 */
......
...@@ -20,8 +20,8 @@ public interface MastershipStore { ...@@ -20,8 +20,8 @@ public interface MastershipStore {
20 * @param role new role 20 * @param role new role
21 * @return a mastership event 21 * @return a mastership event
22 */ 22 */
23 - MastershipEvent setRole( 23 + MastershipEvent setRole(InstanceId instance, DeviceId deviceId,
24 - InstanceId instance, DeviceId deviceId, MastershipRole role); 24 + MastershipRole role);
25 25
26 /** 26 /**
27 * Adds or updates the mastership information for a device. 27 * Adds or updates the mastership information for a device.
...@@ -31,8 +31,8 @@ public interface MastershipStore { ...@@ -31,8 +31,8 @@ public interface MastershipStore {
31 * @param role new role 31 * @param role new role
32 * @return a mastership event 32 * @return a mastership event
33 */ 33 */
34 - MastershipEvent addOrUpdateDevice( 34 + MastershipEvent addOrUpdateDevice(InstanceId instance, DeviceId deviceId,
35 - InstanceId instance, DeviceId deviceId, MastershipRole role); 35 + MastershipRole role);
36 36
37 /** 37 /**
38 * Returns the master for a device. 38 * Returns the master for a device.
...@@ -45,7 +45,7 @@ public interface MastershipStore { ...@@ -45,7 +45,7 @@ public interface MastershipStore {
45 /** 45 /**
46 * Returns the devices that a controller instance is master of. 46 * Returns the devices that a controller instance is master of.
47 * 47 *
48 - * @param instanceId the instance identifier 48 + * @param instanceId the instance identifier
49 * @return a set of device identifiers 49 * @return a set of device identifiers
50 */ 50 */
51 Set<DeviceId> getDevices(InstanceId instanceId); 51 Set<DeviceId> getDevices(InstanceId instanceId);
...@@ -54,7 +54,7 @@ public interface MastershipStore { ...@@ -54,7 +54,7 @@ public interface MastershipStore {
54 * Returns the role of a device for a specific controller instance. 54 * Returns the role of a device for a specific controller instance.
55 * 55 *
56 * @param instanceId the instance identifier 56 * @param instanceId the instance identifier
57 - * @param deviceId the device identifiers 57 + * @param deviceId the device identifiers
58 * @return the role 58 * @return the role
59 */ 59 */
60 MastershipRole getRole(InstanceId instanceId, DeviceId deviceId); 60 MastershipRole getRole(InstanceId instanceId, DeviceId deviceId);
......
...@@ -66,6 +66,9 @@ public class ConnectPoint { ...@@ -66,6 +66,9 @@ public class ConnectPoint {
66 66
67 @Override 67 @Override
68 public boolean equals(Object obj) { 68 public boolean equals(Object obj) {
69 + if (this == obj) {
70 + return true;
71 + }
69 if (obj instanceof ConnectPoint) { 72 if (obj instanceof ConnectPoint) {
70 final ConnectPoint other = (ConnectPoint) obj; 73 final ConnectPoint other = (ConnectPoint) obj;
71 return Objects.equals(this.elementId, other.elementId) && 74 return Objects.equals(this.elementId, other.elementId) &&
......
...@@ -85,6 +85,9 @@ public class DefaultDevice extends AbstractElement implements Device { ...@@ -85,6 +85,9 @@ public class DefaultDevice extends AbstractElement implements Device {
85 85
86 @Override 86 @Override
87 public boolean equals(Object obj) { 87 public boolean equals(Object obj) {
88 + if (this == obj) {
89 + return true;
90 + }
88 if (obj instanceof DefaultDevice) { 91 if (obj instanceof DefaultDevice) {
89 final DefaultDevice other = (DefaultDevice) obj; 92 final DefaultDevice other = (DefaultDevice) obj;
90 return Objects.equals(this.id, other.id) && 93 return Objects.equals(this.id, other.id) &&
......
...@@ -63,6 +63,9 @@ public class DefaultHost extends AbstractElement implements Host { ...@@ -63,6 +63,9 @@ public class DefaultHost extends AbstractElement implements Host {
63 63
64 @Override 64 @Override
65 public boolean equals(Object obj) { 65 public boolean equals(Object obj) {
66 + if (this == obj) {
67 + return true;
68 + }
66 if (obj instanceof DefaultHost) { 69 if (obj instanceof DefaultHost) {
67 final DefaultHost other = (DefaultHost) obj; 70 final DefaultHost other = (DefaultHost) obj;
68 return Objects.equals(this.id, other.id) && 71 return Objects.equals(this.id, other.id) &&
......
...@@ -53,6 +53,9 @@ public class DefaultLink extends AbstractModel implements Link { ...@@ -53,6 +53,9 @@ public class DefaultLink extends AbstractModel implements Link {
53 53
54 @Override 54 @Override
55 public boolean equals(Object obj) { 55 public boolean equals(Object obj) {
56 + if (this == obj) {
57 + return true;
58 + }
56 if (obj instanceof DefaultLink) { 59 if (obj instanceof DefaultLink) {
57 final DefaultLink other = (DefaultLink) obj; 60 final DefaultLink other = (DefaultLink) obj;
58 return Objects.equals(this.src, other.src) && 61 return Objects.equals(this.src, other.src) &&
......
...@@ -57,11 +57,14 @@ public class DefaultPath extends DefaultLink implements Path { ...@@ -57,11 +57,14 @@ public class DefaultPath extends DefaultLink implements Path {
57 57
58 @Override 58 @Override
59 public int hashCode() { 59 public int hashCode() {
60 - return 31 * super.hashCode() + Objects.hash(links); 60 + return Objects.hash(links);
61 } 61 }
62 62
63 @Override 63 @Override
64 public boolean equals(Object obj) { 64 public boolean equals(Object obj) {
65 + if (this == obj) {
66 + return true;
67 + }
65 if (obj instanceof DefaultPath) { 68 if (obj instanceof DefaultPath) {
66 final DefaultPath other = (DefaultPath) obj; 69 final DefaultPath other = (DefaultPath) obj;
67 return Objects.equals(this.links, other.links); 70 return Objects.equals(this.links, other.links);
......
...@@ -58,6 +58,9 @@ public class DefaultPort implements Port { ...@@ -58,6 +58,9 @@ public class DefaultPort implements Port {
58 58
59 @Override 59 @Override
60 public boolean equals(Object obj) { 60 public boolean equals(Object obj) {
61 + if (this == obj) {
62 + return true;
63 + }
61 if (obj instanceof DefaultPort) { 64 if (obj instanceof DefaultPort) {
62 final DefaultPort other = (DefaultPort) obj; 65 final DefaultPort other = (DefaultPort) obj;
63 return Objects.equals(this.element.id(), other.element.id()) && 66 return Objects.equals(this.element.id(), other.element.id()) &&
......
...@@ -40,6 +40,9 @@ public abstract class ElementId { ...@@ -40,6 +40,9 @@ public abstract class ElementId {
40 40
41 @Override 41 @Override
42 public boolean equals(Object obj) { 42 public boolean equals(Object obj) {
43 + if (this == obj) {
44 + return true;
45 + }
43 if (obj instanceof ElementId) { 46 if (obj instanceof ElementId) {
44 final ElementId that = (ElementId) obj; 47 final ElementId that = (ElementId) obj;
45 return this.getClass() == that.getClass() && 48 return this.getClass() == that.getClass() &&
......
...@@ -79,6 +79,9 @@ public final class PortNumber { ...@@ -79,6 +79,9 @@ public final class PortNumber {
79 79
80 @Override 80 @Override
81 public boolean equals(Object obj) { 81 public boolean equals(Object obj) {
82 + if (this == obj) {
83 + return true;
84 + }
82 if (obj instanceof PortNumber) { 85 if (obj instanceof PortNumber) {
83 final PortNumber other = (PortNumber) obj; 86 final PortNumber other = (PortNumber) obj;
84 return this.number == other.number; 87 return this.number == other.number;
......
...@@ -147,7 +147,6 @@ public class DefaultFlowRule implements FlowRule { ...@@ -147,7 +147,6 @@ public class DefaultFlowRule implements FlowRule {
147 * @see java.lang.Object#equals(java.lang.Object) 147 * @see java.lang.Object#equals(java.lang.Object)
148 */ 148 */
149 public boolean equals(Object obj) { 149 public boolean equals(Object obj) {
150 -
151 if (this == obj) { 150 if (this == obj) {
152 return true; 151 return true;
153 } 152 }
......
...@@ -54,6 +54,9 @@ public class DefaultInboundPacket implements InboundPacket { ...@@ -54,6 +54,9 @@ public class DefaultInboundPacket implements InboundPacket {
54 54
55 @Override 55 @Override
56 public boolean equals(Object obj) { 56 public boolean equals(Object obj) {
57 + if (this == obj) {
58 + return true;
59 + }
57 if (obj instanceof InboundPacket) { 60 if (obj instanceof InboundPacket) {
58 final DefaultInboundPacket other = (DefaultInboundPacket) obj; 61 final DefaultInboundPacket other = (DefaultInboundPacket) obj;
59 return Objects.equals(this.receivedFrom, other.receivedFrom) && 62 return Objects.equals(this.receivedFrom, other.receivedFrom) &&
......
...@@ -50,12 +50,12 @@ public class ProviderId { ...@@ -50,12 +50,12 @@ public class ProviderId {
50 if (this == obj) { 50 if (this == obj) {
51 return true; 51 return true;
52 } 52 }
53 - if (obj == null || getClass() != obj.getClass()) { 53 + if (obj instanceof ProviderId) {
54 - return false; 54 + final ProviderId other = (ProviderId) obj;
55 + return Objects.equals(this.scheme, other.scheme) &&
56 + Objects.equals(this.id, other.id);
55 } 57 }
56 - final ProviderId other = (ProviderId) obj; 58 + return false;
57 - return Objects.equals(this.scheme, other.scheme) &&
58 - Objects.equals(this.id, other.id);
59 } 59 }
60 60
61 @Override 61 @Override
......
...@@ -43,6 +43,9 @@ public final class ClusterId { ...@@ -43,6 +43,9 @@ public final class ClusterId {
43 43
44 @Override 44 @Override
45 public boolean equals(Object obj) { 45 public boolean equals(Object obj) {
46 + if (this == obj) {
47 + return true;
48 + }
46 if (obj instanceof ClusterId) { 49 if (obj instanceof ClusterId) {
47 final ClusterId other = (ClusterId) obj; 50 final ClusterId other = (ClusterId) obj;
48 return Objects.equals(this.id, other.id); 51 return Objects.equals(this.id, other.id);
......
...@@ -59,6 +59,9 @@ public class DefaultTopologyCluster implements TopologyCluster { ...@@ -59,6 +59,9 @@ public class DefaultTopologyCluster implements TopologyCluster {
59 59
60 @Override 60 @Override
61 public boolean equals(Object obj) { 61 public boolean equals(Object obj) {
62 + if (this == obj) {
63 + return true;
64 + }
62 if (obj instanceof DefaultTopologyCluster) { 65 if (obj instanceof DefaultTopologyCluster) {
63 final DefaultTopologyCluster other = (DefaultTopologyCluster) obj; 66 final DefaultTopologyCluster other = (DefaultTopologyCluster) obj;
64 return Objects.equals(this.id, other.id) && 67 return Objects.equals(this.id, other.id) &&
......
...@@ -50,6 +50,9 @@ public class DefaultTopologyEdge implements TopologyEdge { ...@@ -50,6 +50,9 @@ public class DefaultTopologyEdge implements TopologyEdge {
50 50
51 @Override 51 @Override
52 public boolean equals(Object obj) { 52 public boolean equals(Object obj) {
53 + if (this == obj) {
54 + return true;
55 + }
53 if (obj instanceof DefaultTopologyEdge) { 56 if (obj instanceof DefaultTopologyEdge) {
54 final DefaultTopologyEdge other = (DefaultTopologyEdge) obj; 57 final DefaultTopologyEdge other = (DefaultTopologyEdge) obj;
55 return Objects.equals(this.link, other.link); 58 return Objects.equals(this.link, other.link);
......
...@@ -32,6 +32,9 @@ public class DefaultTopologyVertex implements TopologyVertex { ...@@ -32,6 +32,9 @@ public class DefaultTopologyVertex implements TopologyVertex {
32 32
33 @Override 33 @Override
34 public boolean equals(Object obj) { 34 public boolean equals(Object obj) {
35 + if (this == obj) {
36 + return true;
37 + }
35 if (obj instanceof DefaultTopologyVertex) { 38 if (obj instanceof DefaultTopologyVertex) {
36 final DefaultTopologyVertex other = (DefaultTopologyVertex) obj; 39 final DefaultTopologyVertex other = (DefaultTopologyVertex) obj;
37 return Objects.equals(this.deviceId, other.deviceId); 40 return Objects.equals(this.deviceId, other.deviceId);
......
...@@ -28,6 +28,9 @@ class PathKey { ...@@ -28,6 +28,9 @@ class PathKey {
28 28
29 @Override 29 @Override
30 public boolean equals(Object obj) { 30 public boolean equals(Object obj) {
31 + if (this == obj) {
32 + return true;
33 + }
31 if (obj instanceof PathKey) { 34 if (obj instanceof PathKey) {
32 final PathKey other = (PathKey) obj; 35 final PathKey other = (PathKey) obj;
33 return Objects.equals(this.src, other.src) && Objects.equals(this.dst, other.dst); 36 return Objects.equals(this.src, other.src) && Objects.equals(this.dst, other.dst);
......
...@@ -179,6 +179,9 @@ public class SimpleLinkStore implements LinkStore { ...@@ -179,6 +179,9 @@ public class SimpleLinkStore implements LinkStore {
179 179
180 @Override 180 @Override
181 public boolean equals(Object obj) { 181 public boolean equals(Object obj) {
182 + if (this == obj) {
183 + return true;
184 + }
182 if (obj instanceof LinkKey) { 185 if (obj instanceof LinkKey) {
183 final LinkKey other = (LinkKey) obj; 186 final LinkKey other = (LinkKey) obj;
184 return Objects.equals(this.src, other.src) && 187 return Objects.equals(this.src, other.src) &&
......
...@@ -41,6 +41,9 @@ public abstract class AbstractEdge<V extends Vertex> implements Edge<V> { ...@@ -41,6 +41,9 @@ public abstract class AbstractEdge<V extends Vertex> implements Edge<V> {
41 41
42 @Override 42 @Override
43 public boolean equals(Object obj) { 43 public boolean equals(Object obj) {
44 + if (this == obj) {
45 + return true;
46 + }
44 if (obj instanceof AbstractEdge) { 47 if (obj instanceof AbstractEdge) {
45 final AbstractEdge other = (AbstractEdge) obj; 48 final AbstractEdge other = (AbstractEdge) obj;
46 return Objects.equals(this.src, other.src) && Objects.equals(this.dst, other.dst); 49 return Objects.equals(this.src, other.src) && Objects.equals(this.dst, other.dst);
......
...@@ -80,6 +80,9 @@ public class AdjacencyListsGraph<V extends Vertex, E extends Edge<V>> ...@@ -80,6 +80,9 @@ public class AdjacencyListsGraph<V extends Vertex, E extends Edge<V>>
80 80
81 @Override 81 @Override
82 public boolean equals(Object obj) { 82 public boolean equals(Object obj) {
83 + if (this == obj) {
84 + return true;
85 + }
83 if (obj instanceof AdjacencyListsGraph) { 86 if (obj instanceof AdjacencyListsGraph) {
84 AdjacencyListsGraph that = (AdjacencyListsGraph) obj; 87 AdjacencyListsGraph that = (AdjacencyListsGraph) obj;
85 return this.getClass() == that.getClass() && 88 return this.getClass() == that.getClass() &&
......
...@@ -107,6 +107,9 @@ public class DefaultMutablePath<V extends Vertex, E extends Edge<V>> implements ...@@ -107,6 +107,9 @@ public class DefaultMutablePath<V extends Vertex, E extends Edge<V>> implements
107 107
108 @Override 108 @Override
109 public boolean equals(Object obj) { 109 public boolean equals(Object obj) {
110 + if (this == obj) {
111 + return true;
112 + }
110 if (obj instanceof DefaultMutablePath) { 113 if (obj instanceof DefaultMutablePath) {
111 final DefaultMutablePath other = (DefaultMutablePath) obj; 114 final DefaultMutablePath other = (DefaultMutablePath) obj;
112 return Objects.equals(this.cost, other.cost) && 115 return Objects.equals(this.cost, other.cost) &&
......
...@@ -72,6 +72,9 @@ public class DefaultPath<V extends Vertex, E extends Edge<V>> implements Path<V, ...@@ -72,6 +72,9 @@ public class DefaultPath<V extends Vertex, E extends Edge<V>> implements Path<V,
72 72
73 @Override 73 @Override
74 public boolean equals(Object obj) { 74 public boolean equals(Object obj) {
75 + if (this == obj) {
76 + return true;
77 + }
75 if (obj instanceof DefaultPath) { 78 if (obj instanceof DefaultPath) {
76 final DefaultPath other = (DefaultPath) obj; 79 final DefaultPath other = (DefaultPath) obj;
77 return Objects.equals(this.src, other.src) && 80 return Objects.equals(this.src, other.src) &&
......
...@@ -166,6 +166,9 @@ public class Heap<T> { ...@@ -166,6 +166,9 @@ public class Heap<T> {
166 166
167 @Override 167 @Override
168 public boolean equals(Object obj) { 168 public boolean equals(Object obj) {
169 + if (this == obj) {
170 + return true;
171 + }
169 if (obj instanceof Heap) { 172 if (obj instanceof Heap) {
170 Heap that = (Heap) obj; 173 Heap that = (Heap) obj;
171 return this.getClass() == that.getClass() && 174 return this.getClass() == that.getClass() &&
......
...@@ -39,6 +39,9 @@ public class TestEdge extends AbstractEdge<TestVertex> { ...@@ -39,6 +39,9 @@ public class TestEdge extends AbstractEdge<TestVertex> {
39 39
40 @Override 40 @Override
41 public boolean equals(Object obj) { 41 public boolean equals(Object obj) {
42 + if (this == obj) {
43 + return true;
44 + }
42 if (obj instanceof TestEdge) { 45 if (obj instanceof TestEdge) {
43 final TestEdge other = (TestEdge) obj; 46 final TestEdge other = (TestEdge) obj;
44 return super.equals(obj) && Objects.equals(this.weight, other.weight); 47 return super.equals(obj) && Objects.equals(this.weight, other.weight);
......
...@@ -20,6 +20,9 @@ public class TestVertex implements Vertex { ...@@ -20,6 +20,9 @@ public class TestVertex implements Vertex {
20 20
21 @Override 21 @Override
22 public boolean equals(Object obj) { 22 public boolean equals(Object obj) {
23 + if (this == obj) {
24 + return true;
25 + }
23 if (obj instanceof TestVertex) { 26 if (obj instanceof TestVertex) {
24 final TestVertex other = (TestVertex) obj; 27 final TestVertex other = (TestVertex) obj;
25 return Objects.equals(this.name, other.name); 28 return Objects.equals(this.name, other.name);
......