use of won.bot.framework.eventbot.event.impl.crawl.CrawlCommandFailureEvent in project webofneeds by researchstudio-sat.
the class CrawlAction method doRun.
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
if (!(event instanceof CrawlCommandEvent))
return;
CrawlCommandEvent crawlCommandEvent = (CrawlCommandEvent) event;
EventListenerContext ctx = getEventListenerContext();
logger.debug("starting crawl for {}", crawlCommandEvent.getStartURI());
StopWatch stopWatch = new StopWatch();
stopWatch.start();
Dataset crawledData = null;
try {
crawledData = ctx.getLinkedDataSource().getDataForResourceWithPropertyPath(crawlCommandEvent.getStartURI(), crawlCommandEvent.getNeedURI(), crawlCommandEvent.getPropertyPaths(), crawlCommandEvent.getGetMaxRequest(), crawlCommandEvent.getMaxDepth());
} catch (Exception e) {
logger.debug("caught exeption during crawl for {}", crawlCommandEvent.getStartURI(), e);
ctx.getEventBus().publish(new CrawlCommandFailureEvent(crawlCommandEvent, "Could not crawl " + crawlCommandEvent.getStartURI() + " with WebID " + crawlCommandEvent.getNeedURI() + ": caught " + e));
return;
}
stopWatch.stop();
logger.debug("finished crawl for {} in {} millis", crawlCommandEvent.getStartURI(), stopWatch.getTotalTimeMillis());
ctx.getEventBus().publish(new CrawlCommandSuccessEvent(crawlCommandEvent, crawledData, "Finished crawling " + crawlCommandEvent.getStartURI() + " in " + stopWatch.getTotalTimeMillis()));
}
use of won.bot.framework.eventbot.event.impl.crawl.CrawlCommandFailureEvent in project webofneeds by researchstudio-sat.
the class CrawlConnectionDataBehaviour method onActivate.
@Override
protected void onActivate(Optional<Object> message) {
logger.debug("activating crawling connection data for connection {}", command.getConnectionURI());
logger.debug("will deactivate autmatically after " + abortTimeout);
LinkedDataSource linkedDataSource = context.getLinkedDataSource();
if (linkedDataSource instanceof CachingLinkedDataSource) {
URI toInvalidate = WonLinkedDataUtils.getEventContainerURIforConnectionURI(command.getConnectionURI(), linkedDataSource);
((CachingLinkedDataSource) linkedDataSource).invalidate(toInvalidate);
((CachingLinkedDataSource) linkedDataSource).invalidate(toInvalidate, command.getNeedURI());
URI remoteConnectionUri = WonLinkedDataUtils.getRemoteConnectionURIforConnectionURI(command.getConnectionURI(), linkedDataSource);
toInvalidate = WonLinkedDataUtils.getEventContainerURIforConnectionURI(remoteConnectionUri, linkedDataSource);
((CachingLinkedDataSource) linkedDataSource).invalidate(toInvalidate);
((CachingLinkedDataSource) linkedDataSource).invalidate(toInvalidate, command.getNeedURI());
}
context.getTaskScheduler().schedule(new Runnable() {
@Override
public void run() {
deactivate();
}
}, new Date(System.currentTimeMillis() + abortTimeout.toMillis()));
;
List<Path> propertyPaths = new ArrayList<>();
PrefixMapping pmap = new PrefixMappingImpl();
pmap.withDefaultMappings(PrefixMapping.Standard);
pmap.setNsPrefix("won", WON.getURI());
pmap.setNsPrefix("msg", WONMSG.getURI());
propertyPaths.add(PathParser.parse("won:hasEventContainer", pmap));
propertyPaths.add(PathParser.parse("won:hasEventContainer/rdfs:member", pmap));
CrawlCommandEvent crawlNeedCommandEvent = new CrawlCommandEvent(command.getNeedURI(), command.getNeedURI(), propertyPaths, 10000, 5);
propertyPaths = new ArrayList();
propertyPaths.add(PathParser.parse("won:hasEventContainer", pmap));
propertyPaths.add(PathParser.parse("won:hasEventContainer/rdfs:member", pmap));
propertyPaths.add(PathParser.parse("won:hasEventContainer/rdfs:member/msg:hasCorrespondingRemoteMessage", pmap));
propertyPaths.add(PathParser.parse("won:hasRemoteNeed", pmap));
propertyPaths.add(PathParser.parse("won:hasRemoteNeed/won:hasEventContainer", pmap));
propertyPaths.add(PathParser.parse("won:hasRemoteNeed/won:hasEventContainer/rdfs:member", pmap));
propertyPaths.add(PathParser.parse("won:hasRemoteConnection", pmap));
propertyPaths.add(PathParser.parse("won:hasRemoteConnection/won:hasEventContainer", pmap));
propertyPaths.add(PathParser.parse("won:hasRemoteConnection/won:hasEventContainer/rdfs:member", pmap));
propertyPaths.add(PathParser.parse("won:hasRemoteConnection/won:hasEventContainer/rdfs:member/msg:hasCorrespondingRemoteMessage", pmap));
CrawlCommandEvent crawlConnectionCommandEvent = new CrawlCommandEvent(command.getNeedURI(), command.getConnectionURI(), propertyPaths, 10000, 5);
Dataset crawledData = DatasetFactory.createGeneral();
// add crawlcommand listener
this.subscribeWithAutoCleanup(CrawlCommandEvent.class, new ActionOnEventListener(context, new OrFilter(new SameEventFilter(crawlNeedCommandEvent), new SameEventFilter(crawlConnectionCommandEvent)), new CrawlAction(context)));
// when the first crawl succeeds, start the second
this.subscribeWithAutoCleanup(CrawlCommandSuccessEvent.class, new ActionOnEventListener(context, new CommandResultFilter(crawlNeedCommandEvent), new BaseEventBotAction(context) {
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
logger.debug("finished crawling need data. ");
Dataset dataset = ((CrawlCommandSuccessEvent) event).getCrawledData();
RdfUtils.addDatasetToDataset(crawledData, dataset);
// now crawl connection data
context.getEventBus().publish(crawlConnectionCommandEvent);
}
}));
// when we're done crawling, validate:
this.subscribeWithAutoCleanup(CrawlCommandSuccessEvent.class, new ActionOnEventListener(context, new CommandResultFilter(crawlConnectionCommandEvent), new BaseEventBotAction(context) {
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
logger.debug("finished crawling need data for connection {}", command.getConnectionURI());
Dataset dataset = ((CrawlCommandSuccessEvent) event).getCrawledData();
RdfUtils.addDatasetToDataset(crawledData, dataset);
context.getEventBus().publish(new CrawlConnectionCommandSuccessEvent(command, crawledData));
deactivate();
}
}));
// when something goes wrong, abort
this.subscribeWithAutoCleanup(CrawlCommandFailureEvent.class, new ActionOnFirstEventListener(context, new OrFilter(new CommandResultFilter(crawlConnectionCommandEvent), new CommandResultFilter(crawlNeedCommandEvent)), new BaseEventBotAction(context) {
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
CrawlCommandFailureEvent failureEvent = (CrawlCommandFailureEvent) event;
logger.debug("crawling failed for connection {}, message: {}", command.getConnectionURI(), failureEvent.getMessage());
context.getEventBus().publish(new CrawlConnectionCommandFailureEvent(failureEvent.getMessage(), command));
deactivate();
}
}));
// start crawling the need - connection will be crawled when need crawling is done
context.getEventBus().publish(crawlNeedCommandEvent);
}
Aggregations