Search in sources :

Example 16 with WonMessageProcessingException

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;
}
Also used : LinkedDataSource(won.protocol.util.linkeddata.LinkedDataSource) Logger(org.slf4j.Logger) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) CachingLinkedDataSource(won.protocol.util.linkeddata.CachingLinkedDataSource) Set(java.util.Set) WonMessageProcessingException(won.protocol.message.processor.exception.WonMessageProcessingException) WonMessage(won.protocol.message.WonMessage) WonRdfUtils(won.protocol.util.WonRdfUtils) HashSet(java.util.HashSet) List(java.util.List) WonMessageProcessor(won.protocol.message.processor.WonMessageProcessor) URI(java.net.URI) CachingLinkedDataSource(won.protocol.util.linkeddata.CachingLinkedDataSource) URI(java.net.URI) HashSet(java.util.HashSet)

Aggregations

WonMessageProcessingException (won.protocol.message.processor.exception.WonMessageProcessingException)16 WonMessage (won.protocol.message.WonMessage)11 URI (java.net.URI)6 PublicKey (java.security.PublicKey)4 Map (java.util.Map)4 Dataset (org.apache.jena.query.Dataset)3 Connection (won.protocol.model.Connection)3 Need (won.protocol.model.Need)3 Annotation (java.lang.annotation.Annotation)2 PrivateKey (java.security.PrivateKey)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 Test (org.junit.Test)2 StringWriter (java.io.StringWriter)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NoSuchProviderException (java.security.NoSuchProviderException)1 SignatureException (java.security.SignatureException)1 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)1 HashSet (java.util.HashSet)1 List (java.util.List)1