Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
6e30220
Add a proof-of-concept for "Observer-like" batch loading
AlexandreCarlton May 12, 2024
95540ff
reactive streams support branch
bbakerman May 17, 2024
2cdba8a
Merge remote-tracking branch 'origin/master' into reactive-streams-br…
bbakerman May 17, 2024
1d78255
reactive streams support branch - merged master
bbakerman May 17, 2024
2032e33
Merge remote-tracking branch 'origin/master' into observer-batch-load…
AlexandreCarlton May 18, 2024
6b5a732
Eliminate *BatchObserver in favour of Publisher
AlexandreCarlton May 18, 2024
68d7f54
Use internal Assertions over Java's raw assert
AlexandreCarlton May 18, 2024
a3132b7
Remove handling of Throwable passed into onNext
AlexandreCarlton May 18, 2024
fbeffae
Expose `new*DataLoader` methods for *PublisherBatchLoader
AlexandreCarlton May 18, 2024
b2a662d
Copy/tweak original/ DataLoader tests for publisher equivalents
AlexandreCarlton May 18, 2024
0d0b2f8
Rename '*PublisherBatchLoader' to 'BatchPublisher'
AlexandreCarlton May 18, 2024
14002f6
Ensure DataLoaderSubscriber is only called by one thread
AlexandreCarlton May 18, 2024
0f303a8
Document Subscriber#onNext invocation order
AlexandreCarlton May 18, 2024
ce115fd
Merge branch 'reactive-streams-branch' into observer-batch-loader-pro…
bbakerman May 19, 2024
288be41
Merge pull request #148 from AlexandreCarlton/observer-batch-loader-p…
bbakerman May 19, 2024
e16fa65
Merge remote-tracking branch 'origin/master' into reactive-streams-br…
bbakerman May 20, 2024
a93112a
reactive streams support branch - getting it compiling
bbakerman May 20, 2024
74567fe
Making the Subscribers use a common base class
bbakerman May 21, 2024
4396624
Making the Subscribers use a common base class- synchronized on each …
bbakerman May 21, 2024
8a64483
Making the Subscribers use a common base class- now with failing test…
bbakerman May 21, 2024
3e8ac9c
Making the Subscribers use a common base class- fail the overall CF o…
bbakerman May 21, 2024
eb2b40c
Inline BatchPublisher tests into DataLoaderTest
AlexandreCarlton May 20, 2024
651e561
Fix MappedBatchPublisher loaders to work without cache
AlexandreCarlton May 20, 2024
8295396
Merge pull request #155 from AlexandreCarlton/migrate-publisher-tests
bbakerman May 22, 2024
86ec5c8
Merge remote-tracking branch 'origin/reactive-streams-branch' into re…
bbakerman May 22, 2024
6d3c4eb
Making the Subscribers use a common base class - merged in main branch
bbakerman May 22, 2024
3fddb8b
Merge pull request #154 from graphql-java/reactive-streams-common-pub…
bbakerman May 22, 2024
034c68f
More tests for Publishers
bbakerman May 22, 2024
b09ac60
Merge remote-tracking branch 'origin/master' into reactive-streams-br…
bbakerman May 23, 2024
5d826b8
Merge remote-tracking branch 'origin/master' into reactive-streams-br…
bbakerman May 23, 2024
8b344db
Now the builds pass - broken out the fixtures
bbakerman May 23, 2024
e9bfc2b
Merge pull request #158 from graphql-java/reactive-streams-branch-ext…
bbakerman May 23, 2024
91d3036
This moves the reactive code pout into its own package because DataLo…
bbakerman May 24, 2024
e98621b
renamed classes inline with their counterparts
bbakerman May 24, 2024
6523015
made them non public and created a static factory support class
bbakerman May 24, 2024
170ccf8
reorged method placement
bbakerman May 24, 2024
77fd0dd
Merge pull request #159 from graphql-java/reactive-streams-branch-mov…
bbakerman May 24, 2024
4b9356e
Added javadoc to publisher interfaces
bbakerman May 24, 2024
3c3cc99
Have MappedBatchPublisher take in a Set<K> keys
AlexandreCarlton May 26, 2024
2e82858
Add README sections for `*BatchPublisher`
AlexandreCarlton May 26, 2024
c3e6ee5
Merge pull request #160 from AlexandreCarlton/add-documentation-for-p…
bbakerman May 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def getDevelopmentVersion() {
version
}


