use of won.protocol.message.WonMessage in project webofneeds by researchstudio-sat.
the class WonMessageCloner method process.
@Override
public void process(final Exchange exchange) throws Exception {
WonMessage message = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER);
exchange.getIn().setHeader(WonCamelConstants.MESSAGE_HEADER, WonMessage.deepCopy(message));
}
use of won.protocol.message.WonMessage in project webofneeds by researchstudio-sat.
the class WonMessageRoutes method logRouteStart.
private void logRouteStart(Exchange exchange) {
// UnitOfWork -> getRouteContext -> Route -> Id.
String routeId = exchange.getUnitOfWork().getRouteContext().getRoute().getId();
WonMessage message = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER);
if (message == null) {
logger.debug("starting route {}: [no WoNMessage]", routeId);
return;
}
logger.debug("starting route {}: {} type:{}, dir:{}, resp:{}, rem: {}", new String[] { routeId, message.getMessageURI().toString(), message.getMessageType().toString(), message.getEnvelopeType().toString(), message.getIsResponseToMessageURI() == null ? "[not a response]" : message.getIsResponseToMessageURI().toString(), message.getCorrespondingRemoteMessageURI() == null ? "[no remote message uri]" : message.getCorrespondingRemoteMessageURI().toString() });
}
use of won.protocol.message.WonMessage in project webofneeds by researchstudio-sat.
the class CloseMessageFromNodeProcessor method process.
public void process(final Exchange exchange) throws Exception {
Message message = exchange.getIn();
WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
URI connectionURIFromWonMessage = wonMessage.getReceiverURI();
Connection con = dataService.nextConnectionState(connectionURIFromWonMessage, ConnectionEventType.PARTNER_CLOSE);
}
use of won.protocol.message.WonMessage in project webofneeds by researchstudio-sat.
the class CloseMessageFromOwnerProcessor method process.
public void process(final Exchange exchange) throws Exception {
Message message = exchange.getIn();
WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
logger.debug("CLOSE received from the owner side for connection {}", wonMessage.getSenderURI());
Connection con = connectionRepository.findOneByConnectionURIForUpdate(wonMessage.getSenderURI());
ConnectionState originalState = con.getState();
con = dataService.nextConnectionState(con, ConnectionEventType.OWNER_CLOSE);
// if the connection was in suggested state, don't send a close message to the remote need
if (originalState != ConnectionState.SUGGESTED) {
// prepare the message to pass to the remote node
// create the message to send to the remote node
URI remoteMessageURI = wonNodeInformationService.generateEventURI(wonMessage.getReceiverNodeURI());
OutboundMessageCreator outboundMessageCreator = new OutboundMessageCreator(remoteMessageURI);
// put it into the 'outbound message' header (so the persister doesn't pick up the wrong one).
message.setHeader(WonCamelConstants.OUTBOUND_MESSAGE_FACTORY_HEADER, outboundMessageCreator);
// set the sender uri in the envelope TODO: TwoMsgs: do not set sender here
wonMessage.addMessageProperty(WONMSG.SENDER_PROPERTY, con.getConnectionURI());
// add the information about the corresponding message to the local one
wonMessage.addMessageProperty(WONMSG.HAS_CORRESPONDING_REMOTE_MESSAGE, remoteMessageURI);
// the persister will pick it up later from the header
}
}
use of won.protocol.message.WonMessage in project webofneeds by researchstudio-sat.
the class DebugBotIncomingMessageToEventMappingAction method handleTextMessageEvent.
private void handleTextMessageEvent(final ConnectionSpecificEvent messageEvent) {
if (messageEvent instanceof MessageEvent) {
EventListenerContext ctx = getEventListenerContext();
EventBus bus = ctx.getEventBus();
Connection con = ((BaseNeedAndConnectionSpecificEvent) messageEvent).getCon();
WonMessage msg = ((MessageEvent) messageEvent).getWonMessage();
String message = extractTextMessageFromWonMessage(msg);
try {
if (message == null) {
Model messageModel = WonRdfUtils.MessageUtils.textMessage("Whatever you sent me there, it was not a normal text message. I'm expecting a <message> won:hasTextMessage \"Some text\" triple in that message.");
bus.publish(new ConnectionMessageCommandEvent(con, messageModel));
} else if (PATTERN_USAGE.matcher(message).matches()) {
bus.publish(new UsageDebugCommandEvent(con));
} else if (PATTERN_HINT.matcher(message).matches()) {
Model messageModel = WonRdfUtils.MessageUtils.textMessage("Ok, I'll create a new need and make it send a hint to you.");
bus.publish(new ConnectionMessageCommandEvent(con, messageModel));
bus.publish(new HintDebugCommandEvent(con));
} else if (PATTERN_CONNECT.matcher(message).matches()) {
Model messageModel = WonRdfUtils.MessageUtils.textMessage("Ok, I'll create a new need and make it send a connect to you.");
bus.publish(new ConnectionMessageCommandEvent(con, messageModel));
bus.publish(new ConnectDebugCommandEvent(con));
} else if (PATTERN_CLOSE.matcher(message).matches()) {
Model messageModel = WonRdfUtils.MessageUtils.textMessage("Ok, I'll close this connection");
bus.publish(new ConnectionMessageCommandEvent(con, messageModel));
bus.publish(new CloseCommandEvent(con));
} else if (PATTERN_DEACTIVATE.matcher(message).matches()) {
Model messageModel = WonRdfUtils.MessageUtils.textMessage("Ok, I'll deactivate this need. This will close the connection we are currently talking on.");
bus.publish(new ConnectionMessageCommandEvent(con, messageModel));
bus.publish(new DeactivateNeedCommandEvent(con.getNeedURI()));
} else if (PATTERN_CHATTY_ON.matcher(message).matches()) {
Model messageModel = WonRdfUtils.MessageUtils.textMessage("Ok, I'll send you messages spontaneously from time to time.");
bus.publish(new ConnectionMessageCommandEvent(con, messageModel));
bus.publish(new SetChattinessDebugCommandEvent(con, true));
} else if (PATTERN_CHATTY_OFF.matcher(message).matches()) {
Model messageModel = WonRdfUtils.MessageUtils.textMessage("Ok, from now on I will be quiet and only respond to your messages.");
bus.publish(new ConnectionMessageCommandEvent(con, messageModel));
bus.publish(new SetChattinessDebugCommandEvent(con, false));
} else if (PATTERN_CACHE_EAGER.matcher(message).matches()) {
Model messageModel = WonRdfUtils.MessageUtils.textMessage("Ok, I'll put any message I receive or send into the RDF cache. This slows down message processing in general, but operations that require crawling connection data will be faster.");
bus.publish(new SetCacheEagernessCommandEvent(true));
bus.publish(new ConnectionMessageCommandEvent(con, messageModel));
} else if (PATTERN_CACHE_LAZY.matcher(message).matches()) {
Model messageModel = WonRdfUtils.MessageUtils.textMessage("Ok, I won't put messages I receive or send into the RDF cache. This speeds up message processing in general, but operations that require crawling connection data will be slowed down.");
bus.publish(new SetCacheEagernessCommandEvent(false));
bus.publish(new ConnectionMessageCommandEvent(con, messageModel));
} else if (PATTERN_SEND_N.matcher(message).matches()) {
Matcher m = PATTERN_SEND_N.matcher(message);
m.find();
String nStr = m.group(1);
int n = Integer.parseInt(nStr);
bus.publish(new SendNDebugCommandEvent(con, n));
} else if (PATTERN_VALIDATE.matcher(message).matches()) {
validate(ctx, bus, con);
} else if (PATTERN_RETRACT.matcher(message).matches()) {
Matcher m = PATTERN_RETRACT.matcher(message);
m.matches();
boolean useWrongSender = m.group(3) != null;
boolean retractProposes = m.group(4) != null;
retract(ctx, bus, con, useWrongSender, retractProposes);
} else if (PATTERN_REJECT.matcher(message).matches()) {
Matcher m = PATTERN_REJECT.matcher(message);
m.matches();
boolean useWrongSender = m.group(2) != null;
reject(ctx, bus, con, useWrongSender);
} else if (PATTERN_PROPOSE.matcher(message).matches()) {
Matcher m = PATTERN_PROPOSE.matcher(message);
m.matches();
boolean my = m.group(3) != null;
boolean any = m.group(4) != null;
int count = m.group(5) == null ? 1 : Integer.parseInt(m.group(5));
propose(ctx, bus, con, any || !my, any || my, count);
} else if (PATTERN_ACCEPT.matcher(message).matches()) {
accept(ctx, bus, con);
} else if (PATTERN_CANCEL.matcher(message).matches()) {
cancel(ctx, bus, con);
} else {
// default: answer with eliza.
bus.publish(new MessageToElizaEvent(con, message));
}
} catch (Exception e) {
// error: send an error message
Model messageModel = WonRdfUtils.MessageUtils.textMessage("Did not understand your command '" + message + "': " + e.getClass().getSimpleName() + ":" + e.getMessage());
bus.publish(new ConnectionMessageCommandEvent(con, messageModel));
}
}
}
Aggregations