use of akka.camel.CamelMessage in project webofneeds by researchstudio-sat.
the class NeedConsumerProtocolActor method onReceive.
@Override
public void onReceive(final Object message) throws Exception {
if (message instanceof CamelMessage) {
CamelMessage camelMsg = (CamelMessage) message;
String needUri = (String) camelMsg.getHeaders().get(MSG_HEADER_NEED_URI);
String wonNodeUri = (String) camelMsg.getHeaders().get(MSG_HEADER_WON_NODE_URI);
// monitoring code
monitoringService.startClock(MonitoringService.NEED_HINT_STOPWATCH, needUri);
// process the incoming need event
if (needUri != null && wonNodeUri != null) {
Object methodName = camelMsg.getHeaders().get(MSG_HEADER_METHODNAME);
if (methodName != null) {
log.debug("Received event '{}' for needUri '{}' and wonNeedUri '{}' and publish it to matchers", methodName, needUri, wonNodeUri);
// publish a need event to all the (distributed) matchers
NeedEvent event = null;
long crawlDate = System.currentTimeMillis();
if (methodName.equals(MSG_HEADER_METHODNAME_NEEDCREATED)) {
event = new NeedEvent(needUri, wonNodeUri, NeedEvent.TYPE.ACTIVE, crawlDate, camelMsg.body().toString(), Lang.TRIG);
pubSubMediator.tell(new DistributedPubSubMediator.Publish(event.getClass().getName(), event), getSelf());
} else if (methodName.equals(MSG_HEADER_METHODNAME_NEEDACTIVATED)) {
event = new NeedEvent(needUri, wonNodeUri, NeedEvent.TYPE.ACTIVE, crawlDate, camelMsg.body().toString(), Lang.TRIG);
pubSubMediator.tell(new DistributedPubSubMediator.Publish(event.getClass().getName(), event), getSelf());
} else if (methodName.equals(MSG_HEADER_METHODNAME_NEEDDEACTIVATED)) {
event = new NeedEvent(needUri, wonNodeUri, NeedEvent.TYPE.INACTIVE, crawlDate, camelMsg.body().toString(), Lang.TRIG);
pubSubMediator.tell(new DistributedPubSubMediator.Publish(event.getClass().getName(), event), getSelf());
} else {
unhandled(message);
}
// let the crawler save the data of this event too
ResourceCrawlUriMessage resMsg = new ResourceCrawlUriMessage(needUri, needUri, wonNodeUri, CrawlUriMessage.STATUS.SAVE, crawlDate, null);
resMsg.setSerializedResource(camelMsg.body().toString());
resMsg.setSerializationFormat(Lang.TRIG);
pubSubMediator.tell(new DistributedPubSubMediator.Publish(resMsg.getClass().getName(), resMsg), getSelf());
return;
}
}
}
unhandled(message);
}
use of akka.camel.CamelMessage in project webofneeds by researchstudio-sat.
the class HintProducerProtocolActor method onTransformOutgoingMessage.
/**
* transform hint events to camel messages that can be sent to the won node
*
* @param message supposed to be a {@link HintEvent}
* @return
*/
@Override
public Object onTransformOutgoingMessage(Object message) {
HintEvent hint = (HintEvent) message;
Map<String, Object> headers = new HashMap<>();
headers.put("needURI", hint.getFromNeedUri());
headers.put("otherNeedURI", hint.getToNeedUri());
headers.put("score", String.valueOf(hint.getScore()));
headers.put("originator", hint.getMatcherUri());
// headers.put("content", RdfUtils.toString(hint.deserializeExplanationModel()));
// headers.put("remoteBrokerEndpoint", localBrokerUri);
headers.put("methodName", "hint");
WonMessage wonMessage = createHintWonMessage(hint);
Object body = WonMessageEncoder.encode(wonMessage, Lang.TRIG);
CamelMessage camelMsg = new CamelMessage(body, headers);
// monitoring code
monitoringService.stopClock(MonitoringService.NEED_HINT_STOPWATCH, hint.getFromNeedUri());
log.debug("Send hint camel message {}", hint.getFromNeedUri());
return camelMsg;
}
Aggregations