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;
}
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);
}
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);
}
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);
}
Aggregations