Skip to content

Commit

Permalink
Make AbstractBlazeQueryEnv closable, shutdown SkyQEnv executor on close
Browse files Browse the repository at this point in the history
Users of SkyQueryEnvironment ought to be able to shut down its executor
when they're finished with it.

RELNOTES: None.
PiperOrigin-RevId: 162262117
  • Loading branch information
anakanemison authored and damienmg committed Jul 18, 2017
1 parent 4da2f16 commit fe88387
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
* {@link QueryEnvironment} that can evaluate queries to produce a result, and implements as much of
* QueryEnvironment as possible while remaining mostly agnostic as to the objects being stored.
*/
public abstract class AbstractBlazeQueryEnvironment<T> extends AbstractQueryEnvironment<T> {
public abstract class AbstractBlazeQueryEnvironment<T> extends AbstractQueryEnvironment<T>
implements AutoCloseable {
protected ErrorSensingEventHandler eventHandler;
protected final boolean keepGoing;
protected final boolean strictScope;
Expand Down Expand Up @@ -78,6 +79,9 @@ protected AbstractBlazeQueryEnvironment(
this.extraFunctions = ImmutableList.copyOf(extraFunctions);
}

@Override
public abstract void close();

private static DependencyFilter constructDependencyFilter(
Set<Setting> settings) {
DependencyFilter specifiedFilter =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ public class BlazeQueryEnvironment extends AbstractBlazeQueryEnvironment<Target>
this.labelVisitor = new LabelVisitor(targetProvider, dependencyFilter);
}

@Override
public void close() {
// BlazeQueryEnvironment has no resources that need to be cleaned up.
}

@Override
public DigraphQueryEvalResult<Target> evaluateQuery(
QueryExpression expr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ protected SkyQueryEnvironment(
PrepareDepsOfPatternsFunction.getSkyKeys(universeKey, eventHandler));
}

@Override
public void close() {
if (executor != null) {
executor.shutdownNow();
executor = null;
}
}

private void beforeEvaluateQuery() throws InterruptedException {
if (graph == null || !graphFactory.isUpToDate(universeKey)) {
// If this environment is uninitialized or the graph factory needs to evaluate, do so. We
Expand Down

0 comments on commit fe88387

Please sign in to comment.