The pipeline context object
public class PipelineContext {
private final String userInput;
private final Map extracted = new HashMap<>();
private final List warnings = new ArrayList<>();
public Optional get(String key, Class type) { ... }
public void put(String key, Object value) { ... }
} Advertisement
Stages consume + produce
Each stage reads what it needs from context, adds what it produces, and returns.
public class EntityExtractor implements PipelineStage {
@Override
public void run(PipelineContext ctx) {
String text = ctx.userInput();
Map entities = extract(text);
ctx.put("entities", entities);
}
} Advertisement
Immutable snapshots
If you fan-out mid-pipeline, snapshot the context so parallel branches can't stomp each other. Copy-on-write does the job.