Add dispatch strategy, implement bfs strategy by zsmoore · Pull Request #261 · graphql-java/java-dataloader
See discussion in - #256
Build on #243
Allow for custom dispatch strategies
Right now the dispatch strategy (in this PR and the original busy strategy) do not need dataloader references, they just need registry references. Its possible that strategies prefer to have the DL loaded such as a DFS strategy to trigger the dl dispatch immediately without using a registry reference but as there is no current need do not include it.
Because of the circular reference dependency between dispatch strategy and registry, choose to add a bootstrap function into the interface to give a reference to the strategy
BFS strategy handles dispatching in a level by level fashion see example here -
i.e.
Async Path
A
B (async)
E
F
C
G (async)
H
D
I
J
A dispatches immediately, queues B, C, D
B, C, D dispatch queue G, H, I, J
Thread is spawned to wait for B to finish and retry every 30 ms
B finishes, queues E, F
E, F, G, H, I, J dispatched
This dispatch strategy also handles chained dataloaders but beyond that handles ASYNC chained dataloaders such that a dataloader makes an api call then chains a subsequent dataloader.
This is done with minimal thread overload by doing dispatchAll + only queueing a single thread when work is known to exist but not be completed
Added some tests to verify some behavior of the dispatch strategy