mercredi 24 juin 2015

Java Stage-based Processing Implementation

There's some domain knowledge/business logic baked into the problem I'm trying to solve but I'll try to boil it down to the basics as much as possible.

Say I have an interface defined as follows:

public interface Stage<I, O> {
    StageResult<O> process(StageResult<I> input) throws StageException;
}

This represents a stage in a multi-stage data processing pipeline, my idea is to break the data processing steps into sequential (non-branching) independent steps (such as read from file, parse network headers, parse message payloads, convert format, write to file) represented by individual Stage implementations. Ideally I'd implement a FileInputStage, a NetworkHeaderParseStage, a ParseMessageStage, a FormatStage, and a FileOutputStage, then have some sort of

Stage<A, C> compose(Stage<A, B> stage1, Stage<B, C> stage2);

method such that I can eventually compose a bunch of stages into a final stage that looks like FileInput -> FileOutput.

Is this something (specifically the compose method, or a similar mechanism for aggregating many stages into one stage) even supported by the Java type system? I'm hacking away at it now and I'm ending up in a very ugly place involving reflection and lots of unchecked generic types.

Am I heading off in the wrong direction or is this even a reasonable thing to try to do in Java? Thanks so much in advance!





Aucun commentaire:

Enregistrer un commentaire