Committed by
Gerrit Code Review
Simplify method names by removing redundancy
Change-Id: I36df7e23792f7004dfae823a8700f6c887ea1efd
Showing
4 changed files
with
29 additions
and
29 deletions
| ... | @@ -32,8 +32,8 @@ public interface ResourceAdminService { | ... | @@ -32,8 +32,8 @@ public interface ResourceAdminService { |
| 32 | * @return true if registration is successfully done, false otherwise. Registration | 32 | * @return true if registration is successfully done, false otherwise. Registration |
| 33 | * succeeds when each resource is not registered or unallocated. | 33 | * succeeds when each resource is not registered or unallocated. |
| 34 | */ | 34 | */ |
| 35 | - default boolean registerResources(Resource... resources) { | 35 | + default boolean register(Resource... resources) { |
| 36 | - return registerResources(ImmutableList.copyOf(resources)); | 36 | + return register(ImmutableList.copyOf(resources)); |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | /** | 39 | /** |
| ... | @@ -43,7 +43,7 @@ public interface ResourceAdminService { | ... | @@ -43,7 +43,7 @@ public interface ResourceAdminService { |
| 43 | * @return true if registration is successfully done, false otherwise. Registration | 43 | * @return true if registration is successfully done, false otherwise. Registration |
| 44 | * succeeds when each resource is not registered or unallocated. | 44 | * succeeds when each resource is not registered or unallocated. |
| 45 | */ | 45 | */ |
| 46 | - boolean registerResources(List<Resource> resources); | 46 | + boolean register(List<Resource> resources); |
| 47 | 47 | ||
| 48 | /** | 48 | /** |
| 49 | * Unregisters the specified resources. | 49 | * Unregisters the specified resources. |
| ... | @@ -52,8 +52,8 @@ public interface ResourceAdminService { | ... | @@ -52,8 +52,8 @@ public interface ResourceAdminService { |
| 52 | * @return true if unregistration is successfully done, false otherwise. Unregistration | 52 | * @return true if unregistration is successfully done, false otherwise. Unregistration |
| 53 | * succeeds when each resource is not registered or unallocated. | 53 | * succeeds when each resource is not registered or unallocated. |
| 54 | */ | 54 | */ |
| 55 | - default boolean unregisterResources(ResourceId... ids) { | 55 | + default boolean unregister(ResourceId... ids) { |
| 56 | - return unregisterResources(ImmutableList.copyOf(ids)); | 56 | + return unregister(ImmutableList.copyOf(ids)); |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | /** | 59 | /** |
| ... | @@ -64,5 +64,5 @@ public interface ResourceAdminService { | ... | @@ -64,5 +64,5 @@ public interface ResourceAdminService { |
| 64 | * succeeds when each resource is not registered or unallocated. | 64 | * succeeds when each resource is not registered or unallocated. |
| 65 | */ | 65 | */ |
| 66 | // TODO: might need to change the first argument type to ResourceId | 66 | // TODO: might need to change the first argument type to ResourceId |
| 67 | - boolean unregisterResources(List<ResourceId> ids); | 67 | + boolean unregister(List<ResourceId> ids); |
| 68 | } | 68 | } | ... | ... |
| ... | @@ -127,25 +127,25 @@ final class ResourceDeviceListener implements DeviceListener { | ... | @@ -127,25 +127,25 @@ final class ResourceDeviceListener implements DeviceListener { |
| 127 | } | 127 | } |
| 128 | 128 | ||
| 129 | private void registerDeviceResource(Device device) { | 129 | private void registerDeviceResource(Device device) { |
| 130 | - executor.submit(() -> adminService.registerResources(Resources.discrete(device.id()).resource())); | 130 | + executor.submit(() -> adminService.register(Resources.discrete(device.id()).resource())); |
| 131 | } | 131 | } |
| 132 | 132 | ||
| 133 | private void unregisterDeviceResource(Device device) { | 133 | private void unregisterDeviceResource(Device device) { |
| 134 | executor.submit(() -> { | 134 | executor.submit(() -> { |
| 135 | DiscreteResource devResource = Resources.discrete(device.id()).resource(); | 135 | DiscreteResource devResource = Resources.discrete(device.id()).resource(); |
| 136 | List<Resource> allResources = getDescendantResources(devResource); | 136 | List<Resource> allResources = getDescendantResources(devResource); |
| 137 | - adminService.unregisterResources(Lists.transform(allResources, Resource::id)); | 137 | + adminService.unregister(Lists.transform(allResources, Resource::id)); |
| 138 | }); | 138 | }); |
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | private void registerPortResource(Device device, Port port) { | 141 | private void registerPortResource(Device device, Port port) { |
| 142 | Resource portPath = Resources.discrete(device.id(), port.number()).resource(); | 142 | Resource portPath = Resources.discrete(device.id(), port.number()).resource(); |
| 143 | executor.submit(() -> { | 143 | executor.submit(() -> { |
| 144 | - adminService.registerResources(portPath); | 144 | + adminService.register(portPath); |
| 145 | 145 | ||
| 146 | queryBandwidth(device.id(), port.number()) | 146 | queryBandwidth(device.id(), port.number()) |
| 147 | .map(bw -> portPath.child(Bandwidth.class, bw.bps())) | 147 | .map(bw -> portPath.child(Bandwidth.class, bw.bps())) |
| 148 | - .map(adminService::registerResources) | 148 | + .map(adminService::register) |
| 149 | .ifPresent(success -> { | 149 | .ifPresent(success -> { |
| 150 | if (!success) { | 150 | if (!success) { |
| 151 | log.error("Failed to register Bandwidth for {}", portPath.id()); | 151 | log.error("Failed to register Bandwidth for {}", portPath.id()); |
| ... | @@ -155,33 +155,33 @@ final class ResourceDeviceListener implements DeviceListener { | ... | @@ -155,33 +155,33 @@ final class ResourceDeviceListener implements DeviceListener { |
| 155 | // for VLAN IDs | 155 | // for VLAN IDs |
| 156 | Set<VlanId> vlans = queryVlanIds(device.id(), port.number()); | 156 | Set<VlanId> vlans = queryVlanIds(device.id(), port.number()); |
| 157 | if (!vlans.isEmpty()) { | 157 | if (!vlans.isEmpty()) { |
| 158 | - adminService.registerResources(vlans.stream() | 158 | + adminService.register(vlans.stream() |
| 159 | - .map(portPath::child) | 159 | + .map(portPath::child) |
| 160 | - .collect(Collectors.toList())); | 160 | + .collect(Collectors.toList())); |
| 161 | } | 161 | } |
| 162 | 162 | ||
| 163 | // for MPLS labels | 163 | // for MPLS labels |
| 164 | Set<MplsLabel> mplsLabels = queryMplsLabels(device.id(), port.number()); | 164 | Set<MplsLabel> mplsLabels = queryMplsLabels(device.id(), port.number()); |
| 165 | if (!mplsLabels.isEmpty()) { | 165 | if (!mplsLabels.isEmpty()) { |
| 166 | - adminService.registerResources(mplsLabels.stream() | 166 | + adminService.register(mplsLabels.stream() |
| 167 | - .map(portPath::child) | 167 | + .map(portPath::child) |
| 168 | - .collect(Collectors.toList())); | 168 | + .collect(Collectors.toList())); |
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | // for Lambdas | 171 | // for Lambdas |
| 172 | Set<OchSignal> lambdas = queryLambdas(device.id(), port.number()); | 172 | Set<OchSignal> lambdas = queryLambdas(device.id(), port.number()); |
| 173 | if (!lambdas.isEmpty()) { | 173 | if (!lambdas.isEmpty()) { |
| 174 | - adminService.registerResources(lambdas.stream() | 174 | + adminService.register(lambdas.stream() |
| 175 | - .map(portPath::child) | 175 | + .map(portPath::child) |
| 176 | - .collect(Collectors.toList())); | 176 | + .collect(Collectors.toList())); |
| 177 | } | 177 | } |
| 178 | 178 | ||
| 179 | // for Tributary slots | 179 | // for Tributary slots |
| 180 | Set<TributarySlot> tSlots = queryTributarySlots(device.id(), port.number()); | 180 | Set<TributarySlot> tSlots = queryTributarySlots(device.id(), port.number()); |
| 181 | if (!tSlots.isEmpty()) { | 181 | if (!tSlots.isEmpty()) { |
| 182 | - adminService.registerResources(tSlots.stream() | 182 | + adminService.register(tSlots.stream() |
| 183 | - .map(portPath::child) | 183 | + .map(portPath::child) |
| 184 | - .collect(Collectors.toList())); | 184 | + .collect(Collectors.toList())); |
| 185 | } | 185 | } |
| 186 | }); | 186 | }); |
| 187 | } | 187 | } |
| ... | @@ -190,7 +190,7 @@ final class ResourceDeviceListener implements DeviceListener { | ... | @@ -190,7 +190,7 @@ final class ResourceDeviceListener implements DeviceListener { |
| 190 | executor.submit(() -> { | 190 | executor.submit(() -> { |
| 191 | DiscreteResource portResource = Resources.discrete(device.id(), port.number()).resource(); | 191 | DiscreteResource portResource = Resources.discrete(device.id(), port.number()).resource(); |
| 192 | List<Resource> allResources = getDescendantResources(portResource); | 192 | List<Resource> allResources = getDescendantResources(portResource); |
| 193 | - adminService.unregisterResources(Lists.transform(allResources, Resource::id)); | 193 | + adminService.unregister(Lists.transform(allResources, Resource::id)); |
| 194 | }); | 194 | }); |
| 195 | } | 195 | } |
| 196 | 196 | ... | ... |
| ... | @@ -171,14 +171,14 @@ public final class ResourceManager extends AbstractListenerManager<ResourceEvent | ... | @@ -171,14 +171,14 @@ public final class ResourceManager extends AbstractListenerManager<ResourceEvent |
| 171 | } | 171 | } |
| 172 | 172 | ||
| 173 | @Override | 173 | @Override |
| 174 | - public boolean registerResources(List<Resource> resources) { | 174 | + public boolean register(List<Resource> resources) { |
| 175 | checkNotNull(resources); | 175 | checkNotNull(resources); |
| 176 | 176 | ||
| 177 | return store.register(resources); | 177 | return store.register(resources); |
| 178 | } | 178 | } |
| 179 | 179 | ||
| 180 | @Override | 180 | @Override |
| 181 | - public boolean unregisterResources(List<ResourceId> ids) { | 181 | + public boolean unregister(List<ResourceId> ids) { |
| 182 | checkNotNull(ids); | 182 | checkNotNull(ids); |
| 183 | 183 | ||
| 184 | return store.unregister(ids); | 184 | return store.unregister(ids); | ... | ... |
| ... | @@ -93,7 +93,7 @@ final class ResourceNetworkConfigListener implements NetworkConfigListener { | ... | @@ -93,7 +93,7 @@ final class ResourceNetworkConfigListener implements NetworkConfigListener { |
| 93 | 93 | ||
| 94 | switch (event.type()) { | 94 | switch (event.type()) { |
| 95 | case CONFIG_ADDED: | 95 | case CONFIG_ADDED: |
| 96 | - if (!adminService.registerResources(Resources.continuous(cp.deviceId(), | 96 | + if (!adminService.register(Resources.continuous(cp.deviceId(), |
| 97 | cp.port(), Bandwidth.class) | 97 | cp.port(), Bandwidth.class) |
| 98 | .resource(bwCapacity.capacity().bps()))) { | 98 | .resource(bwCapacity.capacity().bps()))) { |
| 99 | log.info("Failed to register Bandwidth for {}, attempting update", cp); | 99 | log.info("Failed to register Bandwidth for {}, attempting update", cp); |
| ... | @@ -115,7 +115,7 @@ final class ResourceNetworkConfigListener implements NetworkConfigListener { | ... | @@ -115,7 +115,7 @@ final class ResourceNetworkConfigListener implements NetworkConfigListener { |
| 115 | 115 | ||
| 116 | case CONFIG_REMOVED: | 116 | case CONFIG_REMOVED: |
| 117 | // FIXME Following should be an update to the value based on port speed | 117 | // FIXME Following should be an update to the value based on port speed |
| 118 | - if (!adminService.unregisterResources(Resources.continuous(cp.deviceId(), | 118 | + if (!adminService.unregister(Resources.continuous(cp.deviceId(), |
| 119 | cp.port(), | 119 | cp.port(), |
| 120 | Bandwidth.class).id())) { | 120 | Bandwidth.class).id())) { |
| 121 | log.warn("Failed to unregister Bandwidth for {}", cp); | 121 | log.warn("Failed to unregister Bandwidth for {}", cp); |
| ... | @@ -147,11 +147,11 @@ final class ResourceNetworkConfigListener implements NetworkConfigListener { | ... | @@ -147,11 +147,11 @@ final class ResourceNetworkConfigListener implements NetworkConfigListener { |
| 147 | // but both unregisterResources(..) and registerResources(..) | 147 | // but both unregisterResources(..) and registerResources(..) |
| 148 | // returns true (success) | 148 | // returns true (success) |
| 149 | 149 | ||
| 150 | - if (!adminService.unregisterResources( | 150 | + if (!adminService.unregister( |
| 151 | Resources.continuous(cp.deviceId(), cp.port(), Bandwidth.class).id())) { | 151 | Resources.continuous(cp.deviceId(), cp.port(), Bandwidth.class).id())) { |
| 152 | log.warn("unregisterResources for {} failed", cp); | 152 | log.warn("unregisterResources for {} failed", cp); |
| 153 | } | 153 | } |
| 154 | - return adminService.registerResources(Resources.continuous(cp.deviceId(), | 154 | + return adminService.register(Resources.continuous(cp.deviceId(), |
| 155 | cp.port(), | 155 | cp.port(), |
| 156 | Bandwidth.class).resource(bwCapacity.capacity().bps())); | 156 | Bandwidth.class).resource(bwCapacity.capacity().bps())); |
| 157 | } | 157 | } | ... | ... |
-
Please register or login to post a comment