Search in sources :

Example 1 with CamelConfiguration

use of won.protocol.jms.CamelConfiguration in project webofneeds by researchstudio-sat.

the class OwnerProtocolCommunicationServiceImpl method configureCamelEndpoint.

public final synchronized CamelConfiguration configureCamelEndpoint(URI wonNodeUri, String ownerId) throws Exception {
    CamelConfiguration camelConfiguration = new CamelConfiguration();
    URI brokerURI = activeMQService.getBrokerEndpoint(wonNodeUri);
    String ownerProtocolQueueName;
    List<WonNode> wonNodeList = wonNodeRepository.findByWonNodeURI(wonNodeUri);
    // OwnerProtocolCamelConfigurator ownerProtocolCamelConfigurator =
    // camelConfiguratorFactory.createCamelConfigurator(methodName);
    logger.debug("configuring camel endpoint");
    if (ownerProtocolCamelConfigurator.getBrokerComponentName(brokerURI) != null && ownerProtocolCamelConfigurator.getEndpoint(wonNodeUri) != null) {
        logger.debug("wonNode known");
        WonNode wonNode = wonNodeList.get(0);
        // brokerURI = wonNode.getBrokerURI();
        camelConfiguration.setEndpoint(wonNode.getOwnerProtocolEndpoint());
        if (ownerProtocolCamelConfigurator.getCamelContext().getComponent(wonNodeList.get(0).getBrokerComponent()) == null) {
            // camelConfiguration.setBrokerComponentName(ownerProtocolCamelConfigurator.addCamelComponentForWonNodeBroker
            // (wonNode.getWonNodeURI(),brokerURI,wonNode.getOwnerApplicationID()));
            ownerProtocolQueueName = activeMQService.getProtocolQueueNameWithResource(wonNodeUri);
            String endpoint = ownerProtocolCamelConfigurator.configureCamelEndpointForNodeURI(wonNodeUri, brokerURI, ownerProtocolQueueName);
            camelConfiguration.setBrokerComponentName(ownerProtocolCamelConfigurator.getBrokerComponentName(brokerURI));
            ownerProtocolCamelConfigurator.getCamelContext().getComponent(camelConfiguration.getBrokerComponentName()).createEndpoint(camelConfiguration.getEndpoint());
            if (ownerProtocolCamelConfigurator.getCamelContext().getRoute(wonNode.getStartingComponent()) == null)
                ownerProtocolCamelConfigurator.addRouteForEndpoint(null, wonNode.getWonNodeURI());
        }
    } else {
        // if unknown wonNode
        logger.debug("wonNode unknown");
        // TODO: brokerURI gets the node information already. so requesting node
        // information again for queuename would be duplicate
        ownerProtocolQueueName = activeMQService.getProtocolQueueNameWithResource(wonNodeUri);
        String endpoint = ownerProtocolCamelConfigurator.configureCamelEndpointForNodeURI(wonNodeUri, brokerURI, ownerProtocolQueueName);
        camelConfiguration.setEndpoint(endpoint);
        camelConfiguration.setBrokerComponentName(ownerProtocolCamelConfigurator.getBrokerComponentName(brokerURI));
        ownerProtocolCamelConfigurator.addRouteForEndpoint(null, wonNodeUri);
    }
    return camelConfiguration;
}
Also used : WonNode(won.protocol.model.WonNode) CamelConfiguration(won.protocol.jms.CamelConfiguration) URI(java.net.URI)

Example 2 with CamelConfiguration

use of won.protocol.jms.CamelConfiguration in project webofneeds by researchstudio-sat.

the class MatcherProtocolAtomServiceClientJMSBased method hint.

@Override
public void hint(URI atomURI, URI otherAtom, double score, URI originator, Model content, WonMessage wonMessage) throws Exception {
    logger.info("atom-facing: HINT called for atomURI {} and otherAtom {} " + "with score {} from originator {}.", new Object[] { atomURI, otherAtom, score, originator });
    CamelConfiguration camelConfiguration = matcherProtocolCommunicationService.configureCamelEndpoint(wonMessage.getRecipientNodeURI(), startingEndpoint);
    String endpoint = camelConfiguration.getEndpoint();
    Map<String, String> headerMap = new HashMap<>();
    headerMap.put("atomURI", atomURI.toString());
    headerMap.put("otherAtomURI", otherAtom.toString());
    headerMap.put("score", String.valueOf(score));
    headerMap.put("originator", originator.toString());
    headerMap.put("content", RdfUtils.toString(content));
    headerMap.put(WonCamelConstants.REMOTE_BROKER_ENDPOINT_HEADER, endpoint);
    headerMap.put("methodName", "hint");
    if (!WonMessageUtils.isValidMessageUri(wonMessage.getMessageURI())) {
        wonMessage = WonMessageSignerVerifier.seal(wonMessage);
    }
    messagingService.sendInOnlyMessage(null, headerMap, WonMessageEncoder.encode(wonMessage, Lang.TRIG), startingEndpoint);
}
Also used : HashMap(java.util.HashMap) CamelConfiguration(won.protocol.jms.CamelConfiguration)

