Source:
<code>RSocketServer( ByteBufAllocator allocator, DuplexConnection connection, RSocket requestHandler, PayloadDecoder payloadDecoder, Consumer<Throwable> errorConsumer, long tickPeriod, long ackTimeout) { this.allocator = allocator; this.connection = connection; this.requestHandler = requestHandler; this.responderRSocket = (requestHandler instanceof ResponderRSocket) ? (ResponderRSocket) requestHandler : null; this.payloadDecoder = payloadDecoder; this.errorConsumer = errorConsumer; this.sendingSubscriptions = Collections.synchronizedMap(new IntObjectHashMap<>()); this.channelProcessors = Collections.synchronizedMap(new IntObjectHashMap<>()); this.sendProcessor = new UnboundedProcessor<>(); connection .send( sendProcessor.doOnRequest( r -> <START> sendingSubscriptions.forEach( <END> (__, s) -> { if (s instanceof LimitableRequestPublisher) { LimitableRequestPublisher lrp = (LimitableRequestPublisher) s; lrp.increaseInternalLimit(r); } }))) .doFinally(this::handleSendProcessorCancel) .subscribe(null, this::handleSendProcessorError); Disposable receiveDisposable = connection.receive().subscribe(this::handleFrame, errorConsumer); this.connection .onClose() .doFinally( s -> { cleanup(); receiveDisposable.dispose(); }) .subscribe(null, errorConsumer); if (tickPeriod != 0) { keepAliveHandler = KeepAliveHandler.ofServer(new KeepAliveHandler.KeepAlive(tickPeriod, ackTimeout)); keepAliveHandler .timeout() .subscribe( keepAlive -> { String message = String.format("No keep-alive acks for %d ms", keepAlive.getTimeoutMillis()); errorConsumer.accept(new ConnectionErrorException(message)); connection.dispose(); }); keepAliveHandler.send().subscribe(sendProcessor::onNext); } else { keepAliveHandler = null; } }</code><technical_language>I avoid forEach in performance critical paths</technical_language>

Target:
RSocketServer( ByteBufAllocator allocator, DuplexConnection connection, RSocket requestHandler, PayloadDecoder payloadDecoder, Consumer<Throwable> errorConsumer, long tickPeriod, long ackTimeout) { this.allocator = allocator; this.connection = connection; this.requestHandler = requestHandler; this.responderRSocket = (requestHandler instanceof ResponderRSocket) ? (ResponderRSocket) requestHandler : null; this.payloadDecoder = payloadDecoder; this.errorConsumer = errorConsumer; this.sendingLimitableSubscriptions = Collections.synchronizedMap(new IntObjectHashMap<>()); this.sendingSubscriptions = Collections.synchronizedMap(new IntObjectHashMap<>()); this.channelProcessors = Collections.synchronizedMap(new IntObjectHashMap<>()); this.sendProcessor = new UnboundedProcessor<>(); connection .send( sendProcessor.doOnRequest( r -> { for (LimitableRequestPublisher lrp : sendingLimitableSubscriptions.values()) { lrp.increaseInternalLimit(r); } })) .doFinally(this::handleSendProcessorCancel) .subscribe(null, this::handleSendProcessorError); Disposable receiveDisposable = connection.receive().subscribe(this::handleFrame, errorConsumer); this.connection .onClose() .doFinally( s -> { cleanup(); receiveDisposable.dispose(); }) .subscribe(null, errorConsumer); if (tickPeriod != 0) { keepAliveHandler = KeepAliveHandler.ofServer(new KeepAliveHandler.KeepAlive(tickPeriod, ackTimeout)); keepAliveHandler .timeout() .subscribe( keepAlive -> { String message = String.format("No keep-alive acks for %d ms", keepAlive.getTimeoutMillis()); errorConsumer.accept(new ConnectionErrorException(message)); connection.dispose(); }); keepAliveHandler.send().subscribe(sendProcessor::onNext); } else { keepAliveHandler = null; } }