tom

Cleaned-up some names and added a missing sync-block

...@@ -13,7 +13,6 @@ import org.onlab.onos.net.provider.ProviderId; ...@@ -13,7 +13,6 @@ import org.onlab.onos.net.provider.ProviderId;
13 13
14 import java.util.ArrayList; 14 import java.util.ArrayList;
15 import java.util.Collections; 15 import java.util.Collections;
16 -import java.util.HashMap;
17 import java.util.HashSet; 16 import java.util.HashSet;
18 import java.util.List; 17 import java.util.List;
19 import java.util.Map; 18 import java.util.Map;
...@@ -32,8 +31,8 @@ import static org.onlab.onos.net.device.DeviceEvent.Type.DEVICE_REMOVED; ...@@ -32,8 +31,8 @@ import static org.onlab.onos.net.device.DeviceEvent.Type.DEVICE_REMOVED;
32 class SimpleDeviceStore { 31 class SimpleDeviceStore {
33 32
34 private final Map<DeviceId, DefaultDevice> devices = new ConcurrentHashMap<>(); 33 private final Map<DeviceId, DefaultDevice> devices = new ConcurrentHashMap<>();
35 - private final Set<DeviceId> available = new HashSet<>(); 34 + private final Map<DeviceId, MastershipRole> roles = new ConcurrentHashMap<>();
36 - private final Map<DeviceId, MastershipRole> roles = new HashMap<>(); 35 + private final Set<DeviceId> availableDevices = new HashSet<>();
37 36
38 /** 37 /**
39 * Returns an iterable collection of all devices known to the system. 38 * Returns an iterable collection of all devices known to the system.
...@@ -81,7 +80,7 @@ class SimpleDeviceStore { ...@@ -81,7 +80,7 @@ class SimpleDeviceStore {
81 desc.serialNumber()); 80 desc.serialNumber());
82 synchronized (this) { 81 synchronized (this) {
83 devices.put(deviceId, device); 82 devices.put(deviceId, device);
84 - available.add(deviceId); 83 + availableDevices.add(deviceId);
85 } 84 }
86 return new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, device); 85 return new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, device);
87 } 86 }
...@@ -100,14 +99,14 @@ class SimpleDeviceStore { ...@@ -100,14 +99,14 @@ class SimpleDeviceStore {
100 desc.serialNumber()); 99 desc.serialNumber());
101 synchronized (this) { 100 synchronized (this) {
102 devices.put(device.id(), updated); 101 devices.put(device.id(), updated);
103 - available.add(device.id()); 102 + availableDevices.add(device.id());
104 } 103 }
105 return new DeviceEvent(DeviceEvent.Type.DEVICE_UPDATED, device); 104 return new DeviceEvent(DeviceEvent.Type.DEVICE_UPDATED, device);
106 } 105 }
107 106
108 // Otherwise merely attempt to change availability 107 // Otherwise merely attempt to change availability
109 synchronized (this) { 108 synchronized (this) {
110 - boolean added = available.add(device.id()); 109 + boolean added = availableDevices.add(device.id());
111 return added ? new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, device) : null; 110 return added ? new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, device) : null;
112 } 111 }
113 } 112 }
...@@ -122,7 +121,7 @@ class SimpleDeviceStore { ...@@ -122,7 +121,7 @@ class SimpleDeviceStore {
122 synchronized (this) { 121 synchronized (this) {
123 Device device = devices.get(deviceId); 122 Device device = devices.get(deviceId);
124 checkArgument(device != null, "Device with ID %s is not found", deviceId); 123 checkArgument(device != null, "Device with ID %s is not found", deviceId);
125 - boolean removed = available.remove(deviceId); 124 + boolean removed = availableDevices.remove(deviceId);
126 return removed ? new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, device) : null; 125 return removed ? new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, device) : null;
127 } 126 }
128 } 127 }
...@@ -193,10 +192,12 @@ class SimpleDeviceStore { ...@@ -193,10 +192,12 @@ class SimpleDeviceStore {
193 * @return mastership role change event or null if no change 192 * @return mastership role change event or null if no change
194 */ 193 */
195 DeviceEvent setRole(DeviceId deviceId, MastershipRole role) { 194 DeviceEvent setRole(DeviceId deviceId, MastershipRole role) {
196 - Device device = getDevice(deviceId); 195 + synchronized (this) {
197 - checkArgument(device != null, "Device with ID %s not found"); 196 + Device device = getDevice(deviceId);
198 - MastershipRole oldRole = roles.put(deviceId, role); 197 + checkArgument(device != null, "Device with ID %s not found");
199 - return oldRole == role ? null : new DeviceEvent(DEVICE_MASTERSHIP_CHANGED, device); 198 + MastershipRole oldRole = roles.put(deviceId, role);
199 + return oldRole == role ? null : new DeviceEvent(DEVICE_MASTERSHIP_CHANGED, device);
200 + }
200 } 201 }
201 202
202 /** 203 /**
......