... | ... | @@ -20,7 +20,7 @@ Next, we count all files by incrementing a counter upon each sent file. |
|
|
The last stage will save or print the resulting number.
|
|
|
|
|
|
|
|
|
Our mission is to implement those four stages as seperate filter and connect them.
|
|
|
Our mission is to implement those four stages as separate filter and connect them.
|
|
|
In the following we will learn how to implement a stage.
|
|
|
|
|
|
### Implementing them stages
|
... | ... | @@ -34,5 +34,23 @@ You may extend from ```teetime.framework.AbstractProducerStage``` and use its fi |
|
|
Make sure you use ```terminate()``` after the stage is done with all its work, so that the framework knows the job is done.
|
|
|
A suitable solution can be found [here](https://build.se.informatik.uni-kiel.de/gitlab/teetime/teetime/blob/master/src/test/java/teetime/examples/filecounter/DirReader.java).
|
|
|
|
|
|
|
|
|
|
|
|
\ No newline at end of file |
|
|
The next task is to implement the ```FileCounter```.
|
|
|
It receives elements of the type ```File``` and simply increments a counter upon each incoming element.
|
|
|
```teetime.framework.AbstractConsumerStage``` suits best this requirements.
|
|
|
The counter only contains the correct result if the architecture is about to terminate.
|
|
|
So make sure you override the method ```onTerminating()``` to send the final result.
|
|
|
One more hint: you may use ```createInputPort()``` or ```createOutputPort()``` to create additional ports.
|
|
|
Of course, there is also a [sample solution](https://build.se.informatik.uni-kiel.de/gitlab/teetime/teetime/blob/master/src/test/java/teetime/examples/filecounter/FileCounter.java) for this part.
|
|
|
|
|
|
After all the hard work, we will finish everything by implementing the ```ResultPrinter```.
|
|
|
It receives elements of the type ```Integer``` and prints them to the console.
|
|
|
As this is a simple consumer, ```teetime.framework.AbstractConsumerStage``` should also be used here.
|
|
|
|
|
|
### Connecting them stages
|
|
|
|
|
|
What splendid stages we have, which are waiting to be connected.
|
|
|
Analogous to integrated circuits which are connected through their ports, we only need to connect the ports of the stages which want to communicate with each other.
|
|
|
For this purpose we can use the class ```teetime.framework.Configuration```.
|
|
|
We create instances of our three stages and connect them correctly.
|
|
|
Please remember that TeeTime only supports uni-directed communication.
|
|
|
A sample solution can look like [this](https://build.se.informatik.uni-kiel.de/gitlab/teetime/teetime/blob/master/src/test/java/teetime/examples/filecounter/PrintResultConfig.java). |
|
|
\ No newline at end of file |