-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
83 additions
and
3 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
workshop-examples/src/main/java/_07_advanced_streaming/_01_Multi_Split.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
///usr/bin/env jbang "$0" "$@" ; exit $? | ||
//DEPS io.smallrye.reactive:mutiny:2.4.0 | ||
package _07_advanced_streaming; | ||
|
||
import static _07_advanced_streaming._01_Multi_Split.Country.*; | ||
|
||
import java.util.List; | ||
|
||
import io.smallrye.mutiny.Multi; | ||
|
||
public class _01_Multi_Split { | ||
|
||
static class TemperatureRecord { | ||
final Country country; | ||
final String city; | ||
final long timestamp; | ||
final double value; | ||
|
||
TemperatureRecord(Country country, String city, long timestamp, double value) { | ||
this.country = country; | ||
this.city = city; | ||
this.timestamp = timestamp; | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "TemperatureRecord{" + | ||
"country=" + country + | ||
", city='" + city + '\'' + | ||
", timestamp=" + timestamp + | ||
", value=" + value + | ||
'}'; | ||
} | ||
} | ||
|
||
enum Country { | ||
FRANCE, | ||
UK, | ||
AUSTRALIA | ||
} | ||
|
||
public static void main(String[] args) { | ||
System.out.println("⚡️ Multi split operator"); | ||
|
||
var data = List.of( | ||
new TemperatureRecord(FRANCE, "Tassin-La-Demi-Lune", System.nanoTime(), 28.0), | ||
new TemperatureRecord(FRANCE, "Clermont-Ferrand", System.nanoTime(), 27.0), | ||
new TemperatureRecord(FRANCE, "Nevers", System.nanoTime(), 27.0), | ||
new TemperatureRecord(FRANCE, "Aubière", System.nanoTime(), 28.0), | ||
new TemperatureRecord(AUSTRALIA, "Sydney", System.nanoTime(), 16.0), | ||
new TemperatureRecord(FRANCE, "Lyon", System.nanoTime(), 29.0), | ||
new TemperatureRecord(AUSTRALIA, "Kensington", System.nanoTime(), 16.0), | ||
new TemperatureRecord(UK, "Newcastle", System.nanoTime(), 13.0), | ||
new TemperatureRecord(AUSTRALIA, "Coogee", System.nanoTime(), 16.0), | ||
new TemperatureRecord(UK, "Bexhill", System.nanoTime(), 22.0)); | ||
|
||
var splitter = Multi.createFrom().iterable(data) | ||
.split(Country.class, record -> record.country); | ||
|
||
splitter.get(FRANCE) | ||
.subscribe().with( | ||
record -> System.out.println("🇫🇷 => " + record), | ||
Throwable::printStackTrace, | ||
() -> System.out.println("✅ Done with France")); | ||
|
||
splitter.get(AUSTRALIA) | ||
.subscribe().with( | ||
record -> System.out.println("🇦🇺🦘 => " + record), | ||
Throwable::printStackTrace, | ||
() -> System.out.println("✅ Done with Australia")); | ||
|
||
splitter.get(UK) | ||
.subscribe().with( | ||
record -> System.out.println("🇬🇧 => " + record), | ||
Throwable::printStackTrace, | ||
() -> System.out.println("✅ Done with the UK")); | ||
|
||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...a/_07_misc/_01_Multi_Custom_Operator.java → ...a/_08_misc/_01_Multi_Custom_Operator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...s/src/main/java/_07_misc/_02_Logging.java → ...s/src/main/java/_08_misc/_02_Logging.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...s/src/main/java/_07_misc/_03_Context.java → ...s/src/main/java/_08_misc/_03_Context.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters