use of won.protocol.model.Connection in project webofneeds by researchstudio-sat.
the class SendMessageFromOwnerProcessor method process.
public void process(final Exchange exchange) throws Exception {
Message message = exchange.getIn();
WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
URI connectionUri = wonMessage.getSenderURI();
if (connectionUri == null) {
throw new MissingMessagePropertyException(URI.create(WONMSG.SENDER_PROPERTY.toString()));
}
Connection con = connectionRepository.findOneByConnectionURIForUpdate(connectionUri);
if (con.getState() != ConnectionState.CONNECTED) {
throw new IllegalMessageForConnectionStateException(connectionUri, "CONNECTION_MESSAGE", con.getState());
}
URI remoteMessageUri = wonNodeInformationService.generateEventURI(wonMessage.getReceiverNodeURI());
if (wonMessage.getReceiverURI() == null) {
// set the sender uri in the envelope TODO: TwoMsgs: do not set sender here
wonMessage.addMessageProperty(WONMSG.RECEIVER_PROPERTY, con.getRemoteConnectionURI());
}
// add the information about the remote message to the locally stored one
wonMessage.addMessageProperty(WONMSG.HAS_CORRESPONDING_REMOTE_MESSAGE, remoteMessageUri);
// the persister will pick it up later
// 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);
exchange.getIn().setHeader(WonCamelConstants.OUTBOUND_MESSAGE_FACTORY_HEADER, outboundMessageFactory);
}
use of won.protocol.model.Connection in project webofneeds by researchstudio-sat.
the class CoordinatorFacetImpl method connectFromOwner.
@Override
public void connectFromOwner(final Connection con, final Model content, final WonMessage wonMessage) throws NoSuchNeedException, IllegalMessageForNeedStateException, ConnectionAlreadyExistsException {
logger.debug("Coordinator: ConntectFromOwner");
Resource baseRes = content.getResource(content.getNsPrefixURI(""));
StmtIterator stmtIterator = baseRes.listProperties(WON.HAS_REMOTE_FACET);
if (!stmtIterator.hasNext())
throw new IllegalArgumentException("at least one RDF node must be of type won:hasRemoteFacet");
// TODO: This should just remove RemoteFacet from content and replace the value of Facet with the one from RemoteFacet
final Model remoteFacetModel = ModelFactory.createDefaultModel();
remoteFacetModel.setNsPrefix("", "no:uri");
baseRes = remoteFacetModel.createResource(remoteFacetModel.getNsPrefixURI(""));
Resource remoteFacetResource = stmtIterator.next().getObject().asResource();
baseRes.addProperty(WON.HAS_FACET, remoteFacetModel.createResource(remoteFacetResource.getURI()));
final Connection connectionForRunnable = con;
// try {
// final ListenableFuture<URI> remoteConnectionURI = needProtocolNeedService.connect(con.getRemoteNeedURI(),
// con.getNeedURI(), connectionForRunnable.getConnectionURI(), remoteFacetModel, wonMessage);
// this.executorService.execute(new Runnable(){
// @Override
// public void run() {
// try{
// if (logger.isDebugEnabled()) {
// logger.debug("saving remote connection URI");
// }
// dataService.updateRemoteConnectionURI(con, remoteConnectionURI.get());
// } catch (Exception e) {
// logger.warn("Error saving connection {}. Stacktrace follows", con);
// logger.warn("Error saving connection ", e);
// }
// }
// });
// } catch (WonProtocolException e) {
// // we can't connect the connection. we send a close back to the owner
// // TODO should we introduce a new protocol method connectionFailed (because it's not an owner deny but some protocol-level error)?
// // For now, we call the close method as if it had been called from the remote side
// // TODO: even with this workaround, it would be good to send a content along with the close (so we can explain what happened).
// // try {
// // Connection c = closeConnectionLocally(connectionForRunnable, content);
// // // ToDo (FS): should probably not be the same wonMessage!?
// // needFacingConnectionCommunicationService.close(c.getConnectionURI(), content, wonMessage);
// // } catch (NoSuchConnectionException e1) {
// // logger.warn("caught NoSuchConnectionException:", e1);
// // } catch (IllegalMessageForConnectionStateException e1) {
// // logger.warn("caught IllegalMessageForConnectionStateException:", e1);
// // }
// }
// catch (InterruptedException e) {
// e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
// } catch (ExecutionException e) {
// e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
// } catch (Exception e) {
// logger.debug("caught Exception", e);
// }
}
use of won.protocol.model.Connection in project webofneeds by researchstudio-sat.
the class ParticipantFacetImpl method connectFromNeed.
public void connectFromNeed(final Connection con, final Model content, final WonMessage wonMessage) throws NoSuchNeedException, IllegalMessageForNeedStateException, ConnectionAlreadyExistsException {
final Connection connectionForRunnable = con;
logger.debug("Participant: ConnectFromNeed");
executorService.execute(new Runnable() {
@Override
public void run() {
// TODO: use new system
// ownerProtocolOwnerService.connect(
// con.getNeedURI(), con.getRemoteNeedURI(),
// connectionForRunnable.getConnectionURI(), content, wonMessage);
}
});
}
use of won.protocol.model.Connection 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.model.Connection 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