Skip to content

Commit 3f167a6

Browse files
committed
initial commit
0 parents  commit 3f167a6

File tree

84 files changed

+1142
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1142
-0
lines changed

.idea/.gitignore

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/compiler.xml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jarRepositories.xml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/uiDesigner.xml

Lines changed: 124 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pom.xml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.example</groupId>
8+
<artifactId>java-reactive</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
12+
13+
<dependencies>
14+
<dependency>
15+
<groupId>io.projectreactor</groupId>
16+
<artifactId>reactor-core</artifactId>
17+
</dependency>
18+
<!-- test data -->
19+
<dependency>
20+
<groupId>com.github.javafaker</groupId>
21+
<artifactId>javafaker</artifactId>
22+
<version>1.0.2</version>
23+
</dependency>
24+
<dependency>
25+
<groupId>org.projectlombok</groupId>
26+
<artifactId>lombok</artifactId>
27+
<version>1.18.16</version>
28+
<scope>provided</scope>
29+
</dependency>
30+
<dependency>
31+
<groupId>io.projectreactor</groupId>
32+
<artifactId>reactor-test</artifactId>
33+
<scope>test</scope>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.junit.jupiter</groupId>
37+
<artifactId>junit-jupiter-engine</artifactId>
38+
<version>5.4.2</version>
39+
<scope>test</scope>
40+
</dependency>
41+
</dependencies>
42+
43+
<dependencyManagement>
44+
<dependencies>
45+
<dependency>
46+
<groupId>io.projectreactor</groupId>
47+
<artifactId>reactor-bom</artifactId>
48+
<version>2020.0.2</version>
49+
<type>pom</type>
50+
<scope>import</scope>
51+
</dependency>
52+
</dependencies>
53+
</dependencyManagement>
54+
55+
<build>
56+
<plugins>
57+
<plugin>
58+
<groupId>org.apache.maven.plugins</groupId>
59+
<artifactId>maven-compiler-plugin</artifactId>
60+
<version>3.8.0</version>
61+
<configuration>
62+
<release>11</release>
63+
</configuration>
64+
</plugin>
65+
</plugins>
66+
</build>
67+
68+
<properties>
69+
<maven.compiler.source>11</maven.compiler.source>
70+
<maven.compiler.target>11</maven.compiler.target>
71+
</properties>
72+
73+
</project>

src/main/java/chap1/FakerDemo.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package chap1;
2+
3+
import com.github.javafaker.Faker;
4+
5+
public class FakerDemo {
6+
7+
public static void main(String[] args) {
8+
for(int i =0; i < 10; i++){
9+
System.out.println(Faker.instance().name().fullName());
10+
}
11+
}
12+
}

src/main/java/chap1/Lec01Stream.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package chap1;
2+
3+
import java.util.stream.Stream;
4+
5+
public class Lec01Stream {
6+
public static void main(String[] args) {
7+
Stream<Integer> stream = Stream.of(1).map( i->{
8+
try {
9+
Thread.sleep(1000);
10+
11+
}catch (InterruptedException e){
12+
e.printStackTrace();
13+
}
14+
return i * 2;
15+
});
16+
stream.forEach(System.out::println);
17+
18+
19+
}
20+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package chap1;
2+
3+
import reactor.core.publisher.Mono;
4+
import utility.Util;
5+
6+
public class Lec03MonoSubscribe {
7+
8+
public static void main(String[] args) {
9+
//publisher
10+
Mono<Integer> mono = Mono.just("ball").map(String::length);
11+
12+
//1
13+
mono.subscribe();
14+
15+
//2 subscriber
16+
mono.subscribe(System.out::println,
17+
err -> System.out.println(err.getMessage()),
18+
() -> System.out.println("Completed"));
19+
20+
//3 neat with Uitility
21+
mono.subscribe(Util.onNext(),
22+
err -> Util.onError(),
23+
() -> Util.onComplete());
24+
}
25+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package chap1;
2+
3+
import reactor.core.publisher.Mono;
4+
import utility.Util;
5+
6+
public class Lec04MonoEmptyOrError {
7+
8+
public static void main(String[] args) {
9+
userRepository(2).subscribe(
10+
Util.onNext(),
11+
Util.onError(),
12+
Util.onComplete()
13+
);
14+
}
15+
16+
public static Mono<String> userRepository(int userId) {
17+
if (userId == 1) {
18+
return Mono.just(Util.faker().name().firstName());
19+
} else if (userId == 2) {
20+
return Mono.empty();
21+
} else
22+
return Mono.error(new RuntimeException("Not in the allowed range"));
23+
}
24+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package chap1;
2+
3+
import reactor.core.publisher.Mono;
4+
import utility.Util;
5+
6+
import java.util.concurrent.Callable;
7+
import java.util.function.Supplier;
8+
9+
public class Lec05MonoFromSupplier {
10+
11+
public static void main(String[] args) {
12+
//use just only when you have the data only
13+
// Mono<String> mono = Mono.just(getName());
14+
15+
Supplier<String> stringSupplier = () -> getName();
16+
Mono<String> mono = Mono.fromSupplier(stringSupplier);
17+
mono.subscribe(
18+
Util.onNext()
19+
);
20+
21+
Callable<String> stringCallable = () -> getName();
22+
Mono<String> monoCallable = Mono.fromCallable(stringCallable);
23+
monoCallable.subscribe(
24+
Util.onNext()
25+
);
26+
27+
}
28+
29+
private static String getName() {
30+
System.out.println("Generating name..");
31+
return Util.faker().name().fullName();
32+
}
33+
}
34+

0 commit comments

Comments
 (0)