Source:
public RemoteExecutor getExecutor(final NodeId nodeId) throws CoordinatorException { final Pair<NodeContext, Set<CommandExecutor<?, ?>>> nodePair = nodes.get(nodeId); if (nodePair == null) { throw new CoordinatorException("Node " + nodeId.getIdentifier() + " hasn't registered"); } return new AbstractRemoteExecutor() { @Override public <C extends Command<R>, R extends Serializable> void run(final C command, final NodeCommandExecutionListener<C> listener, final AsyncCallback<R> callback) { final NodeContext nodeContext = nodePair.getFirst(); executorService.execute(new Runnable() { @Override public void run() { listener.onCommandExecutionStarted(command, nodeContext); try { R execute = getCommandExecutor(command).execute(command, nodeContext); listener.onCommandExecuted(command); callback.onSuccess(execute); } catch (Throwable throwable) { log.error("Error during command execution!", throwable); callback.onFailure(throwable); } } }); return; } @Override public <C extends Command<R>, R extends Serializable> Future<R> run(final C command, final NodeCommandExecutionListener<C> listener) { final NodeContext nodeContext = nodePair.getFirst(); return executorService.submit(new Callable<R>() { @Override public R call() { listener.onCommandExecutionStarted(command, nodeContext); try { R execute = getCommandExecutor(command).execute(command, nodeContext); listener.onCommandExecuted(command); return execute; } catch (Throwable throwable) { throw Throwables.propagate(throwable); } } }); } private <C extends Command<R>, R extends Serializable> CommandExecutor<C, R> getCommandExecutor(C command){ for (CommandExecutor<?, ?> commandExecutor : nodePair.getSecond()) { final CommandExecutor<C, R> executor = (CommandExecutor<C, R>) commandExecutor; if (executor.getQualifier().equals(Qualifier.of(command))) { return executor; } } throw new CoordinatorException("Command " + command + " is not available on " + nodeId.getIdentifier()); } }; }

Target:
public RemoteExecutor getExecutor(final NodeId nodeId) throws CoordinatorException { final Pair<NodeContext, Set<CommandExecutor<?, ?>>> nodePair = nodes.get(nodeId); if (nodePair == null) { throw new CoordinatorException("Node " + nodeId.getIdentifier() + " hasn't registered"); } return new AbstractRemoteExecutor() { @Override public <C extends Command<R>, R extends Serializable> void run(final C command, final NodeCommandExecutionListener<C> listener, final AsyncCallback<R> callback) { final NodeContext nodeContext = nodePair.getFirst(); executorService.execute(new Runnable() { @Override public void run() { listener.onCommandExecutionStarted(command, nodeContext); try { R execute = getCommandExecutor(command).execute(command, nodeContext); listener.onCommandExecuted(command); callback.onSuccess(execute); } catch (Throwable throwable) { log.error("Error during command execution!", throwable); callback.onFailure(throwable); } } }); return; } @Override public <C extends Command<R>, R extends Serializable> Future<R> run(final C command, final NodeCommandExecutionListener<C> listener) { final NodeContext nodeContext = nodePair.getFirst(); return executorService.submit(new Callable<R>() { @Override public R call() { listener.onCommandExecutionStarted(command, nodeContext); R execute = getCommandExecutor(command).execute(command, nodeContext); listener.onCommandExecuted(command); return execute; } }); } private <C extends Command<R>, R extends Serializable> CommandExecutor<C, R> getCommandExecutor(C command){ for (CommandExecutor<?, ?> commandExecutor : nodePair.getSecond()) { final CommandExecutor<C, R> executor = (CommandExecutor<C, R>) commandExecutor; if (executor.getQualifier().equals(Qualifier.of(command))) { return executor; } } throw new CoordinatorException("Command " + command + " is not available on " + nodeId.getIdentifier()); } }; }