def releaseVersion = System.env.RELEASE_VERSION
version = releaseVersion ? releaseVersion : getDevelopmentVersion()
group = 'com.graphql-java'
Expand Down Expand Up @@ -76,6 +75,7 @@ dependencies {
testImplementation 'org.awaitility:awaitility:2.0.0'
testImplementation 'io.projectreactor:reactor-core:3.6.6'
testImplementation 'com.github.ben-manes.caffeine:caffeine:2.9.0'
testImplementation 'io.projectreactor:reactor-core:3.6.6'
}

task sourcesJar(type: Jar) {
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/org/dataloader/BatchPublisher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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 will 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(V)} is invoked on each value in the same order as
* the provided keys.
*
* @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
*/
public interface BatchPublisher<K, V> {
void load(List<K> keys, Subscriber<V> subscriber);
}
12 changes: 12 additions & 0 deletions src/main/java/org/dataloader/BatchPublisherWithContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.dataloader;

import org.reactivestreams.Subscriber;

import java.util.List;

/**
* An {@link BatchPublisher} with a {@link BatchLoaderEnvironment} provided as an extra parameter to {@link #load}.
*/
public interface BatchPublisherWithContext<K, V> {
void load(List<K> keys, Subscriber<V> subscriber, BatchLoaderEnvironment environment);
}
268 changes: 268 additions & 0 deletions src/main/java/org/dataloader/DataLoaderFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,274 @@ public static <K, V> DataLoader<K, V> newMappedDataLoaderWithTry(MappedBatchLoad
return mkDataLoader(batchLoadFunction, options);
}

/**
* Creates new DataLoader with the specified batch loader function and default options
* (batching, caching and unlimited batch size).
*
* @param batchLoadFunction the batch load function to use
* @param <K> the key type
* @param <V> the value type
*
* @return a new DataLoader
*/
public static <K, V> DataLoader<K, V> newPublisherDataLoader(BatchPublisher<K, V> batchLoadFunction) {
return newPublisherDataLoader(batchLoadFunction, null);
}

/**
* Creates new DataLoader with the specified batch loader function with the provided options
*
* @param batchLoadFunction the batch load function to use
* @param options the options to use
* @param <K> the key type
* @param <V> the value type
*
* @return a new DataLoader
*/
public static <K, V> DataLoader<K, V> newPublisherDataLoader(BatchPublisher<K, V> batchLoadFunction, DataLoaderOptions options) {
return mkDataLoader(batchLoadFunction, options);
}

/**
* Creates new DataLoader with the specified batch loader function and default options
* (batching, caching and unlimited batch size) where the batch loader function returns a list of
* {@link org.dataloader.Try} objects.
* <p>
* If it's important you to know the exact status of each item in a batch call and whether it threw exceptions then
* you can use this form to create the data loader.
* <p>
* Using Try objects allows you to capture a value returned or an exception that might
* have occurred trying to get a value. .
*
* @param batchLoadFunction the batch load function to use that uses {@link org.dataloader.Try} objects
* @param <K> the key type
* @param <V> the value type
*
* @return a new DataLoader
*/
public static <K, V> DataLoader<K, V> newPublisherDataLoaderWithTry(BatchPublisher<K, Try<V>> batchLoadFunction) {
return newPublisherDataLoaderWithTry(batchLoadFunction, null);
}

