Move {push|pop}DisableSleep to beforeCommand/afterCommand instead of registering for the event bus.
Follow up on
RELNOTES: None
package com.google.devtools.build.lib.platform;
import com.google.common.annotations.VisibleForTesting;
-import com.google.common.eventbus.Subscribe;
-import com.google.devtools.build.lib.buildtool.buildevent.BuildCompleteEvent;
-import com.google.devtools.build.lib.buildtool.buildevent.BuildStartingEvent;
import com.google.devtools.build.lib.runtime.BlazeModule;
import com.google.devtools.build.lib.runtime.CommandEnvironment;
import com.google.devtools.build.lib.util.AbruptExitException;
@@ -46,21 +43,23 @@ public final class SleepPreventionModule extends BlazeModule {
public static native int popDisableSleep();
}
- @Override
- public void beforeCommand(CommandEnvironment env) throws AbruptExitException {
- // Only register this component if JNI is available.
- if (!"0".equals(System.getProperty("io.bazel.EnableJni"))) {
- env.getEventBus().register(this);
- }
+ private final Boolean jniEnabled;
+
+ public SleepPreventionModule() {
+ this.jniEnabled = !"0".equals(System.getProperty("io.bazel.EnableJni"));
}
- @Subscribe
- public void buildStarting(BuildStartingEvent event) {
+ @Override
+ public void beforeCommand(CommandEnvironment env) throws AbruptExitException {
+ if (jniEnabled) {
SleepPrevention.pushDisableSleep();
}
+ }
- @Subscribe
- public void buildComplete(BuildCompleteEvent event) {
+ @Override
+ public void afterCommand() throws AbruptExitException {
+ if (jniEnabled) {
SleepPrevention.popDisableSleep();
}
}
+}
