use of won.matcher.service.common.event.LoadNeedEvent in project webofneeds by researchstudio-sat.
the class NeedEventLoaderActor method onReceive.
@Override
public void onReceive(final Object o) throws Throwable {
if (o instanceof LoadNeedEvent) {
LoadNeedEvent msg = (LoadNeedEvent) o;
log.debug("received request to load needs events: {}", msg);
BulkNeedEvent bulkNeedEvent;
int offset = 0;
do {
// check if need event should be returned in time interval or last X need events
if (msg.getLastXNeedEvents() == -1) {
bulkNeedEvent = sparqlService.retrieveActiveNeedEvents(msg.getFromDate(), msg.getToDate(), offset, MAX_BULK_SIZE, true);
} else {
bulkNeedEvent = sparqlService.retrieveActiveNeedEvents(0, Long.MAX_VALUE, offset, Math.min(MAX_BULK_SIZE, msg.getLastXNeedEvents() - offset), false);
}
if (bulkNeedEvent.getNeedEvents().size() > 0) {
log.debug("send bulk event of size {} back to requesting actor", bulkNeedEvent.getNeedEvents().size());
getSender().tell(bulkNeedEvent, getSelf());
offset += bulkNeedEvent.getNeedEvents().size();
}
} while (bulkNeedEvent.getNeedEvents().size() == MAX_BULK_SIZE);
}
}
Aggregations