aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/runtime
diff options
context:
space:
mode:
authorGravatar Klaus Aehlig <aehlig@google.com>2016-07-08 14:26:14 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2016-07-11 09:39:09 +0000
commit0aec8b2e6d199112edfa09b3ef0cb1095437b02a (patch)
tree48f2f60eb278569a37f91d6e4c4af4e71c22a4ea /src/main/java/com/google/devtools/build/lib/runtime
parent916b23cd68caba94a8e3d0c5af026a750a42a626 (diff)
Add a final event on the event bus
Add an event to the event bus that is guaranteed to come after the completion of the command. Listeners can use this event to clean up any resources that still need to be cleaned up. As first customer, add the ExperimentalEventHandler so that it is guaranteed not to leak the update thread. -- Change-Id: Ia20bae8a00541aa1338e49f74a7320ac098ab71d Reviewed-on: https://bazel-review.googlesource.com/#/c/4011 MOS_MIGRATED_REVID=126909844
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/runtime')
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/AfterCommandEvent.java21
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java1
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/ExperimentalEventHandler.java6
3 files changed, 28 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/AfterCommandEvent.java b/src/main/java/com/google/devtools/build/lib/runtime/AfterCommandEvent.java
new file mode 100644
index 0000000000..0cc630211f
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/runtime/AfterCommandEvent.java
@@ -0,0 +1,21 @@
+// Copyright 2016 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.google.devtools.build.lib.runtime;
+
+/**
+ * An event that is guaranteed to be posted after every command, no matter what the command was and
+ * how it terminated. Listeneres on the event bus can use this event to do any final resource clean
+ * up.
+ */
+public class AfterCommandEvent {}
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java
index 48a4898545..ebb512df09 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java
@@ -501,6 +501,7 @@ public class BlazeCommandDispatcher {
: ExitCode.BLAZE_INTERNAL_ERROR.getNumericExitCode();
throw new ShutdownBlazeServerException(numericExitCode, ShutdownMethod.CLEAN, e);
} finally {
+ env.getEventBus().post(new AfterCommandEvent());
runtime.afterCommand(env, numericExitCode);
// Swallow IOException, as we are already in a finally clause
Flushables.flushQuietly(outErr.getOutputStream());
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/ExperimentalEventHandler.java b/src/main/java/com/google/devtools/build/lib/runtime/ExperimentalEventHandler.java
index fb0822acc7..dbc0dbffd5 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/ExperimentalEventHandler.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/ExperimentalEventHandler.java
@@ -334,6 +334,12 @@ public class ExperimentalEventHandler implements EventHandler {
}
@Subscribe
+ public synchronized void afterCommand(AfterCommandEvent event) {
+ buildComplete = true;
+ stopUpdateThread();
+ }
+
+ @Subscribe
public void actionStarted(ActionStartedEvent event) {
stateTracker.actionStarted(event);
refresh();