... | ... | @@ -29,35 +29,10 @@ This section will explain the implementation of those exact stages. |
|
|
If you want to dig deeper into the implementation mechanisms of the TeeTime framework, we recommend to take a look at [INSERT LINK](#).
|
|
|
|
|
|
Our first stage will be the ```DirReader```. It visits all directories and sends all containing files to the next stage.
|
|
|
A suitable implementation may look like this:
|
|
|
```Java
|
|
|
class DirReader extends AbstractProducerStage<File> {
|
|
|
|
|
|
private final File element;
|
|
|
|
|
|
public DirReader(final File directory) {
|
|
|
if (directory.isDirectory()) { // Check if it is a directory
|
|
|
element = directory;
|
|
|
} else {
|
|
|
throw new IllegalArgumentException("Given file is not a directory.");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void execute() {
|
|
|
visit(element);
|
|
|
this.terminate(); // If everything is done, terminate
|
|
|
}
|
|
|
|
|
|
private void visit(final File element) {
|
|
|
for (File file : element.listFiles()) {
|
|
|
if (file.isDirectory()) {
|
|
|
this.visit(file); // Visit recursively all dirs
|
|
|
} else {
|
|
|
outputPort.send(file); // Send file to next stage
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
``` |
|
|
\ No newline at end of file |
|
|
This is a perfect task to start working with TeeTime: implement this logic into a single stage.
|
|
|
You may extend from ```teetime.framework.AbstractProducerStage``` and use its field ```outputPort``` to send elements to the next stage.
|
|
|
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 |