/**
* Creates new DataLoader with the specified batch loader function and with the provided options
* where the batch loader function returns a list of
* {@link org.dataloader.Try} objects.
*
* @param batchLoadFunction the batch load function to use that uses {@link org.dataloader.Try} objects
* @param options the options to use
* @param <K> the key type
* @param <V> the value type
*
* @return a new DataLoader
*
* @see #newDataLoaderWithTry(BatchLoader)
*/
public static <K, V> DataLoader<K, V> newPublisherDataLoaderWithTry(BatchPublisher<K, Try<V>> batchLoadFunction, DataLoaderOptions options) {
return mkDataLoader(batchLoadFunction, options);
}

/**
* Creates new DataLoader with the specified batch loader function and default options
* (batching, caching and unlimited batch size).
*
* @param batchLoadFunction the batch load function to use
* @param <K> the key type
* @param <V> the value type
*
* @return a new DataLoader
*/
public static <K, V> DataLoader<K, V> newPublisherDataLoader(BatchPublisherWithContext<K, V> batchLoadFunction) {
return newPublisherDataLoader(batchLoadFunction, null);
}

/**
* Creates new DataLoader with the specified batch loader function with the provided options
*
* @param batchLoadFunction the batch load function to use
* @param options the options to use
* @param <K> the key type
* @param <V> the value type
*
* @return a new DataLoader
*/
public static <K, V> DataLoader<K, V> newPublisherDataLoader(BatchPublisherWithContext<K, V> batchLoadFunction, DataLoaderOptions options) {
return mkDataLoader(batchLoadFunction, options);
}

/**
* Creates new DataLoader with the specified batch loader function and default options
* (batching, caching and unlimited batch size) where the batch loader function returns a list of
* {@link org.dataloader.Try} objects.
* <p>
* If it's important you to know the exact status of each item in a batch call and whether it threw exceptions then
* you can use this form to create the data loader.
* <p>
* Using Try objects allows you to capture a value returned or an exception that might
* have occurred trying to get a value. .
*
* @param batchLoadFunction the batch load function to use that uses {@link org.dataloader.Try} objects
* @param <K> the key type
* @param <V> the value type
*
* @return a new DataLoader
*/
public static <K, V> DataLoader<K, V> newPublisherDataLoaderWithTry(BatchPublisherWithContext<K, Try<V>> batchLoadFunction) {
return newPublisherDataLoaderWithTry(batchLoadFunction, null);
}

/**
* Creates new DataLoader with the specified batch loader function and with the provided options
* where the batch loader function returns a list of
* {@link org.dataloader.Try} objects.
*
* @param batchLoadFunction the batch load function to use that uses {@link org.dataloader.Try} objects
* @param options the options to use
* @param <K> the key type
* @param <V> the value type
*
* @return a new DataLoader
*
* @see #newPublisherDataLoaderWithTry(BatchPublisher)
*/
public static <K, V> DataLoader<K, V> newPublisherDataLoaderWithTry(BatchPublisherWithContext<K, Try<V>> batchLoadFunction, DataLoaderOptions options) {
return mkDataLoader(batchLoadFunction, options);
}

/**
* Creates new DataLoader with the specified batch loader function and default options
* (batching, caching and unlimited batch size).
*
* @param batchLoadFunction the batch load function to use
* @param <K> the key type
* @param <V> the value type
*
* @return a new DataLoader
*/
public static <K, V> DataLoader<K, V> newMappedPublisherDataLoader(MappedBatchPublisher<K, V> batchLoadFunction) {
return newMappedPublisherDataLoader(batchLoadFunction, null);
}

/**
* Creates new DataLoader with the specified batch loader function with the provided options
*
* @param batchLoadFunction the batch load function to use
* @param options the options to use
* @param <K> the key type
* @param <V> the value type
*
* @return a new DataLoader
*/
public static <K, V> DataLoader<K, V> newMappedPublisherDataLoader(MappedBatchPublisher<K, V> batchLoadFunction, DataLoaderOptions options) {
return mkDataLoader(batchLoadFunction, options);
}

