Source:
private synchronized StreamObserver<CommandProviderOutbound> getSubscriberObserver(String context) { if (subscriberStreamObserver != null) { return subscriberStreamObserver; } StreamObserver<CommandProviderInbound> commandsFromRoutingServer = new UpstreamAwareStreamObserver<CommandProviderInbound>() { @Override public void onNext(CommandProviderInbound commandToSubscriber) { logger.debug("Received command from server: {}", commandToSubscriber); switch (commandToSubscriber.getRequestCase()) { case COMMAND: commandExecutor.execute(new CommandProcessingTask(commandToSubscriber.getCommand())); sendSuccessfulInstructionResult(commandToSubscriber.getInstructionId(), requestStreamFactory.apply(this)); break; case CONFIRMATION: logger.trace("Received command confirmation: {}.", commandToSubscriber.getConfirmation()); break; default: sendUnsuccessfulInstructionResult(commandToSubscriber.getInstructionId(), unsupportedInstruction(), requestStreamFactory.apply(this)); break; } } @SuppressWarnings("Duplicates") @Override public void onError(Throwable ex) { logger.warn("Command Inbound Stream closed with error", ex); subscriberStreamObserver = null; } @Override public void onCompleted() { logger.info("Received completed from server."); subscriberStreamObserver = null; } }; ResubscribableStreamObserver<CommandProviderInbound> resubscribableStreamObserver = new ResubscribableStreamObserver<>(commandsFromRoutingServer, t -> resubscribe()); StreamObserver<CommandProviderOutbound> streamObserver = axonServerConnectionManager.getCommandStream(context, resubscribableStreamObserver); logger.info("Creating new command stream subscriber"); subscriberStreamObserver = new FlowControllingStreamObserver<>( streamObserver, configuration, flowControl -> CommandProviderOutbound.newBuilder().setFlowControl(flowControl).build(), t -> t.getRequestCase().equals(CommandProviderOutbound.RequestCase.COMMAND_RESPONSE) ).sendInitialPermits(); return subscriberStreamObserver; }

Target:
private synchronized StreamObserver<CommandProviderOutbound> getSubscriberObserver(String context) { if (subscriberStreamObserver != null) { return subscriberStreamObserver; } StreamObserver<CommandProviderInbound> commandsFromRoutingServer = new UpstreamAwareStreamObserver<CommandProviderInbound>() { @Override public void onNext(CommandProviderInbound commandToSubscriber) { logger.debug("Received command from server: {}", commandToSubscriber); CommandProviderInbound.RequestCase requestCase = commandToSubscriber.getRequestCase(); Collection<BiConsumer<CommandProviderInbound, StreamObserver<CommandProviderOutbound>>> defaultHandlers = Collections .singleton((cpi, stream) -> instructionAckSource .sendUnsupportedInstruction(cpi.getInstructionId(), configuration.getClientId(), requestStreamFactory.apply(this))); commandHandlers.getOrDefault(configuration.getContext(), requestCase, defaultHandlers) .forEach(handler -> handler.accept(commandToSubscriber, requestStreamFactory.apply(this))); } @SuppressWarnings("Duplicates") @Override public void onError(Throwable ex) { logger.warn("Command Inbound Stream closed with error", ex); subscriberStreamObserver = null; } @Override public void onCompleted() { logger.info("Received completed from server."); subscriberStreamObserver = null; } }; ResubscribableStreamObserver<CommandProviderInbound> resubscribableStreamObserver = new ResubscribableStreamObserver<>(commandsFromRoutingServer, t -> resubscribe()); StreamObserver<CommandProviderOutbound> streamObserver = axonServerConnectionManager.getCommandStream(context, resubscribableStreamObserver); logger.info("Creating new command stream subscriber"); subscriberStreamObserver = new FlowControllingStreamObserver<>( streamObserver, configuration, flowControl -> CommandProviderOutbound.newBuilder().setFlowControl(flowControl).build(), t -> t.getRequestCase().equals(CommandProviderOutbound.RequestCase.COMMAND_RESPONSE) ).sendInitialPermits(); return subscriberStreamObserver; }