3. ArmoniK Java SDK — Worker

3.1. Project Structure

The Java Worker SDK is split into two Maven modules:

Module

Purpose

armonik-worker-domain

SDK for implementing TaskProcessor, used for dynamic loading

armonik-worker

Allows static TaskProcessor implementation

Key entry points:

  • TaskProcessor interface — implement your task logic here.

  • ArmoniKWorker class — handles server startup.


3.2. TaskProcessor Interface

TaskProcessor is a @FunctionalInterface with a single method:

TaskOutcome processTask(TaskContext context);

Return values:

Value

Meaning

TaskOutcome.SUCCESS

Task completed successfully

TaskOutcome.error(String)

Business logic failure with a message

Error handling strategy:

  • Return SUCCESS for 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

rawData()

Read entire blob as byte[] (cached if ≤ 8 MiB)

stream()

Read as InputStream (large files, bypasses cache)

asString(Charset)

Read as String with specified encoding

size()

Get blob size in bytes

3.3.3. TaskOutput — Write operations

Method

Description

write(byte[])

Write byte array

write(InputStream)

Write from stream

write(String, Charset)

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 WorkerLibrary in task options.

Runtime flow:

  1. Receive task with WorkerLibrary specification.

  2. Unzip the blob containing the library (fat JAR).

  3. Load the JAR with a dedicated ClassLoader.

  4. Locate TaskProcessor by fully qualified class name.

  5. Instantiate the processor.

  6. Execute processTask(TaskContext).

  7. Return execution status.

  8. Unload library and clean up.


3.5.2. Static Mode

Build a custom Docker image with your processor embedded.

Advantages:

  • Simpler setup, no WorkerLibrary needed.

  • Self-contained image.

Limitations:

  • Supports a single task type.

  • Requires rebuilding the Docker image for any logic change.

Setup steps:

  1. Implement the TaskProcessor interface.

  2. Create a Main class.

  3. Configure with ArmoniKWorker.builder().withTaskProcessor(...).

  4. Build a fat JAR (Maven Shade or Gradle Shadow).

  5. Create a Docker image with the JAR.

  6. Deploy to ArmoniK (edit or create a partition).