Package com.tonic.analysis.query.exec
Class QueryService
- java.lang.Object
-
- com.tonic.analysis.query.exec.QueryService
-
public class QueryService extends Object
Front end for running query text against a class pool - parse, plan, then execute, either inline or on a single daemon worker thread.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classQueryService.QueryConfigRuntime knobs for a query run - currently just the wall-clock budget that aborts long scans.static classQueryService.QueryResultThe outcome of one query run - the source text, its parsed and planned forms, the matches, timing, and either a completion flag or a parse error message.
-
Constructor Summary
Constructors Constructor Description QueryService(ClassPool classPool)Creates a service over a pool, with its own parser and a single-thread daemon executor for async runs.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancel()Asks the run in progress, if any, to stop early.QueryService.QueryResultexecute(String queryText, QueryService.QueryConfig config, QueryBatchRunner.ProgressListener progressListener)Parses, plans, and runs a query on the calling thread, timing the whole sequence.CompletableFuture<QueryService.QueryResult>executeAsync(String queryText, QueryService.QueryConfig config, QueryBatchRunner.ProgressListener progressListener)Runs a query on the service's worker thread; a parse failure completes the future with an error result rather than exceptionally.Queryparse(String queryText)Parses query text into its syntax tree.ProbePlanplan(Query query)Turns a parsed query into an executable plan with its scope filter.voidsetUserClassNames(Set<String> userClassNames)Restricts subsequent runs to named classes; a null set searches the whole pool.voidshutdown()Shuts down the worker thread; async runs already submitted still finish.
-
-
-
Constructor Detail
-
QueryService
public QueryService(ClassPool classPool)
Creates a service over a pool, with its own parser and a single-thread daemon executor for async runs.- Parameters:
classPool- the classes to query
-
-
Method Detail
-
setUserClassNames
public void setUserClassNames(Set<String> userClassNames)
Restricts subsequent runs to named classes; a null set searches the whole pool.- Parameters:
userClassNames- the class names to keep
-
parse
public Query parse(String queryText) throws ParseException
Parses query text into its syntax tree.- Parameters:
queryText- the query source- Returns:
- the parsed query
- Throws:
ParseException- if the text is not a valid query
-
plan
public ProbePlan plan(Query query)
Turns a parsed query into an executable plan with its scope filter.- Parameters:
query- the parsed query- Returns:
- the probe plan
-
executeAsync
public CompletableFuture<QueryService.QueryResult> executeAsync(String queryText, QueryService.QueryConfig config, QueryBatchRunner.ProgressListener progressListener)
Runs a query on the service's worker thread; a parse failure completes the future with an error result rather than exceptionally.- Parameters:
queryText- the query sourceconfig- the time budget, or null for the runner defaultprogressListener- notified of run progress, or null- Returns:
- a future for the result
-
execute
public QueryService.QueryResult execute(String queryText, QueryService.QueryConfig config, QueryBatchRunner.ProgressListener progressListener) throws ParseException
Parses, plans, and runs a query on the calling thread, timing the whole sequence.- Parameters:
queryText- the query sourceconfig- the time budget, or null for the runner defaultprogressListener- notified of run progress, or null- Returns:
- the matches, elapsed time, and whether the run completed
- Throws:
ParseException- if the text is not a valid query
-
cancel
public void cancel()
Asks the run in progress, if any, to stop early.
-
shutdown
public void shutdown()
Shuts down the worker thread; async runs already submitted still finish.
-
-