use of won.protocol.model.ConnectionState in project webofneeds by researchstudio-sat.
the class LinkedDataServiceImpl method addConnectionMetadata.
private void addConnectionMetadata(final Dataset content, URI needURI, URI containerURI) {
Model model = content.getNamedModel(createDataGraphUriFromUri(containerURI));
List<Object[]> connectionCountsPerState = needRepository.getCountsPerConnectionState(needURI);
Resource containerResource = model.getResource(containerURI.toString());
for (Object[] countForState : connectionCountsPerState) {
ConnectionState stateName = (ConnectionState) countForState[0];
Long count = (Long) countForState[1];
Property countProperty = getRdfPropertyForState(stateName);
if (countProperty == null) {
logger.warn("did not recognize connection state " + stateName);
continue;
}
containerResource.addProperty(countProperty, Integer.toString(count.intValue()), XSDDatatype.XSDint);
}
}
use of won.protocol.model.ConnectionState in project webofneeds by researchstudio-sat.
the class CloseMessageFromSystemProcessor 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 system side for connection {}", wonMessage.getSenderURI());
Connection con = connectionRepository.findOneByConnectionURIForUpdate(wonMessage.getSenderURI());
ConnectionState originalState = con.getState();
// TODO: we could introduce SYSTEM_CLOSE here
con = dataService.nextConnectionState(con, ConnectionEventType.OWNER_CLOSE);
// if we know the remote connection, send a close message to the remote connection
if (con.getRemoteConnectionURI() != null) {
URI remoteNodeURI = wonNodeInformationService.getWonNodeUri(con.getRemoteConnectionURI());
URI remoteMessageUri = wonNodeInformationService.generateEventURI(remoteNodeURI);
// put the factory into the outbound message factory header. It will be used to generate the outbound message
// after the wonMessage has been processed and saved, to make sure that the outbound message contains
// all the data that we also store locally
OutboundMessageFactory outboundMessageFactory = new OutboundMessageFactory(remoteMessageUri, con);
message.setHeader(WonCamelConstants.OUTBOUND_MESSAGE_FACTORY_HEADER, outboundMessageFactory);
// 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
}
// because the FromSystem message is now in the message header, it will be
// picked up by the routing system and delivered to the owner.
// the message for the remote connection is in the outbound message header and will be
// sent to the remote connection.
}
use of won.protocol.model.ConnectionState 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
}
}
Aggregations