Skip to content

flipkart-incubator/action-baton

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ActionBaton

Java License

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.


πŸ“‘ Index


πŸš€ Why ActionBaton?

  • 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.

πŸ“¦ Installation

Note: The libraries are currently not published to Maven Central. This section will be updated once they are available.

πŸ“– Quick Start

1. Define an Action

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
    }
}

2. Orchestrate and Execute

ActionExecutionContext context = new ActionExecutionContextImpl("ONBOARDING");
context.getContext().put("email", "user@example.com");

ActionBatonBuilderFactory.getInstance()
    .getSequenceBuilder()
    .add(new ValidateUserAction())
    .add(new SendEmailAction())
    .build()
    .execute(context);

🎯 Execution Patterns

Sequential

factory.getSequenceBuilder()
    .add(new Step1Action())
    .add(new Step2Action())
    .build()
    .execute(context);

Parallel

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);

Conditional

factory.getConditionalBuilder()
    .predicate(new MyPredicate())
    .ifThen(new SuccessAction())
    .elseThen(new FailureAction())
    .build()
    .execute(context);

Iterator

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);

Mapper

Decouples action logic by transforming the ActionExecutionContext into a specific input object.

factory.getMapperExecutor()
    .mapper(new MyMapper())
    .action(new UnderlyingAction())
    .build()
    .execute(context);

ActionDag

Executes a complex Directed Acyclic Graph (DAG) defined programmatically or via configuration.

factory.getActionDagActionBuilder()
    .actionDag(myDagEntity)
    .orchestrator(myOrchestrator)
    .build()
    .execute(context);

Mixed (Complex Flows)

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);

πŸ”§ Configuration-Driven Workflows

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);

πŸ“Š Comparison and Use Cases

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


πŸ—οΈ Architecture

ActionBaton uses a layered approach:

  1. Core Interfaces: IAction, IPredicate, IMapper, IIterator (See Code Examples).
  2. Builders: Fluent API for programmatic definition.
  3. Executors: Implementations for different patterns (Sequential, Parallel, etc.).
  4. Context: ActionExecutionContext for state management across steps.

🀝 Contributing

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

πŸ‘₯ Contributors

ActionBaton is built by developers, for developers. We are always looking for new contributors to join our journey!


πŸ“„ License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.


Making workflow orchestration simple and lightweight.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages