use of won.protocol.message.WonMessageType in project webofneeds by researchstudio-sat.
the class ConnectionStateChangeBuilderCamelProcessor method process.
@Override
public void process(Exchange exchange) throws Exception {
ConnectionStateChangeBuilder stateChangeBuilder = new ConnectionStateChangeBuilder();
WonMessage wonMessage = getMessageRequired(exchange);
WonMessageType type = wonMessage.getMessageTypeRequired();
if (type.isResponseMessage()) {
type = wonMessage.getRespondingToMessageType();
}
if (type.isConnectionSpecificMessage()) {
Optional<Connection> con = getConnection(exchange, connectionService);
if (con.isPresent()) {
stateChangeBuilder.oldState(con.get().getState());
}
}
// put the state change builder in the header
exchange.getIn().setHeader(WonCamelConstants.CONNECTION_STATE_CHANGE_BUILDER_HEADER, stateChangeBuilder);
}
use of won.protocol.message.WonMessageType in project webofneeds by researchstudio-sat.
the class LockMessageParentWonMessageProcessor method lockParent.
private void lockParent(WonMessage message, WonMessageDirection direction) {
// try to lock the message's connection first
// * if the message is connection-specific
// * and one exists already
WonMessageType type = message.getMessageTypeRequired().isResponseMessage() ? message.getRespondingToMessageTypeRequired() : message.getMessageTypeRequired();
if (type.isConnectionSpecificMessage()) {
logger.debug("Attempting to lock connection for message {} {}", message.getMessageURI(), direction);
Optional<URI> conURI = messageService.getConnectionofMessage(message, direction);
if (conURI.isPresent()) {
logger.debug("Locking connection {} for message {} {}", new Object[] { conURI.get(), message.getMessageURI(), direction });
Optional<Connection> con = connectionRepository.findOneByConnectionURIForUpdate(conURI.get());
if (con.isPresent()) {
entityManager.refresh(con.get());
logger.debug("Locked connection {} for message {} {}", new Object[] { conURI.get(), message.getMessageURI(), direction });
logger.debug("connection: {}", con.get());
return;
} else {
logger.debug("Did not lock connection {} for message {} {}", new Object[] { conURI.get(), message.getMessageURI(), direction });
}
} else {
logger.debug("Did not find connection to lock for message {} {}", message.getMessageURI(), direction);
}
} else {
logger.debug("Not attempting to lock connection for message {} {}", message.getMessageURI(), direction);
}
logger.debug("Attempting to lock atom for message {}", message.getMessageURI());
// no connection found to lock or wanting to lock the atom too
Optional<URI> atomURI = messageService.getAtomOfMessage(message, direction);
if (atomURI.isPresent()) {
Optional<Atom> atom = atomRepository.findOneByAtomURIForUpdate(atomURI.get());
if (atom.isPresent()) {
entityManager.refresh(atom.get());
logger.debug("Locked atom {} for message {} {}", new Object[] { atom.get().getAtomURI(), message.getMessageURI(), direction });
} else {
logger.debug("Did not find atom {} to lock for message {} {}", new Object[] { atomURI.get(), message.getMessageURI(), direction });
}
} else {
logger.debug("Did not find atom to lock for message {} {}", message.getMessageURI(), direction);
}
// it's possible that we did not lock anything because
// * the message is neither atom- nor conneciton-specific
// * the message is a CREATE message - the atom doesn't exist yet
}
use of won.protocol.message.WonMessageType in project webofneeds by researchstudio-sat.
the class WonCamelHelper method getMessageType.
// // type
public static Optional<WonMessageType> getMessageType(Exchange exchange) {
Objects.requireNonNull(exchange);
URI uri = (URI) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_TYPE_HEADER);
if (uri == null) {
return Optional.empty();
}
WonMessageType type = WonMessageType.getWonMessageType(uri);
return Optional.ofNullable(type);
}
use of won.protocol.message.WonMessageType in project webofneeds by researchstudio-sat.
the class LinkedDataCacheInvalidator method process.
@Override
public WonMessage process(final WonMessage message) throws WonMessageProcessingException {
WonMessageType type = message.getMessageType();
if (type == WonMessageType.SUCCESS_RESPONSE) {
type = message.getRespondingToMessageType();
}
URI webId = message.getRecipientAtomURI();
if (type.isConnectionSpecificMessage()) {
Optional<URI> connectionURI = WonLinkedDataUtils.getConnectionURIForIncomingMessage(message, linkedDataSource);
if (connectionURI.isPresent()) {
// message was created
try {
logger.debug("invalidating events list for atom " + message.getRecipientAtomURI() + " for connection " + connectionURI.get());
URI messageContainerUri = WonRelativeUriHelper.createMessageContainerURIForConnection(connectionURI.get());
invalidate(messageContainerUri, webId);
if (type.causesConnectionStateChange()) {
invalidate(connectionURI.get(), webId);
}
} catch (Exception e) {
logger.info("Error occurred while trying to invalidate cache for {}: {}", message.getRecipientAtomURI(), e.getMessage());
}
}
}
if (type.causesNewConnection()) {
// the list of connections of the receiver atom should be invalidated, since
// these type
// of messages mean that the new connection has been created recently
logger.debug("invalidating connections list for atom " + message.getRecipientAtomURI());
try {
URI connectionsListUri = WonRelativeUriHelper.createConnectionContainerURIForAtom(message.getRecipientAtomURI());
invalidate(connectionsListUri, webId);
} catch (Exception e) {
logger.info("Error occurred while trying to invalidate cache for {}: {}", message.getRecipientAtomURI(), e.getMessage());
}
}
if (type.causesAtomStateChange()) {
invalidate(message.getRecipientAtomURI(), webId);
}
return message;
}
use of won.protocol.message.WonMessageType in project webofneeds by researchstudio-sat.
the class OwnerCallbackAdapter method process.
@Override
public WonMessage process(final WonMessage message) throws WonMessageProcessingException {
assert adaptee != null : "adaptee is not set";
logger.debug("processing message {} and calling appropriate method on adaptee", message.getMessageURI());
executor.execute(() -> {
// if we get only one message, (case succ2), we don't have an option anyway
// if we get all 3, the interesting one is the head (case: message from remote)
// if we get a message plus a response, it's the local response and we want to
// process that one.
WonMessage focalMessage = message.getFocalMessage();
WonMessageType messageType = focalMessage.getMessageType();
switch(messageType) {
case ATOM_HINT_MESSAGE:
adaptee.onAtomHintFromMatcher(focalMessage);
break;
case SOCKET_HINT_MESSAGE:
adaptee.onSocketHintFromMatcher(focalMessage);
break;
case CONNECT:
adaptee.onConnectFromOtherAtom(makeConnection(message), focalMessage);
break;
case CONNECTION_MESSAGE:
adaptee.onMessageFromOtherAtom(makeConnection(message), focalMessage);
break;
case CLOSE:
adaptee.onCloseFromOtherAtom(makeConnection(message), focalMessage);
break;
case SUCCESS_RESPONSE:
adaptee.onSuccessResponse(focalMessage.getRespondingToMessageURI(), focalMessage, Optional.ofNullable(makeConnection(message)));
break;
case FAILURE_RESPONSE:
adaptee.onFailureResponse(focalMessage.getRespondingToMessageURI(), focalMessage, Optional.ofNullable(makeConnection(message)));
break;
case CREATE_ATOM:
logger.debug("Handling CREATE_ATOM for message {}", focalMessage);
break;
case DELETE:
logger.debug("Handling DELETE for message {}", focalMessage);
break;
case REPLACE:
logger.debug("Handling REPLACE for message {}", focalMessage);
break;
case DEACTIVATE:
logger.debug("Handling DEACTIVATE for message {}", focalMessage);
break;
default:
logger.info("could not find callback method for wonMessage of type {}", focalMessage);
if (logger.isDebugEnabled()) {
logger.debug("message: {}", RdfUtils.writeDatasetToString(message.getCompleteDataset(), Lang.TRIG));
}
}
});
// return the message for further processing
return message;
}
Aggregations