Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions runtime/src/main/java/dev/cel/runtime/async/AsyncProgramImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.google.common.util.concurrent.ListeningExecutorService;
import javax.annotation.concurrent.ThreadSafe;
import dev.cel.runtime.CelAttribute;
import dev.cel.runtime.CelAttributePattern;
import dev.cel.runtime.CelEvaluationException;
import dev.cel.runtime.CelRuntime.Program;
import dev.cel.runtime.CelUnknownSet;
Expand Down Expand Up @@ -60,17 +59,14 @@ final class AsyncProgramImpl implements CelAsyncRuntime.AsyncProgram {
private final UnknownContext startingUnknownContext;
private final Program program;
private final ListeningExecutorService executor;
private final ImmutableMap<CelAttributePattern, CelUnknownAttributeValueResolver> resolvers;

AsyncProgramImpl(
Program program,
ListeningExecutorService executor,
ImmutableMap<CelAttributePattern, CelUnknownAttributeValueResolver> resolvers,
int maxEvaluateIterations,
UnknownContext startingUnknownContext) {
this.program = program;
this.executor = executor;
this.resolvers = resolvers;
this.maxEvaluateIterations = maxEvaluateIterations;
// The following is populated from CelAsyncRuntime. The impl is immutable, thus safe to reuse as
// a starting context.
Expand All @@ -86,12 +82,6 @@ private Optional<CelUnknownAttributeValueResolver> lookupResolver(
}
}

for (Map.Entry<CelAttributePattern, CelUnknownAttributeValueResolver> entry :
resolvers.entrySet()) {
if (entry.getKey().isPartialMatch(attribute)) {
return Optional.of(entry.getValue());
}
}
return Optional.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
package dev.cel.runtime.async;

import com.google.errorprone.annotations.CanIgnoreReturnValue;
import dev.cel.runtime.CelAttributePattern;
import dev.cel.runtime.CelRuntime;
import dev.cel.runtime.async.CelAsyncRuntime.AsyncProgram;
import java.util.concurrent.ExecutorService;

/** Builder interface for {@link CelAsyncRuntime}. */
Expand All @@ -27,27 +25,6 @@ public interface CelAsyncRuntimeBuilder {
@CanIgnoreReturnValue
CelAsyncRuntimeBuilder setRuntime(CelRuntime runtime);

/**
* Add attributes that are declared as Unknown, without any resolver.
*
* @deprecated Use {@link AsyncProgram#evaluateToCompletion(CelResolvableAttributePattern...)}
* instead to propagate the unknown attributes along with the resolvers into the program.
*/
@CanIgnoreReturnValue
@Deprecated
CelAsyncRuntimeBuilder addUnknownAttributePatterns(CelAttributePattern... attributes);

/**
* Marks an attribute pattern as unknown and associates a resolver with it.
*
* @deprecated Use {@link AsyncProgram#evaluateToCompletion(CelResolvableAttributePattern...)}
* instead to propagate the unknown attributes along with the resolvers into the program.
*/
@CanIgnoreReturnValue
@Deprecated
CelAsyncRuntimeBuilder addResolvableAttributePattern(
CelAttributePattern attribute, CelUnknownAttributeValueResolver resolver);

/**
* Set the maximum number of allowed evaluation passes.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
package dev.cel.runtime.async;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import javax.annotation.concurrent.ThreadSafe;
import dev.cel.common.CelAbstractSyntaxTree;
import dev.cel.runtime.CelAttributePattern;
import dev.cel.runtime.CelEvaluationException;
import dev.cel.runtime.CelRuntime;
import dev.cel.runtime.CelRuntimeFactory;
Expand All @@ -32,39 +30,31 @@
/** Default {@link CelAsyncRuntime} runtime implementation. See {@link AsyncProgramImpl}. */
@ThreadSafe
final class CelAsyncRuntimeImpl implements CelAsyncRuntime {
private final ImmutableMap<CelAttributePattern, CelUnknownAttributeValueResolver>
unknownAttributeResolvers;
private final ImmutableSet<CelAttributePattern> unknownAttributePatterns;
private final CelRuntime runtime;
private final ListeningExecutorService executorService;
private final ThreadSafeCelVariableResolver variableResolver;
private final int maxEvaluateIterations;

private CelAsyncRuntimeImpl(
ImmutableMap<CelAttributePattern, CelUnknownAttributeValueResolver> unknownAttributeResolvers,
ImmutableSet<CelAttributePattern> unknownAttributePatterns,
ThreadSafeCelVariableResolver variableResolver,
CelRuntime runtime,
ListeningExecutorService executorService,
int maxEvaluateIterations) {
this.unknownAttributeResolvers = unknownAttributeResolvers;
this.unknownAttributePatterns = unknownAttributePatterns;
this.variableResolver = variableResolver;
this.runtime = runtime;
this.executorService = executorService;
this.maxEvaluateIterations = maxEvaluateIterations;
}

private UnknownContext newAsyncContext() {
return UnknownContext.create(variableResolver, unknownAttributePatterns);
return UnknownContext.create(variableResolver, ImmutableList.of());
}

@Override
public AsyncProgram createProgram(CelAbstractSyntaxTree ast) throws CelEvaluationException {
return new AsyncProgramImpl(
runtime.createProgram(ast),
executorService,
unknownAttributeResolvers,
maxEvaluateIterations,
newAsyncContext());
}
Expand All @@ -76,17 +66,12 @@ static Builder newBuilder() {
/** {@link CelAsyncRuntimeBuilder} implementation for {@link CelAsyncRuntimeImpl}. */
private static final class Builder implements CelAsyncRuntimeBuilder {
private CelRuntime runtime;
private final ImmutableSet.Builder<CelAttributePattern> unknownAttributePatterns;
private final ImmutableMap.Builder<CelAttributePattern, CelUnknownAttributeValueResolver>
unknownAttributeResolvers;
private ListeningExecutorService executorService;
private Optional<ThreadSafeCelVariableResolver> variableResolver;
private int maxEvaluateIterations;

private Builder() {
runtime = CelRuntimeFactory.standardCelRuntimeBuilder().build();
unknownAttributeResolvers = ImmutableMap.builder();
unknownAttributePatterns = ImmutableSet.builder();
variableResolver = Optional.empty();
maxEvaluateIterations = DEFAULT_MAX_EVALUATE_ITERATIONS;
}
Expand All @@ -97,20 +82,6 @@ public Builder setRuntime(CelRuntime runtime) {
return this;
}

@Override
public Builder addUnknownAttributePatterns(CelAttributePattern... attributes) {
unknownAttributePatterns.add(attributes);
return this;
}

@Override
public Builder addResolvableAttributePattern(
CelAttributePattern attribute, CelUnknownAttributeValueResolver resolver) {
unknownAttributeResolvers.put(attribute, resolver);
unknownAttributePatterns.add(attribute);
return this;
}

@Override
public Builder setMaxEvaluateIterations(int n) {
Preconditions.checkArgument(n > 0, "maxEvaluateIterations must be positive");
Expand All @@ -134,8 +105,6 @@ public Builder setExecutorService(ExecutorService executorService) {
public CelAsyncRuntime build() {
Preconditions.checkNotNull(executorService, "executorService must be specified.");
return new CelAsyncRuntimeImpl(
unknownAttributeResolvers.buildOrThrow(),
unknownAttributePatterns.build(),
variableResolver.orElse((unused) -> Optional.empty()),
runtime,
executorService,
Expand Down
Loading