forked from eclipse-rdf4j/rdf4j
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
494 additions
and
394 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
56 changes: 56 additions & 0 deletions
56
...ommon/iterator/src/main/java/org/eclipse/rdf4j/common/reactor/CloseableFluxIteration.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,56 @@ | ||
package org.eclipse.rdf4j.common.reactor; | ||
|
||
import org.eclipse.rdf4j.common.iteration.AbstractCloseableIteration; | ||
import reactor.core.publisher.Flux; | ||
|
||
import java.util.Iterator; | ||
import java.util.NoSuchElementException; | ||
|
||
/** | ||
* Wraps a {@link Flux} reactive stream into a {@link org.eclipse.rdf4j.common.iteration.CloseableIteration}. | ||
* | ||
* @param <T> The type of elements iterated over. | ||
* @param <X> The exception type that can be thrown from {@link #hasNext()}, {@link #next()} and other methods. | ||
*/ | ||
@SuppressWarnings("deprecation") | ||
public class CloseableFluxIteration<T> extends AbstractCloseableIteration<T> implements FluxIteration<T> { | ||
|
||
private final Flux<T> flux; | ||
private Iterator<T> iter; | ||
|
||
/** | ||
* Creates a new IterationWrapper that operates on the supplied Iteration. | ||
* | ||
* @param flux The wrapped Iteration for this <var>IterationWrapper</var>, must not be <var>null</var>. | ||
*/ | ||
public CloseableFluxIteration(Flux<T> flux) { | ||
this.flux = flux; | ||
} | ||
|
||
@Override | ||
public Flux<T> flux() { | ||
return flux; | ||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
if (iter == null) { | ||
iter = flux.toIterable().iterator(); | ||
} | ||
|
||
return iter.hasNext(); | ||
} | ||
|
||
@Override | ||
public T next() { | ||
if (!hasNext()) { | ||
throw new NoSuchElementException(); | ||
} | ||
return iter.next(); | ||
} | ||
|
||
@Override | ||
protected void handleClose() { | ||
// TODO interrupt any thread blocking on the iterator from the flux | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
core/common/iterator/src/main/java/org/eclipse/rdf4j/common/reactor/FluxIteration.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,9 @@ | ||
package org.eclipse.rdf4j.common.reactor; | ||
|
||
import reactor.core.publisher.Flux; | ||
|
||
public interface FluxIteration<T> { | ||
|
||
Flux<T> flux(); | ||
|
||
} |
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
33 changes: 33 additions & 0 deletions
33
...src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/ReactiveQueryEvaluationStep.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,33 @@ | ||
package org.eclipse.rdf4j.query.algebra.evaluation; | ||
|
||
import org.eclipse.rdf4j.common.iteration.CloseableIteration; | ||
import org.eclipse.rdf4j.common.reactor.CloseableFluxIteration; | ||
import org.eclipse.rdf4j.query.BindingSet; | ||
import reactor.core.publisher.Flux; | ||
|
||
public interface ReactiveQueryEvaluationStep extends QueryEvaluationStep { | ||
|
||
Flux<BindingSet> transform(Flux<BindingSet> input); | ||
|
||
default Flux<BindingSet> transform(BindingSet input) { | ||
return transform(Flux.just(input)); | ||
} | ||
|
||
@Override | ||
default CloseableIteration<BindingSet> evaluate(BindingSet bindings) { | ||
Flux<BindingSet> input = Flux.just(bindings); | ||
Flux<BindingSet> output = transform(input); | ||
return new CloseableFluxIteration<>(output); | ||
} | ||
|
||
static ReactiveQueryEvaluationStep from(QueryEvaluationStep step) { | ||
if (step instanceof ReactiveQueryEvaluationStep) { | ||
return (ReactiveQueryEvaluationStep) step; | ||
} else { | ||
return input -> input.flatMapSequential( | ||
bindings -> step.evaluate(bindings).flux(), | ||
1,1 | ||
); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...uation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/ReactiveTripleSource.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,18 @@ | ||
package org.eclipse.rdf4j.query.algebra.evaluation; | ||
|
||
import org.eclipse.rdf4j.model.IRI; | ||
import org.eclipse.rdf4j.model.Resource; | ||
import org.eclipse.rdf4j.model.Statement; | ||
import org.eclipse.rdf4j.model.Value; | ||
import org.eclipse.rdf4j.query.QueryEvaluationException; | ||
import reactor.core.publisher.Flux; | ||
|
||
public interface ReactiveTripleSource { | ||
|
||
Flux<? extends Statement> getStatements(Resource subj, IRI pred, Value obj, Resource... contexts) | ||
throws QueryEvaluationException; | ||
|
||
static ReactiveTripleSource from(TripleSource source) { | ||
return (subj, pred, obj, contexts) -> source.getStatements(subj, pred, obj, contexts).flux(); | ||
} | ||
} |
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
Oops, something went wrong.