Source:
<code>public TrackingEventStream openStream(TrackingToken trackingToken) { Assert.isTrue(trackingToken == null || trackingToken instanceof GlobalSequenceTrackingToken, () -> "Invalid tracking token type. Must be GlobalSequenceTrackingToken."); long nextToken = trackingToken == null ? 0 : ((GlobalSequenceTrackingToken) trackingToken).getGlobalIndex() + 1; EventBuffer consumer = new EventBuffer(upcasterChain, getEventSerializer()); logger.info("open stream: {}", nextToken); StreamObserver<GetEventsRequest> requestStream = eventStoreClient .listEvents(new StreamObserver<EventWithToken>() { @Override public void onNext(EventWithToken eventWithToken) { logger.debug("Received event with token: {}", eventWithToken.getToken()); consumer.push(eventWithToken); } @Override public void onError(Throwable throwable) { consumer.fail(new EventStoreException( "Error while reading events from the server", throwable )); } @Override public void onCompleted() { consumer.fail(new EventStoreException("Error while reading events from the server", new RuntimeException("Connection closed by server"))); } }); FlowControllingStreamObserver<GetEventsRequest> observer = new FlowControllingStreamObserver<>( requestStream, configuration, t -> GetEventsRequest.newBuilder().setNumberOfPermits(t.getPermits()).build(), t -> false ); GetEventsRequest request = GetEventsRequest.newBuilder() .setTrackingToken(nextToken) .setClientId(configuration.getClientId()) .setComponentName(configuration.getComponentName()) .setNumberOfPermits(configuration.getInitialNrOfPermits()) .build(); observer.onNext(request); consumer.registerCloseListener((eventConsumer) -> observer.onCompleted()); consumer.registerConsumeListener(observer::markConsumed); <START> if( configuration.isBlacklistingEnabled()) { <END> Set<PayloadDescription> blacklisted = new CopyOnWriteArraySet<>(); consumer.registerBlacklistListener(type -> { PayloadDescription payloadType = PayloadDescription.newBuilder() .setRevision(getOrDefault(type.getRevision(), "")) .setType(type.getName()) .build(); if (blacklisted.add(payloadType)) { observer.onNext(GetEventsRequest.newBuilder() .addBlacklist(payloadType).build()); } }); } return consumer; }</code><technical_language>Nit: style guide ensure correct spacing if (</technical_language>

Target:
public TrackingEventStream openStream(TrackingToken trackingToken) { Assert.isTrue(trackingToken == null || trackingToken instanceof GlobalSequenceTrackingToken, () -> "Invalid tracking token type. Must be GlobalSequenceTrackingToken."); long nextToken = trackingToken == null ? 0 : ((GlobalSequenceTrackingToken) trackingToken).getGlobalIndex() + 1; EventBuffer consumer = new EventBuffer(upcasterChain, getEventSerializer()); logger.info("open stream: {}", nextToken); StreamObserver<GetEventsRequest> requestStream = eventStoreClient .listEvents(context, new StreamObserver<EventWithToken>() { @Override public void onNext(EventWithToken eventWithToken) { logger.debug("Received event with token: {}", eventWithToken.getToken()); consumer.push(eventWithToken); } @Override public void onError(Throwable throwable) { consumer.fail(new EventStoreException( "Error while reading events from the server", throwable )); } @Override public void onCompleted() { consumer.fail(new EventStoreException("Error while reading events from the server", new RuntimeException("Connection closed by server"))); } }); FlowControllingStreamObserver<GetEventsRequest> observer = new FlowControllingStreamObserver<>( requestStream, configuration, t -> GetEventsRequest.newBuilder().setNumberOfPermits(t.getPermits()).build(), t -> false ); GetEventsRequest request = GetEventsRequest.newBuilder() .setTrackingToken(nextToken) .setClientId(configuration.getClientId()) .setComponentName(configuration.getComponentName()) .setNumberOfPermits(configuration.getInitialNrOfPermits()) .build(); observer.onNext(request); consumer.registerCloseListener((eventConsumer) -> observer.onCompleted()); consumer.registerConsumeListener(observer::markConsumed); if (!configuration.isDisableEventBlacklisting()) { Set<PayloadDescription> blacklisted = new CopyOnWriteArraySet<>(); consumer.registerBlacklistListener(type -> { PayloadDescription payloadType = PayloadDescription.newBuilder() .setRevision(getOrDefault(type.getRevision(), "")) .setType(type.getName()) .build(); if (blacklisted.add(payloadType)) { observer.onNext(GetEventsRequest.newBuilder() .addBlacklist(payloadType) .build()); } }); } return consumer; }