use of won.protocol.message.processor.exception.WonMessageProcessingException in project webofneeds by researchstudio-sat.
the class EagerlyCachePopulatingMessageProcessor method process.
@Override
public WonMessage process(WonMessage message) throws WonMessageProcessingException {
if (this.linkedDataSourceOnBehalfOfNeed != null && this.linkedDataSourceOnBehalfOfNeed instanceof CachingLinkedDataSource) {
logger.debug("eagerly fetching delivery chain for mesasge {} into cache", message.getMessageURI());
URI requester = message.getReceiverNeedURI();
((CachingLinkedDataSource) linkedDataSourceOnBehalfOfNeed).addToCache(message.getCompleteDataset(), message.getMessageURI(), requester);
// load the original message(s) into cache, too
Set<URI> toLoad = new HashSet<URI>();
addIfNotNull(toLoad, message.getIsRemoteResponseToMessageURI());
addIfNotNull(toLoad, message.getIsResponseToMessageURI());
addIfNotNull(toLoad, message.getCorrespondingRemoteMessageURI());
List<URI> previous = WonRdfUtils.MessageUtils.getPreviousMessageUrisIncludingRemote(message);
addIfNotNull(toLoad, previous);
parallelRequestsThreadpool.submit(() -> toLoad.parallelStream().forEach(uri -> linkedDataSourceOnBehalfOfNeed.getDataForResource(uri, requester)));
}
return message;
}
Aggregations