-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #151 from graphql-java/reactive-streams-branch
A PR for reactive streams support
- Loading branch information
Showing
24 changed files
with
1,549 additions
and
144 deletions.
There are no files selected for viewing
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
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
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,36 @@ | ||
package org.dataloader; | ||
|
||
import org.reactivestreams.Subscriber; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* A function that is invoked for batch loading a stream of data values indicated by the provided list of keys. | ||
* <p> | ||
* The function <b>must</b> call the provided {@link Subscriber} to process the values it has retrieved to allow | ||
* the future returned by {@link DataLoader#load(Object)} to complete as soon as the individual value is available | ||
* (rather than when all values have been retrieved). | ||
* <p> | ||
* <b>NOTE:</b> It is <b>required</b> that {@link Subscriber#onNext(Object)} is invoked on each value in the same order as | ||
* the provided keys and that you provide a value for every key provided. | ||
* | ||
* @param <K> type parameter indicating the type of keys to use for data load requests. | ||
* @param <V> type parameter indicating the type of values returned | ||
* @see BatchLoader for the non-reactive version | ||
*/ | ||
public interface BatchPublisher<K, V> { | ||
/** | ||
* Called to batch the provided keys into a stream of values. You <b>must</b> provide | ||
* the same number of values as there as keys, and they <b>must</b> be in the order of the keys. | ||
* <p> | ||
* The idiomatic approach would be to create a reactive {@link org.reactivestreams.Publisher} that provides | ||
* the values given the keys and then subscribe to it with the provided {@link Subscriber}. | ||
* <p> | ||
* <b>NOTE:</b> It is <b>required</b> that {@link Subscriber#onNext(Object)} is invoked on each value in the same order as | ||
* the provided keys and that you provide a value for every key provided. | ||
* | ||
* @param keys the collection of keys to load | ||
* @param subscriber as values arrive you must call the subscriber for each value | ||
*/ | ||
void load(List<K> keys, Subscriber<V> subscriber); | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/org/dataloader/BatchPublisherWithContext.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,34 @@ | ||
package org.dataloader; | ||
|
||
import org.reactivestreams.Subscriber; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* This form of {@link BatchPublisher} is given a {@link org.dataloader.BatchLoaderEnvironment} object | ||
* that encapsulates the calling context. A typical use case is passing in security credentials or database details | ||
* for example. | ||
* <p> | ||
* See {@link BatchPublisher} for more details on the design invariants that you must implement in order to | ||
* use this interface. | ||
*/ | ||
public interface BatchPublisherWithContext<K, V> { | ||
/** | ||
* Called to batch the provided keys into a stream of values. You <b>must</b> provide | ||
* the same number of values as there as keys, and they <b>must</b> be in the order of the keys. | ||
* <p> | ||
* The idiomatic approach would be to create a reactive {@link org.reactivestreams.Publisher} that provides | ||
* the values given the keys and then subscribe to it with the provided {@link Subscriber}. | ||
* <p> | ||
* <b>NOTE:</b> It is <b>required</b> that {@link Subscriber#onNext(Object)} is invoked on each value in the same order as | ||
* the provided keys and that you provide a value for every key provided. | ||
* <p> | ||
* This is given an environment object to that maybe be useful during the call. A typical use case | ||
* is passing in security credentials or database details for example. | ||
* | ||
* @param keys the collection of keys to load | ||
* @param subscriber as values arrive you must call the subscriber for each value | ||
* @param environment an environment object that can help with the call | ||
*/ | ||
void load(List<K> keys, Subscriber<V> subscriber, BatchLoaderEnvironment environment); | ||
} |
Oops, something went wrong.