Example 3 with CamelConfiguration

use of won.protocol.jms.CamelConfiguration in project webofneeds by researchstudio-sat.

the class MatcherProtocolNeedServiceClientJMSBased method hint.

@Override
public void hint(URI needURI, URI otherNeed, double score, URI originator, Model content, WonMessage wonMessage) throws Exception {
    logger.info("need-facing: HINT called for needURI {} and otherNeed {} " + "with score {} from originator {}.", new Object[] { needURI, otherNeed, score, originator });
    CamelConfiguration camelConfiguration = matcherProtocolCommunicationService.configureCamelEndpoint(wonMessage.getReceiverNodeURI(), startingEndpoint);
    String endpoint = camelConfiguration.getEndpoint();
    Map<String, String> headerMap = new HashMap<>();
    headerMap.put("needURI", needURI.toString());
    headerMap.put("otherNeedURI", otherNeed.toString());
    headerMap.put("score", String.valueOf(score));
    headerMap.put("originator", originator.toString());
    headerMap.put("content", RdfUtils.toString(content));
    headerMap.put("remoteBrokerEndpoint", endpoint);
    headerMap.put("methodName", "hint");
    messagingService.sendInOnlyMessage(null, headerMap, WonMessageEncoder.encode(wonMessage, Lang.TRIG), startingEndpoint);
}
Also used : HashMap(java.util.HashMap) CamelConfiguration(won.protocol.jms.CamelConfiguration)

Example 4 with CamelConfiguration

use of won.protocol.jms.CamelConfiguration in project webofneeds by researchstudio-sat.

the class OwnerProtocolCommunicationServiceImpl method register.

/**
 * Registers the owner application at a won node. Owner Id is typically his Key
 * ID (lower 64 bits of the owner public key fingerprint). Unless there is a
 * collision of owner ids on the node - then the owner can assign another id...
 *
 * @throws Exception
 */
public synchronized void register(URI wonNodeURI, MessagingService messagingService) throws Exception {
    CamelConfiguration camelConfiguration = null;
    logger.debug("setting up communication with won node {} ", wonNodeURI);
    String ownerApplicationId = calculateOwnerApplicationIdFromOwnerCertificate();
    logger.debug("using ownerApplicationId: {}", ownerApplicationId);
    WonNode wonNode = wonNodeRepository.findOneByWonNodeURIAndOwnerApplicationID(wonNodeURI, ownerApplicationId);
    if (wonNode != null) {
        // register further below
        try {
            logger.debug("we're already registered. Connecting with WoN node: " + wonNodeURI);
            configureCamelEndpoint(wonNodeURI, ownerApplicationId);
            configureRemoteEndpointForOwnerApplication(ownerApplicationId, getProtocolCamelConfigurator().getEndpoint(wonNodeURI));
            logger.debug("connected with WoN node: " + wonNodeURI);
            return;
        } catch (Exception e) {
            LoggingUtils.logMessageAsInfoAndStacktraceAsDebug(logger, e, "We thought we were already registerd, but connecting to {} failed With an exception. Trying to re-register. ", wonNodeURI);
        }
    // we'll try to re-register now, see below. This is necessary if the WoN node
    // forgets about us for whatever
    // reason.
    }
    logger.info("we're not yet registered. Registering with WoN node {} under ownerApplicationId {}", wonNodeURI, ownerApplicationId);
    String nodeGeneratedOwnerApplicationId = registrationClient.register(wonNodeURI.toString());
    if (!ownerApplicationId.equals(nodeGeneratedOwnerApplicationId)) {
        throw new java.lang.IllegalStateException("WoN node " + wonNodeURI + " generated an ownerApplicationId that differs from" + " ours. Node generated: " + nodeGeneratedOwnerApplicationId + ", we " + "generated: " + ownerApplicationId);
    }
    logger.debug("registered with WoN node: " + wonNodeURI + ",  ownerappID: " + ownerApplicationId);
    camelConfiguration = configureCamelEndpoint(wonNodeURI, ownerApplicationId);
    storeWonNode(ownerApplicationId, camelConfiguration, wonNodeURI);
    configureRemoteEndpointForOwnerApplication(ownerApplicationId, getProtocolCamelConfigurator().getEndpoint(wonNodeURI));
    logger.info("connected with WoN node: : " + wonNodeURI);
}
Also used : WonNode(won.protocol.model.WonNode) CamelConfiguration(won.protocol.jms.CamelConfiguration) CamelConfigurationFailedException(won.protocol.exception.CamelConfigurationFailedException) NoSuchConnectionException(won.protocol.exception.NoSuchConnectionException) CertificateException(java.security.cert.CertificateException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

CamelConfiguration (won.protocol.jms.CamelConfiguration)4 HashMap (java.util.HashMap)2 WonNode (won.protocol.model.WonNode)2 URI (java.net.URI)1 CertificateException (java.security.cert.CertificateException)1 ExecutionException (java.util.concurrent.ExecutionException)1 CamelConfigurationFailedException (won.protocol.exception.CamelConfigurationFailedException)1 NoSuchConnectionException (won.protocol.exception.NoSuchConnectionException)1