Skip to content

Commit

Permalink
Java and Reactor examples for [Non]BlockingExecutor annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Katkov authored and Nikita Katkov committed Sep 28, 2021
1 parent ec7d510 commit 5b314f1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
* Indicates that the annotated executor (e.g. coroutine dispatcher, scheduler, etc.)
* allows blocking methods execution.
*
* If a given context does not allow blocking calls, {@link NonBlockingExecutor} should be used.
* If a given executor does not allow blocking calls, {@link NonBlockingExecutor} should be used.
*
* Example:
* Example 1 (Kotlin coroutines):
* <pre>
* {@code
* class ExampleService {
* @BlockingContext
* class BlockingExampleService {
* @BlockingExecutor
* val dispatcher: CoroutineContext
* get() { ... }
*
Expand All @@ -42,6 +42,27 @@
* }
* }
* </pre>
*
* Example 2 (Java with Reactor framework):
* <pre>
* {@code
* class BlockingExampleService {
* private static final @BlockingExecutor Scheduler blockingScheduler =
* Schedulers.newBoundedElastic(4, 10, "executor");
*
* public Flux<String> foo(Flux<String> urls) {
* return urls.publishOn(blockingScheduler)
* .map(url -> blockingBuzz(url)); // no IDE warning
* }
*
* @Blocking
* private String blockingBuzz(String url) { ... }
* }
* }
* </pre>
*
* @see Blocking
* @see NonBlocking
*/
@Documented
@Retention(RetentionPolicy.CLASS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
* Indicates that the annotated executor (e.g. coroutine dispatcher, scheduler, etc.)
* does not allow blocking methods execution.
*
* If a given context allows blocking calls, {@link BlockingExecutor} should be used.
* If a given executor allows blocking calls, {@link BlockingExecutor} should be used.
*
* Example:
* Example 1 (Kotlin coroutines):
* <pre>
* {@code
* class ExampleService {
* @NonBlockingContext
* class NonBlockingExampleService {
* @NonBlockingExecutor
* val dispatcher: CoroutineContext
* get() { ... }
*
Expand All @@ -42,6 +42,28 @@
* }
* }
* </pre>
*
* <br>
* Example 2 (Java with Reactor framework):
* <pre>
* {@code
* class NonBlockingExampleService {
* private static final @NonBlockingExecutor Scheduler operationsScheduler =
* Schedulers.newParallel("parallel");
*
* public Flux<String> foo(Flux<String> urls) {
* return urls.publishOn(operationsScheduler)
* .filter(url -> blockingBuzz(url) != null); // IDE warning: `Possibly blocking call in non-blocking context`
* }
*
* @Blocking
* private String blockingBuzz(String url) { ... }
* }
* }
* </pre>
*
* @see Blocking
* @see NonBlocking
*/
@Documented
@Retention(RetentionPolicy.CLASS)
Expand Down

0 comments on commit 5b314f1

Please sign in to comment.