Skip to main content

API Reference Overview

Ratchet's public API is organized into two packages: run.ratchet.api for the user-facing API, and run.ratchet.spi for extension points. This page provides a complete index and explains how the pieces fit together.

Package Structure

run.ratchet.api — User-Facing API

Classes and interfaces you use directly when scheduling jobs, building workflows, and observing events.

Class / InterfaceKindPurpose
JobSchedulerServiceInterfacePrimary entry point for scheduling, canceling, pausing, and retrying jobs
JobBuilderInterfaceFluent builder for configuring individual jobs before submission
RecurringJobBuilderInterfaceBuilder for configuring recurring (cron-based) jobs
BatchBuilderInterfaceBuilder for in-memory batch processing of collections
StreamingBatchBuilderInterfaceBuilder for memory-efficient streaming batch processing
JobContextFinal classThread-local access to job ID, job-scoped logger binding, and parameters during execution
JobResult<T>ClassCaptures execution outcome: success/failure, return value, timing, metadata
JobHandleInterfaceLightweight receipt returned after job submission, provides the job ID
JobOptionsRecordImmutable configuration for priority, retries, backoff, and timeout
WorkflowConditionRecordDefines conditions for workflow branching (success, failure, custom, batch)
WorkflowBranchRecordPairs a condition with a task and optional description
BatchContextRecordProgress snapshot for batch jobs (total, completed, failed items)
StreamingBatchContextRecordProgress snapshot during the streaming phase of batch construction
JobPriorityEnumPriority levels: LOWEST, LOW, NORMAL, HIGH, CRITICAL
BackoffPolicyEnumRetry delay strategies: NONE, FIXED, EXPONENTIAL
JobTypeEnumJob categories: SINGLE, RECURRING, BATCH, CHAIN, WORKFLOW, SYSTEM
CircuitBreakerProfileEnumPre-configured circuit breaker profiles: DEFAULT, FAST, CRITICAL, EXTERNAL_API

run.ratchet.api — Annotations

AnnotationTargetPurpose
@RecurringMethodDeclares a method as a cron-scheduled recurring job
@CircuitBreakerProtectedType, MethodWraps invocations through the ResilienceStrategy circuit breaker
@DoNotRetryTypeMarks exception classes that should never be retried
@IncubatingAnyMarks experimental APIs that may change without deprecation

run.ratchet.api — Functional Interfaces

InterfaceSignaturePurpose
SerializableCheckedRunnablevoid run() throws ExceptionPrimary job task definition
SerializableConsumer<T>void accept(T t)Success callbacks, progress hooks
SerializableBiConsumer<T,U>void accept(T t, U u)Failure callbacks (context + error)
SerializableFunction<T,R>R apply(T t)Value-based workflow conditions
SerializablePredicate<T>boolean test(T t)Custom workflow conditions
SerializableCheckedConsumer<T>void accept(T t) throws ExceptionStreaming batch item processing

run.ratchet.api.event — Event Types

EventFires When
JobStartedEventJob begins execution
JobCompletedEventJob completes successfully
JobFailedEventJob fails after final attempt
JobRetryingEventJob is being retried
JobCancellingEventJob cancellation initiated
JobCancelledEventJob cancellation confirmed
JobPausedEventJob paused
JobResumedEventJob resumed
JobDlqEventJob moved to dead letter queue
BatchCompletingEventBatch is finishing
BatchCompletedEventBatch fully complete
ChainStartedEventWorkflow chain begins
ChainCompletedEventWorkflow chain succeeds
ChainFailedEventWorkflow chain fails
WorkflowBranchTriggeredEventA workflow condition matches
PerformanceMetricsEventSystem metrics snapshot available

run.ratchet.spi — Extension Points

InterfacePurpose
RetryPolicyCustom retry/backoff logic
ResilienceStrategyCircuit breaker / bulkhead wrapping
ClassPolicyDeserialization class allowlist
ErrorSanitizerScrub sensitive data from error messages
JobInvocationResolverCustom callback-to-job invocation resolution
ResultPersistenceStrategyCustom job return-value persistence
ExecutorProviderSupply custom thread pools or virtual threads
BeanResolverCustom bean instantiation (default: CDI)
MetricsCollectorEmit custom metrics (Micrometer, StatsD, etc.)
JobLoggerCustom job logging backend
ClusterCoordinatorDistributed wakeup notifications
StartupCoordinatorStore-backed startup leases for destructive initialization tasks
NodeIdentityProviderIdentify nodes in a cluster
RatchetOptionsRequired @ApplicationScoped CDI-produced runtime options — applications must produce one or the scheduler refuses to start

How to Read This Reference

Entry Point

Start with JobSchedulerService -- it is the only interface you inject and use directly. Every scheduling operation begins here:

@Inject
JobSchedulerService scheduler;

Building Jobs

JobSchedulerService.enqueue() returns a JobBuilder, which provides the fluent API for configuring retries, priorities, timeouts, workflows, and callbacks before calling submit().

Inside a Running Job

When Ratchet executes your job, JobContext is available on the current thread. Use it to access parameters, the job ID, and the current job-scoped logger binding.

Handling Results

JobResult<T> captures everything about a completed execution and is used in workflow conditions to drive branching logic.

API vs SPI

  • API (run.ratchet.api): Classes you use directly. Stable across minor versions.
  • SPI (run.ratchet.spi): Extension points you implement to customize behavior. Interfaces marked @Incubating may change between minor versions.

To provide a custom SPI implementation, create a CDI bean annotated with @Alternative @Priority(APPLICATION).

Maven Coordinates

<dependency>
<groupId>run.ratchet</groupId>
<artifactId>ratchet-api</artifactId>
</dependency>

The ratchet-api module has no runtime dependencies beyond Jakarta EE API types (jakarta.enterprise.cdi-api and jakarta.interceptor-api, both provided by the runtime). It defines the complete public API and SPI surface.

See Also