/**
* Creates new DataLoader with the specified batch loader function and default options
* (batching, caching and unlimited batch size) where the batch loader function returns a list of
* {@link org.dataloader.Try} objects.
* <p>
* If it's important you to know the exact status of each item in a batch call and whether it threw exceptions then
* you can use this form to create the data loader.
* <p>
* Using Try objects allows you to capture a value returned or an exception that might
* have occurred trying to get a value. .
*
* @param batchLoadFunction the batch load function to use that uses {@link org.dataloader.Try} objects
* @param <K> the key type
* @param <V> the value type
*
* @return a new DataLoader
*/
public static <K, V> DataLoader<K, V> newMappedPublisherDataLoaderWithTry(MappedBatchPublisher<K, Try<V>> batchLoadFunction) {
return newMappedPublisherDataLoaderWithTry(batchLoadFunction, null);
}

/**
* Creates new DataLoader with the specified batch loader function and with the provided options
* where the batch loader function returns a list of
* {@link org.dataloader.Try} objects.
*
* @param batchLoadFunction the batch load function to use that uses {@link org.dataloader.Try} objects
* @param options the options to use
* @param <K> the key type
* @param <V> the value type
*
* @return a new DataLoader
*
* @see #newDataLoaderWithTry(BatchLoader)
*/
public static <K, V> DataLoader<K, V> newMappedPublisherDataLoaderWithTry(MappedBatchPublisher<K, Try<V>> batchLoadFunction, DataLoaderOptions options) {
return mkDataLoader(batchLoadFunction, options);
}

/**
* Creates new DataLoader with the specified batch loader function and default options
* (batching, caching and unlimited batch size).
*
* @param batchLoadFunction the batch load function to use
* @param <K> the key type
* @param <V> the value type
*
* @return a new DataLoader
*/
public static <K, V> DataLoader<K, V> newMappedPublisherDataLoader(MappedBatchPublisherWithContext<K, V> batchLoadFunction) {
return newMappedPublisherDataLoader(batchLoadFunction, null);
}

/**
* Creates new DataLoader with the specified batch loader function with the provided options
*
* @param batchLoadFunction the batch load function to use
* @param options the options to use
* @param <K> the key type
* @param <V> the value type
*
* @return a new DataLoader
*/
public static <K, V> DataLoader<K, V> newMappedPublisherDataLoader(MappedBatchPublisherWithContext<K, V> batchLoadFunction, DataLoaderOptions options) {
return mkDataLoader(batchLoadFunction, options);
}

/**
* Creates new DataLoader with the specified batch loader function and default options
* (batching, caching and unlimited batch size) where the batch loader function returns a list of
* {@link org.dataloader.Try} objects.
* <p>
* If it's important you to know the exact status of each item in a batch call and whether it threw exceptions then
* you can use this form to create the data loader.
* <p>
* Using Try objects allows you to capture a value returned or an exception that might
* have occurred trying to get a value. .
*
* @param batchLoadFunction the batch load function to use that uses {@link org.dataloader.Try} objects
* @param <K> the key type
* @param <V> the value type
*
* @return a new DataLoader
*/
public static <K, V> DataLoader<K, V> newMappedPublisherDataLoaderWithTry(MappedBatchPublisherWithContext<K, Try<V>> batchLoadFunction) {
return newMappedPublisherDataLoaderWithTry(batchLoadFunction, null);
}

/**
* Creates new DataLoader with the specified batch loader function and with the provided options
* where the batch loader function returns a list of
* {@link org.dataloader.Try} objects.
*
* @param batchLoadFunction the batch load function to use that uses {@link org.dataloader.Try} objects
* @param options the options to use
* @param <K> the key type
* @param <V> the value type
*
* @return a new DataLoader
*
* @see #newMappedPublisherDataLoaderWithTry(MappedBatchPublisher)
*/
public static <K, V> DataLoader<K, V> newMappedPublisherDataLoaderWithTry(MappedBatchPublisherWithContext<K, Try<V>> batchLoadFunction, DataLoaderOptions options) {
return mkDataLoader(batchLoadFunction, options);
}

static <K, V> DataLoader<K, V> mkDataLoader(Object batchLoadFunction, DataLoaderOptions options) {
return new DataLoader<>(batchLoadFunction, options);
}
Expand Down
Loading