use of won.matcher.service.common.event.BulkAtomEvent in project webofneeds by researchstudio-sat.
the class RematchSparqlService method registerMatchingAttempts.
/**
* Bulk update of several meta data messages about the crawling process using a
* separate graph.
*
* @param msg multiple messages that describe crawling meta data to update
*/
public void registerMatchingAttempts(BulkAtomEvent msg) {
final AtomicInteger counter = new AtomicInteger();
StringBuilder builder = new StringBuilder();
msg.getAtomEvents().stream().map(e -> createMatchAttemptUpdate(e)).filter(o -> o.isPresent()).map(o -> o.get()).map(updateString -> parseUpdateQuery(updateString)).filter(o -> o.isPresent()).map(o -> o.get()).collect(Collectors.groupingBy(x -> counter.getAndIncrement() % MAX_UPDATES_PER_REQUEST)).values().stream().forEach(requests -> {
requests.stream().reduce((UpdateRequest left, UpdateRequest right) -> {
right.getOperations().stream().forEach(left::add);
return left;
}).ifPresent(request -> executeUpdate(request));
});
}
use of won.matcher.service.common.event.BulkAtomEvent in project webofneeds by researchstudio-sat.
the class MatcherPubSubActor method onReceive.
@Override
public void onReceive(Object o) throws Exception {
if (o.equals(TICK)) {
if (!atomsUpdateRequestReceived) {
// request missing atom events from matching service while this matcher was not
// available
long lastSeenAtomDate = Long.valueOf(appStateProps.getProperty(LAST_SEEN_ATOM_DATE_PROPERTY_NAME));
LoadAtomEvent loadAtomEvent;
if (lastSeenAtomDate == -1) {
// request the last one atom event from matching service and accept every atom
// event timestamp
loadAtomEvent = new LoadAtomEvent(1);
} else {
// request atom events with date > last atom event date
log.info("request missed atoms from matching service with crawl date > {}", lastSeenAtomDate);
loadAtomEvent = new LoadAtomEvent(lastSeenAtomDate, Long.MAX_VALUE);
}
pubSubMediator.tell(new DistributedPubSubMediator.Publish(loadAtomEvent.getClass().getName(), loadAtomEvent), getSelf());
}
} else if (o instanceof AtomEvent) {
AtomEvent atomEvent = (AtomEvent) o;
log.info("AtomEvent received: " + atomEvent);
// matching service
if (atomsUpdateRequestReceived) {
long lastSeenAtomDate = Long.valueOf(appStateProps.getProperty(LAST_SEEN_ATOM_DATE_PROPERTY_NAME));
if (atomEvent.getCrawlDate() > lastSeenAtomDate) {
appStateProps.setProperty(LAST_SEEN_ATOM_DATE_PROPERTY_NAME, String.valueOf(atomEvent.getCrawlDate()));
saveLastSeenAtomDate();
}
}
matcherActor.tell(atomEvent, getSelf());
} else if (o instanceof BulkAtomEvent) {
// receiving a bulk atom event means this is the answer for the request of atom
// updates
// there could arrive several of these bulk events
atomsUpdateRequestReceived = true;
BulkAtomEvent bulkAtomEvent = (BulkAtomEvent) o;
log.info("BulkAtomEvent received with {} atom events", bulkAtomEvent.getAtomEvents().size());
for (AtomEvent atomEvent : ((BulkAtomEvent) o).getAtomEvents()) {
long lastSeenAtomDate = Long.valueOf(appStateProps.getProperty(LAST_SEEN_ATOM_DATE_PROPERTY_NAME));
if (atomEvent.getCrawlDate() > lastSeenAtomDate) {
appStateProps.setProperty(LAST_SEEN_ATOM_DATE_PROPERTY_NAME, String.valueOf(atomEvent.getCrawlDate()));
saveLastSeenAtomDate();
}
matcherActor.tell(atomEvent, getSelf());
}
} else if (o instanceof HintEvent) {
HintEvent hintEvent = (HintEvent) o;
log.info("Publish hint event: " + hintEvent);
pubSubMediator.tell(new DistributedPubSubMediator.Publish(hintEvent.getClass().getName(), hintEvent), getSelf());
} else if (o instanceof BulkHintEvent) {
BulkHintEvent bulkHintEvent = (BulkHintEvent) o;
log.info("Publish bulk hint event: " + bulkHintEvent);
pubSubMediator.tell(new DistributedPubSubMediator.Publish(bulkHintEvent.getClass().getName(), bulkHintEvent), getSelf());
} else {
unhandled(o);
}
}
Aggregations