Move Reporter out of the BuildEventStreamer.
The Reporter is a general-purpose object for communicating events to the user.
When an event is sent (with Reporter#post or Reporter#handle) using the Reporter
then those events are forwarded to the set of registered handlers (for #handle)
and to the event bus/extended handlers for #post. BuildEventStreamer responsibility
is to send BuildEvents to all active transports, it shouldn't
be on the business of sending UI messages (via #handle) or posting to the
event bus (via #post).
With this CL the messages that were sent inside the BuildEventStreamer
are now sent in the BuildEventServiceModule allowing us to manage all the UI
messages from there instead of scattered around the BES/BEP transports code.
From the UI perspective, the ExperimentalStateTracker uses
AnnounceBuildEventTransportsEvent and BuildEventTransportClosedEvent to decide
whether to print information about the BES upload. We now send those events
in the BES module.
In summary, there are a few concrete improvements with this CL:
- The waiting messages are solely the responsibility of the experimental UI.
- The logic for closing the BEP transports in the streamer is simplified.
- The streamer doesn't report arbitrary events to the event handlers or the event bus.
PiperOrigin-RevId: 239613756
diff --git a/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java b/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java
index fef7e48..78490ee 100644
--- a/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java
@@ -95,8 +95,7 @@
artifactGroupNamer = new CountingArtifactGroupNamer();
transport = new RecordingBuildEventTransport(artifactGroupNamer);
streamer =
- new BuildEventStreamer(
- ImmutableSet.<BuildEventTransport>of(transport), reporter, artifactGroupNamer);
+ new BuildEventStreamer(ImmutableSet.<BuildEventTransport>of(transport), artifactGroupNamer);
}
@After
@@ -333,6 +332,8 @@
eventBus.register(handler);
assertThat(handler.transportSet).isNull();
+ eventBus.post(new AnnounceBuildEventTransportsEvent(ImmutableSet.of(transport)));
+
BuildEvent startEvent =
new GenericBuildEvent(
testId("Initial"), ImmutableSet.of(ProgressEvent.INITIAL_PROGRESS_UPDATE,
@@ -349,6 +350,8 @@
streamer.buildEvent(new BuildCompleteEvent(new BuildResult(0)));
assertThat(streamer.isClosed()).isTrue();
+ eventBus.post(new BuildEventTransportClosedEvent(transport));
+
List<BuildEvent> finalStream = transport.getEvents();
assertThat(finalStream).hasSize(3);
assertThat(ImmutableSet.of(finalStream.get(1).getEventId(), finalStream.get(2).getEventId()))
@@ -1031,7 +1034,6 @@
new BuildEventStreamer.Builder()
.artifactGroupNamer(artifactGroupNamer)
.besStreamOptions(options)
- .cmdLineReporter(reporter)
.buildEventTransports(ImmutableSet.of(transport))
.build();