Iced Cakes Pipeline
Jump to navigation
Jump to search
Contents
Motivation
Pipelines can increase throughput when processing a stream of data. We will gain additional experience with Phasers by building a software pipeline.
Backgroud
Code To Use
Cakes
Looping
Phasers
class Phaser (Guide to the Java Phaser)
- register
- arrive
- awaitAdvance use via PhaserUtils.awaitAdvanceForPhase(phaser, phase)
If you are on or past the phase you want to await, then calling phaser.awaitAdvance() directly is fine. If you might be on a prior phase, then invoke PhaserUtils.awaitAdvanceForPhase(phaser, phase). If in doubt, invoking awaitAdvanceForPhase is fine.
public static int awaitAdvanceForPhase(Phaser phaser, int phase) {
return awaitAdvanceForPhase(phaser, phase, () -> Thread.yield());
}
public static int awaitAdvanceForPhase(Phaser phaser, int phase, Runnable runnable) {
while (true) {
int currentPhase = phaser.awaitAdvance(phase);
if (currentPhase < 0 || currentPhase > phase) {
return currentPhase;
} else {
if (runnable != null) {
runnable.run();
}
}
}
}
Questions To Ask Yourself
- What are my tasks?
- What work does each task need to do?
- What, if anything, does each task depend upon? That is: what does each task have to wait for before it may proceed?
Code To Implement
| class: | CakePipeline.java | |
| methods: | mixBakeAndIceCakes | |
| package: | pipeline.cake.studio | |
| source folder: | student/src/main/java |
method: public static IcedCake[] mixBakeAndIceCakes(Mixer mixer, Baker baker, Icer icer, int cakeCount)
(parallel implementation required)
Testing Your Solution
Visualization
| class: | CakePipelineVizApp.java | VIZ |
| package: | pipeline.cake.viz | |
| source folder: | student/src//java |
Correctness
| class: | CakePipelineTestSuite.java | |
| package: | pipeline.cake.studio | |
| source folder: | testing/src/test/java |
When you are passing the tests and your visualization looks good, demo it to an instructor.
