diff options
author | 2017-04-06 18:54:22 +0000 | |
---|---|---|
committer | 2017-04-07 11:17:34 +0200 | |
commit | 0b937434094c38333fad07ec603d269f5b750c30 (patch) | |
tree | 9864d657078fbd34b0d1a4e03deb8861dd2cd45a /src/main/java/com/google/devtools/build/lib/runtime | |
parent | ed959e2a460e23cb253ce0c5c758e91e0f12e7bd (diff) |
BEP: Improve the BuildEventTransport interface.
Better specify the BuildEventTransport interface. Besides clarifying threading
and blocking issues, this change also clarifies error handling/reporting.
After several discussions we concluded that the BuildEventTransport interface
should not provide error reporting / handling facilities, as there is not much
bazel could do with this information. Instead, a transport may decide for
itself if an error is fatal and abort the build or if an error should be logged
to the user's terminal or if it should be ignored.
Furthermore, changing the close() method lays the groundwork for an upcoming
change that will report the transport shutdown status to the user command
line.
PiperOrigin-RevId: 152408938
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/runtime')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java b/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java index 9901ceeb49..697cd155a2 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java @@ -34,14 +34,17 @@ import com.google.devtools.build.lib.buildtool.buildevent.BuildInterruptedEvent; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.EventHandler; import com.google.devtools.build.lib.rules.extra.ExtraAction; -import java.io.IOException; +import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; +import java.util.List; import java.util.Set; +import java.util.concurrent.Future; import java.util.logging.Logger; /** Listen for {@link BuildEvent} and stream them to the provided {@link BuildEventTransport}. */ public class BuildEventStreamer implements EventHandler { + private final Collection<BuildEventTransport> transports; private Set<BuildEventId> announcedEvents; private final Set<BuildEventId> postedEvents = new HashSet<>(); @@ -89,15 +92,10 @@ public class BuildEventStreamer implements EventHandler { } for (BuildEventTransport transport : transports) { - try { - if (linkEvent != null) { - transport.sendBuildEvent(linkEvent); - } - transport.sendBuildEvent(event); - } catch (IOException e) { - // TODO(aehlig): signal that the build ought to be aborted - log.severe("Failed to write to build event transport: " + e); + if (linkEvent != null) { + transport.sendBuildEvent(linkEvent); } + transport.sendBuildEvent(event); } } @@ -128,12 +126,18 @@ public class BuildEventStreamer implements EventHandler { } private void close() { + List<Future<Void>> shutdownFutures = new ArrayList<>(transports.size()); + for (BuildEventTransport transport : transports) { + shutdownFutures.add(transport.close()); + } + + // Wait for all transports to close. + for (Future<Void> f : shutdownFutures) { try { - transport.close(); - } catch (IOException e) { - // TODO(aehlig): signal that the build ought to be aborted - log.warning("Failure while closing build event transport: " + e); + f.get(); + } catch (Exception e) { + log.severe("Failed to close a build event transport: " + e); } } } |