ActionBaton is a lightweight, developer-friendly Java library for internal workflow orchestration. It supports sequential, parallel, conditional, and mixed execution patterns with minimal dependencies. Built with simplicity in mind, it is an open-source project that welcomes community contributions.
- Why ActionBaton?
- Installation
- Quick Start
- Execution Patterns
- Configuration-Driven Workflows
- Detailed Code Examples
- Comparison and Real-World Use Cases
- Architecture
- Contributing
- Contributors
- License
- Lightweight: ~500KB with minimal dependencies (Jackson, SLF4J).
- Flexible: Mix sequential, parallel, conditional, iterator, and mapper patterns.
- Java 21 Ready: Support for Virtual Threads in parallel execution.
- Self-contained: No external infrastructure or databases required.
Note: The libraries are currently not published to Maven Central. This section will be updated once they are available.
public class SendEmailAction implements IAction<ActionExecutionContext, Exception> {
@Override
public String getActionName() { return "SEND_EMAIL"; }
@Override
public void execute(ActionExecutionContext context) throws Exception {
String email = (String) context.getContext().get("email");
// Business logic here
}
}ActionExecutionContext context = new ActionExecutionContextImpl("ONBOARDING");
context.getContext().put("email", "user@example.com");
ActionBatonBuilderFactory.getInstance()
.getSequenceBuilder()
.add(new ValidateUserAction())
.add(new SendEmailAction())
.build()
.execute(context);factory.getSequenceBuilder()
.add(new Step1Action())
.add(new Step2Action())
.build()
.execute(context);ParallelExecutorProperties props = new ParallelExecutorProperties();
props.setThreadCount(5);
props.setUseVirtualThreads(true); // Java 21+
factory.getParallelBuilder()
.add(Arrays.asList(new TaskA(), new TaskB()))
.properties(props)
.build()
.execute(context);factory.getConditionalBuilder()
.predicate(new MyPredicate())
.ifThen(new SuccessAction())
.elseThen(new FailureAction())
.build()
.execute(context);Iterates over a collection provided by an IIterator and executes an action for each item.
factory.getIteratorActionBuilder()
.iterate(new MyIterator()) // Returns List<V>
.add(new ProcessItemAction())
.build()
.execute(context);Decouples action logic by transforming the ActionExecutionContext into a specific input object.
factory.getMapperExecutor()
.mapper(new MyMapper())
.action(new UnderlyingAction())
.build()
.execute(context);Executes a complex Directed Acyclic Graph (DAG) defined programmatically or via configuration.
factory.getActionDagActionBuilder()
.actionDag(myDagEntity)
.orchestrator(myOrchestrator)
.build()
.execute(context);Mix and match different patterns to create complex workflows.
factory.getSequenceBuilder()
.add(new InitializeAction())
.add(factory.getParallelBuilder()
.add(new ParallelTask1())
.add(new ParallelTask2())
.build())
.add(factory.getConditionalBuilder()
.predicate(new ShouldContinuePredicate())
.ifThen(new FinalStepAction())
.build())
.build()
.execute(context);ActionBaton supports declarative workflows via JSON:
{
"actionDagId": "USER_FLOW",
"rootAction": {
"executor": "SEQUENTIAL",
"actions": [
{ "name": "VALIDATE" },
{
"executor": "PARALLEL",
"actions": [{ "name": "EMAIL" }, { "name": "LOG" }]
}
]
}
}Execute using ActionOrchestrator:
orchestrator.executeActionDag(context, dagJson);For a detailed comparison with solutions like Apache Camel, Dexecutor, and CompletableFuture, as well as more real-world examples, see: π Comparison and Real-World Use Cases
ActionBaton uses a layered approach:
- Core Interfaces:
IAction,IPredicate,IMapper,IIterator(See Code Examples). - Builders: Fluent API for programmatic definition.
- Executors: Implementations for different patterns (Sequential, Parallel, etc.).
- Context:
ActionExecutionContextfor state management across steps.
We welcome contributions from the community! Whether you are fixing a bug, adding a new feature, or improving documentation, your help is appreciated. Feel free to:
- Submit Pull Requests
- Report issues
- Suggest new features
ActionBaton is built by developers, for developers. We are always looking for new contributors to join our journey!
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Making workflow orchestration simple and lightweight.