Skip to content

Commit 5b314f1

Browse files
Nikita KatkovNikita Katkov
authored andcommitted
Java and Reactor examples for [Non]BlockingExecutor annotations
1 parent ec7d510 commit 5b314f1

File tree

2 files changed

+51
-8
lines changed

2 files changed

+51
-8
lines changed

java8/src/main/java/org/jetbrains/annotations/BlockingExecutor.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
* Indicates that the annotated executor (e.g. coroutine dispatcher, scheduler, etc.)
2323
* allows blocking methods execution.
2424
*
25-
* If a given context does not allow blocking calls, {@link NonBlockingExecutor} should be used.
25+
* If a given executor does not allow blocking calls, {@link NonBlockingExecutor} should be used.
2626
*
27-
* Example:
27+
* Example 1 (Kotlin coroutines):
2828
* <pre>
2929
* {@code
30-
* class ExampleService {
31-
* @BlockingContext
30+
* class BlockingExampleService {
31+
* @BlockingExecutor
3232
* val dispatcher: CoroutineContext
3333
* get() { ... }
3434
*
@@ -42,6 +42,27 @@
4242
* }
4343
* }
4444
* </pre>
45+
*
46+
* Example 2 (Java with Reactor framework):
47+
* <pre>
48+
* {@code
49+
* class BlockingExampleService {
50+
* private static final @BlockingExecutor Scheduler blockingScheduler =
51+
* Schedulers.newBoundedElastic(4, 10, "executor");
52+
*
53+
* public Flux<String> foo(Flux<String> urls) {
54+
* return urls.publishOn(blockingScheduler)
55+
* .map(url -> blockingBuzz(url)); // no IDE warning
56+
* }
57+
*
58+
* @Blocking
59+
* private String blockingBuzz(String url) { ... }
60+
* }
61+
* }
62+
* </pre>
63+
*
64+
* @see Blocking
65+
* @see NonBlocking
4566
*/
4667
@Documented
4768
@Retention(RetentionPolicy.CLASS)

java8/src/main/java/org/jetbrains/annotations/NonBlockingExecutor.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
* Indicates that the annotated executor (e.g. coroutine dispatcher, scheduler, etc.)
2323
* does not allow blocking methods execution.
2424
*
25-
* If a given context allows blocking calls, {@link BlockingExecutor} should be used.
25+
* If a given executor allows blocking calls, {@link BlockingExecutor} should be used.
2626
*
27-
* Example:
27+
* Example 1 (Kotlin coroutines):
2828
* <pre>
2929
* {@code
30-
* class ExampleService {
31-
* @NonBlockingContext
30+
* class NonBlockingExampleService {
31+
* @NonBlockingExecutor
3232
* val dispatcher: CoroutineContext
3333
* get() { ... }
3434
*
@@ -42,6 +42,28 @@
4242
* }
4343
* }
4444
* </pre>
45+
*
46+
* <br>
47+
* Example 2 (Java with Reactor framework):
48+
* <pre>
49+
* {@code
50+
* class NonBlockingExampleService {
51+
* private static final @NonBlockingExecutor Scheduler operationsScheduler =
52+
* Schedulers.newParallel("parallel");
53+
*
54+
* public Flux<String> foo(Flux<String> urls) {
55+
* return urls.publishOn(operationsScheduler)
56+
* .filter(url -> blockingBuzz(url) != null); // IDE warning: `Possibly blocking call in non-blocking context`
57+
* }
58+
*
59+
* @Blocking
60+
* private String blockingBuzz(String url) { ... }
61+
* }
62+
* }
63+
* </pre>
64+
*
65+
* @see Blocking
66+
* @see NonBlocking
4567
*/
4668
@Documented
4769
@Retention(RetentionPolicy.CLASS)

0 commit comments

Comments
 (0)