... | ... | @@ -3,23 +3,27 @@ |
|
|
## What Base Class Should I Extend?
|
|
|
When writing an own stage, you should know a few abstract classes that could save you some work.
|
|
|
|
|
|
Inherit from `AbstractConsumerStage`, if you want to write a stage that always needs to consume elements from its input ports to make progress.
|
|
|
In this way, you get a stage with a pre-initialized consumer semantics.
|
|
|
Moreover, you can access a default input port named `inputPort`.
|
|
|
Example consumer stages are `Counter`, `Cache`, and `Delay`.
|
|
|
- Inherit from `AbstractTransformation`, if you want to write a stage that should have exactly one input port and exactly one output port, each with a **different port type**.
|
|
|
You can access the input port by `inputPort` and the output port by `outputPort`.
|
|
|
|
|
|
Inherit from `AbstractProducerStage`, if you want to write a stage that does not need to have any input ports.
|
|
|
- Inherit from `AbstractFilter`, if you want to write a stage that should have exactly one input port and exactly one output port, both with the **same port type**.
|
|
|
You can access the input port by `inputPort` and the output port by `outputPort`.
|
|
|
|
|
|
- Inherit from `AbstractConsumerStage`, if you want to write a stage that should have exactly one input port and an arbitrary number of output ports.
|
|
|
Example consumer stages are the `CollectorSink` and the `InstanceOfFilter`.
|
|
|
|
|
|
- Inherit from `AbstractStage`, if you want to write a stage that should have more than one input port and an arbitrary number of output ports.
|
|
|
An example stage is the `Merger`.
|
|
|
|
|
|
- Inherit from `AbstractProducerStage`, if you want to write a stage that does not need to have any input ports.
|
|
|
In this way, you get a stage with a pre-initialized producer semantics.
|
|
|
Moreover, you can access a default output port named `outputPort`.
|
|
|
**Note:** You need to place a `terminate()` call within your `execute` method to signal the framework when your producer stage has finished its job.
|
|
|
Example producer stages are `Clock` and `InitialElementProducer`.
|
|
|
|
|
|
<!-- Inherit from `AbstractStage`, if you want to write a stage that should have neither a pre-initialized semantics nor any default input and output ports.
|
|
|
An example stage is the `Merger`. -->
|
|
|
Example producer stages are the `Clock` and the `InitialElementProducer`.
|
|
|
|
|
|
## What Code Shall I Write?
|
|
|
You only need to implement the logics your stage should represent in the `execute()` method.
|
|
|
If you need an input or an output port, declare it as class attribute by using the `createInputPort()` and `createOutputPort()` methods.
|
|
|
If you need an input or an output port, declare it as instance field by using the `createInputPort()` and `createOutputPort()` methods.
|
|
|
If your stage should have an internal state, follow these [instructions](writing-a-stage-with-a-state).
|
|
|
|
|
|
The following examples will give you a short insight on how stages can be implemented:
|
... | ... | |