You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This small and simple utility library is a port of [Facebook DataLoader](https://github.com/facebook/dataloader)
11
-
to Java 8 for use with [Vert.x](http://vertx.io). It can serve as integral part of your application's data layer to provide a
8
+
This small and simple utility library is a Pure Java 8 port of [Facebook DataLoader](https://github.com/facebook/dataloader).
9
+
It can serve as integral part of your application's data layer to provide a
12
10
consistent API over various back-ends and reduce message communication overhead through batching and caching.
13
11
14
-
An important use case for `DataLoader` is improving the efficiency of GraphQL query execution, but there are
12
+
An important use case for `java-dataloader` is improving the efficiency of GraphQL query execution, but there are
15
13
many other use cases where you can benefit from using this utility.
16
14
17
15
Most of the code is ported directly from Facebook's reference implementation, with one IMPORTANT adaptation to make
18
-
it work for Java 8 and Vert.x. ([more on this below](manual-dispatching)).
16
+
it work for Java 8. ([more on this below](manual-dispatching)).
19
17
20
18
But before reading on, be sure to take a short dive into the
21
19
[original documentation](https://github.com/facebook/dataloader/blob/master/README.md) provided by Lee Byron (@leebyron)
@@ -40,24 +38,24 @@ and Nicholas Schrock (@schrockn) from [Facebook](https://www.facebook.com/), the
40
38
41
39
## Features
42
40
43
-
Vert.x `DataLoader` is a feature-complete port of the Facebook reference implementation with [one major difference](#manual-dispatching). These features are:
41
+
`java-dataloader` is a feature-complete port of the Facebook reference implementation with [one major difference](#manual-dispatching). These features are:
44
42
45
43
- Simple, intuitive API, using generics and fluent coding
46
44
- Define batch load function with lambda expression
47
45
- Schedule a load request in queue for batching
48
46
- Add load requests from anywhere in code
49
-
- Request returns [`Future<V>`](http://vertx.io/docs/apidocs/io/vertx/core/Future.html) of requested value
50
-
- Can create multiple requests at once, returns [`CompositeFuture`](http://vertx.io/docs/apidocs/io/vertx/core/CompositeFuture.html)
47
+
- Request returns a [`CompleteableFuture<V>`](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html) of the requested value
48
+
- Can create multiple requests at once, returns a `CombinedFutures` object
51
49
- Caches load requests, so data is only fetched once
52
50
- Can clear individual cache keys, so data is fetched on next batch queue dispatch
53
51
- Can prime the cache with key/values, to avoid data being fetched needlessly
54
52
- Can configure cache key function with lambda expression to extract cache key from complex data loader key types
55
-
- Dispatch load request queue after batch is prepared, also returns [`CompositeFuture`](http://vertx.io/docs/apidocs/io/vertx/core/CompositeFuture.html)
53
+
- Dispatch load request queue after batch is prepared, also returns `CombinedFutures`
56
54
- Individual batch futures complete / resolve as batch is processed
57
-
-`CompositeFuture`s results are ordered according to insertion order of load requests
55
+
-`CombinedFutures` results are ordered according to insertion order of load requests
58
56
- Deals with partial errors when a batch future fails
59
57
- Can disable batching and/or caching in configuration
60
-
- Can supply your own [`CacheMap<K, V>`](https://github.com/engagingspaces/vertx-dataloader/blob/master/src/main/java/io/engagingspaces/vertx/dataloader/CacheMap.java) implementations
58
+
- Can supply your own [`CacheMap<K, V>`](https://github.com/bbakerman/java-dataloader/blob/master/src/main/java/io/engagingspaces/vertx/dataloader/CacheMap.java) implementations
61
59
- Has very high test coverage (see [Acknowledgements](#acknowlegdements))
62
60
63
61
## Differences to reference implementation
@@ -68,10 +66,6 @@ The original data loader was written in Javascript for NodeJS. NodeJS is single-
68
66
asynchronous logic by invoking functions on separate threads in an event loop, as explained
69
67
[in this post](http://stackoverflow.com/a/19823583/3455094) on StackOverflow.
70
68
71
-
[Vert.x](http://vertx.io) on the other hand also uses an event loop ([that you should not block!!](http://vertx.io/docs/vertx-core/java/#golden_rule)), but comes
72
-
with actor-like [`Verticle`](http://vertx.io/docs/vertx-core/java/#_verticles)s and a
73
-
distributed [`EventBus`](http://vertx.io/docs/vertx-core/java/#event_bus) that make it inherently asynchronous, and non-blocking.
74
-
75
69
Now in NodeJS generates so-call 'ticks' in which queued functions are dispatched for execution, and Facebook `DataLoader` uses
76
70
the `nextTick()` function in NodeJS to _automatically_ dequeue load requests and send them to the batch execution function for processing.
77
71
@@ -80,10 +74,10 @@ And here there is an **IMPORTANT DIFFERENCE** compared to how _this_ data loader
80
74
In NodeJS the batch preparation will not affect the asynchronous processing behaviour in any way. It will just prepare
81
75
batches in 'spare time' as it were.
82
76
83
-
This is different in Vert.x as you will actually _delay_ the execution of your load requests, until the moment where you make a call
77
+
This is different in Java as you will actually _delay_ the execution of your load requests, until the moment where you make a call
84
78
to `dataLoader.dispatch()` in comparison to when you would just handle futures directly.
85
79
86
-
Does this make Java `DataLoader` any less useful than the reference implementation? I would argue this is not the case,
80
+
Does this make Java `DataLoader` any less useful than the reference implementation? We would argue this is not the case,
87
81
and there are also gains to this different mode of operation:
88
82
89
83
- In contrast to the NodeJS implementation _you_ as developer are in full control of when batches are dispatched
@@ -97,7 +91,7 @@ in the load request queue will never be batched, and thus _will never complete_!
97
91
98
92
### Installing
99
93
100
-
Gradle users configure the `vertx-dataloader` dependency in `build.gradle`:
94
+
Gradle users configure the `java-dataloader` dependency in `build.gradle`:
0 commit comments