java.lang.Object
java.lang.Thread
de.seggebaeing.sqlanalyzer.logic.util.thread.WorkerThread
de.seggebaeing.sqlanalyzer.logic.util.thread.GenerationThread
All Implemented Interfaces:
Runnable

public class GenerationThread extends WorkerThread
Worker that generates SQL queries by executing Prompt × LLM combinations, optionally repeated, using a fixed-size pool of subworkers.

Responsibilities:

  • Schedules jobs for each Prompt × LLM × repetition and computes a temperature value interpolated between each LLM’s min/max range.
  • Respects provider rate limits via PromptAuthorizer: waits before prompting and, on RateLimitException, reports and registers the retry Instant.
  • Emits per-LLM progress callbacks (startedProgress/finishedProgress).
  • Collects results in a thread-safe set of GeneratedQuery and strips Markdown fences from returned SQL.
  • Honors interruption (cancels subworkers) and, on full success, invokes the supplied signalDone callback.
Threading: uses a poolSize-bounded ExecutorService. The result set is synchronized; callers should only read it after the thread finished.
Since:
1.0
Author:
Felix Seggebäing
  • Constructor Details

    • GenerationThread

      public GenerationThread(int poolSize, int repetitionCount, Collection<LLM> llms, Collection<Prompt> prompts, Runnable signalDone, Consumer<LLM> startedProgress, Consumer<LLM> finishedProgress, BiConsumer<LLM,Instant> rateLimitReporter)
      Constructs a generation worker thread.
      Parameters:
      poolSize - number of parallel subworkers to use
      repetitionCount - number of repetitions per Prompt × LLM
      llms - LLMs to use for generation
      prompts - prompts to be combined with each LLM
      signalDone - callback invoked on successful completion (may be null)
      startedProgress - callback invoked when a subworker starts work for an LLM
      finishedProgress - callback invoked when a subworker finishes for an LLM
      rateLimitReporter - callback to report rate-limit retry instants per LLM
      Implementation Note:
      The thread name is assigned as "Generation-Worker-<n>" using an atomic counter.
  • Method Details

    • run

      public void run()
      Executes generation by dispatching Prompt × LLM × repetition jobs to a fixed thread pool.

      Creates a ExecutorService with poolSize, submits one task per combination, then shuts down the pool and waits for completion. On full success (no timeout/interruption), invokes signalDone. Honors interruption by cancelling subworkers.

      Specified by:
      run in interface Runnable
      Specified by:
      run in class WorkerThread
      Implementation Note:
      Results are accumulated in a synchronized set; read them only after the thread finishes.
    • getResult

      public Set<GeneratedQuery> getResult()
      Returns the set of generated queries produced by this worker.

      Behavior is undefined if called before the thread has completed successfully.

      Specified by:
      getResult in class WorkerThread
      Returns:
      the (synchronized) result set of GeneratedQuery
      Implementation Note:
      The returned set is a Collections.synchronizedSet; synchronize on it when iterating.