- final ListenableFuture<RpcResult<SetRoleOutput>> changeRoleFuture = tryToChangeRole(input.getControllerRole());
- Futures.addCallback(changeRoleFuture, new FutureCallback<RpcResult<SetRoleOutput>>() {
-
- @Override
- public void onSuccess(final RpcResult<SetRoleOutput> result) {
- if (result.isSuccessful()) {
- LOG.debug("setRoleOutput received after roleChangeTask execution:{}", result);
- future.set(RpcResultBuilder.<SetRoleOutput> success().withResult(result.getResult()).build());
- } else {
- final boolean present = result
- .getErrors()
- .stream()
- .anyMatch(rpcError -> (rpcError.getMessage().contains(ROLE_REQUEST_UNSUPPORTED)));
-
- if (!present) {
- LOG.warn("setRole() failed with errors, will retry: {} times.", MAX_RETRIES - retryCounter);
- repeaterForChangeRole(future, input, (retryCounter + 1));
- } else {
- LOG.warn("setRole() failed with error - role request unsupported.");
- future.set(result);
- }
- }
- }
-
- @Override
- public void onFailure(final Throwable t) {
- if (!t.getMessage().contains(ROLE_REQUEST_UNSUPPORTED)) {
- LOG.warn("Exception in setRole(), will retry: {} times.", t, MAX_RETRIES - retryCounter);
- repeaterForChangeRole(future, input, (retryCounter + 1));
- } else {
- LOG.warn("Exception in setRole() - role request unsupported.", t);
- future.set(RpcResultBuilder.<SetRoleOutput>failed()
- .withError(RpcError.ErrorType.APPLICATION, t.getMessage()).build());
- }
- }
- });