- public ListenableFuture<Void> onRoleChanged(final OfpRole oldRole, final OfpRole newRole) {
- LOG.trace("onRoleChanged method call for Entity {}", entity);
-
- if (!isDeviceConnected()) {
- // this can happen as after the disconnect, we still get a last message from EntityOwnershipService.
- LOG.info("Device {} is disconnected from this node. Hence not attempting a role change.",
- deviceContext.getPrimaryConnectionContext().getNodeId());
- LOG.debug("SetRole cancelled for entity [{}], reason = device disconnected.", entity);
- return Futures.immediateFailedFuture(new Exception(
- "Device disconnected - stopped by setRole: " + deviceContext
- .getPrimaryConnectionContext().getNodeId()));
- }
-
- LOG.debug("Role change received from ownership listener from {} to {} for device:{}", oldRole, newRole,
- deviceContext.getPrimaryConnectionContext().getNodeId());
-
- final AsyncFunction<RpcResult<SetRoleOutput>, Void> roleChangeFunction = new AsyncFunction<RpcResult<SetRoleOutput>, Void>() {
- @Override
- public ListenableFuture<Void> apply(final RpcResult<SetRoleOutput> setRoleOutputRpcResult) throws Exception {
- LOG.debug("Role change {} successful made on switch :{}", newRole, deviceContext.getDeviceState()
- .getNodeId());
- getDeviceState().setRole(newRole);
- return deviceContext.onClusterRoleChange(oldRole, newRole);
- }
- };
- return sendRoleChangeToDevice(newRole, roleChangeFunction);