3. ArmoniK Java SDK — Worker
3.1. Project Structure
The Java Worker SDK is split into two Maven modules:
Module |
Purpose |
|---|---|
|
SDK for implementing |
|
Allows static |
Key entry points:
TaskProcessorinterface — implement your task logic here.ArmoniKWorkerclass — handles server startup.
3.2. TaskProcessor Interface
TaskProcessor is a @FunctionalInterface with a single method:
TaskOutcome processTask(TaskContext context);
Return values:
Value |
Meaning |
|---|---|
|
Task completed successfully |
|
Business logic failure with a message |
Error handling strategy:
Return
SUCCESSfor successful execution.Return
error(message)for expected business failures.Let exceptions propagate for infrastructure/unexpected issues.
3.3. TaskContext — Input/Output Access
3.3.1. Accessing inputs and outputs by logical name
TaskInput input = context.getInput("A");
TaskOutput output = context.getOutput("result");
boolean hasInput = context.hasInput("A");
boolean hasOutput = context.hasOutput("result");
3.3.2. TaskInput — Read operations
Method |
Description |
|---|---|
|
Read entire blob as |
|
Read as |
|
Read as |
|
Get blob size in bytes |
3.3.3. TaskOutput — Write operations
Method |
Description |
|---|---|
|
Write byte array |
|
Write from stream |
|
Write string with specified encoding |
3.4. TaskContext — Advanced Features
3.4.1. Blob creation
context.createBlob(InputBlobDefinition definition);
Creates a session-scoped blob from within the worker.
3.4.2. Subtask submission
context.submitTask(TaskDefinition definition);
Submits a child task from within the current task (dynamic workflows).
Subtask input sources:
Parent task input (reuse)
Existing blob
New
InputBlobDefinition
Subtask output targets:
Parent task output (delegation)
New
OutputBlobDefinition
3.5. Deployment Modes
3.5.1. Dynamic Mode
Uses a pre-built Docker image that loads your JAR at runtime.
Advantages:
Supports multiple task types.
No Docker rebuild required when changing logic.
Requirements:
Your class must implement
WorkerLibrary.The JAR is uploaded as a blob and referenced via
WorkerLibraryin task options.
Runtime flow:
Receive task with
WorkerLibraryspecification.Unzip the blob containing the library (fat JAR).
Load the JAR with a dedicated
ClassLoader.Locate
TaskProcessorby fully qualified class name.Instantiate the processor.
Execute
processTask(TaskContext).Return execution status.
Unload library and clean up.
3.5.2. Static Mode
Build a custom Docker image with your processor embedded.
Advantages:
Simpler setup, no
WorkerLibraryneeded.Self-contained image.
Limitations:
Supports a single task type.
Requires rebuilding the Docker image for any logic change.
Setup steps:
Implement the
TaskProcessorinterface.Create a
Mainclass.Configure with
ArmoniKWorker.builder().withTaskProcessor(...).Build a fat JAR (Maven Shade or Gradle Shadow).
Create a Docker image with the JAR.
Deploy to ArmoniK (edit or create a partition).