use of com.vaticle.typedb.core.reasoner.resolution.framework.Request in project grakn by graknlabs.
the class NegationResolver method receiveFail.
@Override
protected void receiveFail(com.vaticle.typedb.core.reasoner.resolution.framework.Response.Fail fromDownstream, int iteration) {
LOG.trace("{}: Receiving Failed: {}, therefore is SATISFIED", name(), fromDownstream);
if (isTerminated())
return;
Request toDownstream = fromDownstream.sourceRequest();
Request fromUpstream = fromUpstream(toDownstream);
BoundsState boundsState = this.boundsStates.get(fromUpstream.partialAnswer().conceptMap());
boundsState.setSatisfied();
for (BoundsState.Awaiting awaiting : boundsState.awaiting) {
answerToUpstream(upstreamAnswer(awaiting.request), awaiting.request, awaiting.iterationRequested);
}
boundsState.clearAwaiting();
}
use of com.vaticle.typedb.core.reasoner.resolution.framework.Request in project grakn by graknlabs.
the class CompoundResolver method receiveFail.
@Override
protected void receiveFail(Response.Fail fromDownstream, int iteration) {
LOG.trace("{}: received Exhausted, with iter {}: {}", name(), iteration, fromDownstream);
if (isTerminated())
return;
Request toDownstream = fromDownstream.sourceRequest();
Request fromUpstream = fromUpstream(toDownstream);
RequestState requestState = requestStates.get(fromUpstream);
if (iteration < requestState.iteration()) {
// short circuit old iteration failed messages back out of the actor model
failToUpstream(fromUpstream, iteration);
return;
}
requestState.downstreamManager().removeDownstream(fromDownstream.sourceRequest());
nextAnswer(fromUpstream, requestState, iteration);
}
use of com.vaticle.typedb.core.reasoner.resolution.framework.Request in project grakn by graknlabs.
the class ConclusionResolver method receiveFail.
@Override
protected void receiveFail(Response.Fail fromDownstream, int iteration) {
LOG.trace("{}: received Fail: {}", name(), fromDownstream);
if (isTerminated())
return;
Request toDownstream = fromDownstream.sourceRequest();
Request fromUpstream = fromUpstream(toDownstream);
ConclusionRequestState<?> requestState = this.requestStates.get(fromUpstream);
if (iteration < requestState.iteration()) {
// short circuit old iteration fail messages to upstream
failToUpstream(fromUpstream, iteration);
return;
}
requestState.downstreamManager().removeDownstream(fromDownstream.sourceRequest());
nextAnswer(fromUpstream, requestState, iteration);
}
use of com.vaticle.typedb.core.reasoner.resolution.framework.Request in project grakn by graknlabs.
the class ConjunctionResolver method toNextChild.
private void toNextChild(Response.Answer fromDownstream, int iteration, Request fromUpstream, RequestState requestState, Plans.Plan plan) {
int nextResolverIndex = fromDownstream.planIndex() + 1;
Resolvable<?> nextResolvable = plan.get(nextResolverIndex);
ResolverRegistry.ResolverView nextPlannedDownstream = downstreamResolvers.get(nextResolvable);
final Partial<?> downstream = toDownstream(fromDownstream.answer().asCompound(), nextPlannedDownstream, nextResolvable);
Request downstreamRequest = Request.create(driver(), nextPlannedDownstream.resolver(), downstream, nextResolverIndex);
requestFromDownstream(downstreamRequest, fromUpstream, iteration);
// negated requests can be used twice in a parallel setting, and return the same answer twice
if (!nextResolvable.isNegated() || (nextResolvable.isNegated() && !requestState.downstreamManager().contains(downstreamRequest))) {
requestState.downstreamManager().addDownstream(downstreamRequest);
}
}
use of com.vaticle.typedb.core.reasoner.resolution.framework.Request in project grakn by graknlabs.
the class ConjunctionResolver method receiveAnswer.
@Override
protected void receiveAnswer(Response.Answer fromDownstream, int iteration) {
LOG.trace("{}: received Answer: {}", name(), fromDownstream);
if (isTerminated())
return;
Request toDownstream = fromDownstream.sourceRequest();
Request fromUpstream = fromUpstream(toDownstream);
RequestState requestState = requestStates.get(fromUpstream);
Plans.Plan plan = plans.getActive(fromUpstream);
// this could be either implemented with a different response type: FinalAnswer, or splitting Request into ReusableRequest vs SingleRequest
if (plan.get(toDownstream.planIndex()).isNegated())
requestState.downstreamManager().removeDownstream(toDownstream);
Partial.Compound<?, ?> partialAnswer = fromDownstream.answer().asCompound();
if (plan.isLast(fromDownstream.planIndex())) {
Optional<AnswerState> upstreamAnswer = toUpstreamAnswer(partialAnswer);
boolean answerAccepted = upstreamAnswer.isPresent() && tryAcceptUpstreamAnswer(upstreamAnswer.get(), fromUpstream, iteration);
if (!answerAccepted)
nextAnswer(fromUpstream, requestState, iteration);
} else {
toNextChild(fromDownstream, iteration, fromUpstream, requestState, plan);
}
}
Aggregations