use of won.matcher.service.common.event.LoadAtomEvent in project webofneeds by researchstudio-sat.
the class AtomEventLoaderActor method onReceive.
@Override
public void onReceive(final Object o) throws Throwable {
if (o instanceof LoadAtomEvent) {
LoadAtomEvent msg = (LoadAtomEvent) o;
log.debug("received request to load atoms events: {}", msg);
BulkAtomEvent bulkAtomEvent;
int offset = 0;
do {
// check if atom event should be returned in time interval or last X atom events
if (msg.getLastXAtomEvents() == -1) {
bulkAtomEvent = sparqlService.retrieveActiveAtomEvents(msg.getFromDate(), msg.getToDate(), offset, MAX_BULK_SIZE, true);
} else {
bulkAtomEvent = sparqlService.retrieveActiveAtomEvents(0, Long.MAX_VALUE, offset, Math.min(MAX_BULK_SIZE, msg.getLastXAtomEvents() - offset), false);
}
if (bulkAtomEvent.getAtomEvents().size() > 0) {
log.debug("send bulk event of size {} back to requesting actor", bulkAtomEvent.getAtomEvents().size());
getSender().tell(bulkAtomEvent, getSelf());
offset += bulkAtomEvent.getAtomEvents().size();
}
} while (bulkAtomEvent.getAtomEvents().size() == MAX_BULK_SIZE);
}
}
use of won.matcher.service.common.event.LoadAtomEvent 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);
}
}
use of won.matcher.service.common.event.LoadAtomEvent 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