Source:
<code>public synchronized Channel getChannel() { checkConnectionState(); if( channel == null || channel.isShutdown()) { channel = null; logger.info("Connecting using {}...", connectInformation.isSslEnabled()?"TLS":"unencrypted connection"); boolean unavailable = false; for(NodeInfo nodeInfo : connectInformation.routingServers()) { ManagedChannel candidate = createChannel( nodeInfo.getHostName(), nodeInfo.getGrpcPort()); PlatformServiceGrpc.PlatformServiceBlockingStub stub = PlatformServiceGrpc.newBlockingStub(candidate) .withInterceptors(new ContextAddingInterceptor(connectInformation.getContext()), new TokenAddingInterceptor(connectInformation.getToken())); try { PlatformInfo clusterInfo = stub.getPlatformServer(ClientIdentification.newBuilder() .setClientId(connectInformation.getClientId()) .setComponentName(connectInformation.getComponentName()) .build()); if(isPrimary(nodeInfo, clusterInfo)) { channel = candidate; } else { shutdown(candidate); logger.info("Connecting to ({}:{})", clusterInfo.getPrimary().getNodeName(), clusterInfo.getPrimary().getHostName(), clusterInfo.getPrimary().getGrpcPort()); channel = createChannel(clusterInfo.getPrimary().getHostName(), clusterInfo.getPrimary().getGrpcPort()); } startInstructionStream(clusterInfo.getPrimary().getNodeName()); unavailable = false; logger.info("Re-subscribing commands and queries"); <START> scheduler.schedule(() -> reconnectListeners.forEach(Runnable::run), 100, TimeUnit.MILLISECONDS); <END> break; } catch( StatusRuntimeException sre) { shutdown(candidate); logger.warn("Connecting to AxonServer node {}:{} failed: {}", nodeInfo.getHostName(), nodeInfo.getGrpcPort(), sre.getMessage()); if( sre.getStatus().getCode().equals(Status.Code.UNAVAILABLE)) { unavailable = true; } } } if( unavailable) { if(!connectInformation.getSuppressDownloadMessage()) { connectInformation.setSuppressDownloadMessage(true); writeDownloadMessage(); } scheduleReconnect(false); throw new AxonServerException(ErrorCode.CONNECTION_FAILED.errorCode(), "No connection to AxonServer available"); } else if (!connectInformation.getSuppressDownloadMessage()) { connectInformation.setSuppressDownloadMessage(true); } } return channel; }</code><technical_language>a scheduler, schedule Runnable scheduled task? This reduces risk of tasks executed another throws exception</technical_language>

Target:
public synchronized Channel getChannel() { checkConnectionState(); if( channel == null || channel.isShutdown()) { channel = null; logger.info("Connecting using {}...", connectInformation.isSslEnabled()?"TLS":"unencrypted connection"); boolean unavailable = false; for(NodeInfo nodeInfo : connectInformation.routingServers()) { ManagedChannel candidate = createChannel( nodeInfo.getHostName(), nodeInfo.getGrpcPort()); PlatformServiceGrpc.PlatformServiceBlockingStub stub = PlatformServiceGrpc.newBlockingStub(candidate) .withInterceptors(new ContextAddingInterceptor(connectInformation.getContext()), new TokenAddingInterceptor(connectInformation.getToken())); try { PlatformInfo clusterInfo = stub.getPlatformServer(ClientIdentification.newBuilder() .setClientId(connectInformation.getClientId()) .setComponentName(connectInformation.getComponentName()) .build()); if(isPrimary(nodeInfo, clusterInfo)) { channel = candidate; } else { shutdown(candidate); logger.info("Connecting to ({}:{})", clusterInfo.getPrimary().getNodeName(), clusterInfo.getPrimary().getHostName(), clusterInfo.getPrimary().getGrpcPort()); channel = createChannel(clusterInfo.getPrimary().getHostName(), clusterInfo.getPrimary().getGrpcPort()); } startInstructionStream(clusterInfo.getPrimary().getNodeName()); unavailable = false; logger.info("Re-subscribing commands and queries"); reconnectListeners.forEach(action -> scheduler.schedule(action::run, 100, TimeUnit.MILLISECONDS)); break; } catch( StatusRuntimeException sre) { shutdown(candidate); logger.warn("Connecting to AxonServer node {}:{} failed: {}", nodeInfo.getHostName(), nodeInfo.getGrpcPort(), sre.getMessage()); if( sre.getStatus().getCode().equals(Status.Code.UNAVAILABLE)) { unavailable = true; } } } if( unavailable) { if(!connectInformation.getSuppressDownloadMessage()) { connectInformation.setSuppressDownloadMessage(true); writeDownloadMessage(); } scheduleReconnect(false); throw new AxonServerException(ErrorCode.CONNECTION_FAILED.errorCode(), "No connection to AxonServer available"); } else if (!connectInformation.getSuppressDownloadMessage()) { connectInformation.setSuppressDownloadMessage(true); } } return channel; }