use of won.protocol.model.Connection in project webofneeds by researchstudio-sat.
the class BAAtomicCCCoordinatorFacetImpl method canFirstPhaseFinish.
private boolean canFirstPhaseFinish(Connection con) {
List<Connection> listOfCons = getAllCoordinatorParticipantConnections(con);
URI ownerUri = null;
URI needUri = null;
URI currentStateUri = null;
for (Connection tmpCon : listOfCons) {
ownerUri = tmpCon.getNeedURI();
needUri = tmpCon.getRemoteNeedURI();
currentStateUri = BACCState.parseString(stateManager.getStateForNeedUri(ownerUri, needUri, getFacetType().getURI()).toString()).getURI();
if (currentStateUri.toString().equals(WON_TX.STATE_ACTIVE.getURI().toString()) || currentStateUri.toString().equals(WON_TX.STATE_COMPLETING.getURI().toString()))
return false;
}
return true;
}
use of won.protocol.model.Connection in project webofneeds by researchstudio-sat.
the class BAAtomicCCCoordinatorFacetImpl method propagateSecondPhase.
private void propagateSecondPhase(Connection con) {
List<Connection> listOfCons = getAllCoordinatorParticipantConnections(con);
BACCState state;
for (Connection currentCon : listOfCons) {
state = BACCState.parseString(stateManager.getStateForNeedUri(currentCon.getNeedURI(), currentCon.getRemoteNeedURI(), getFacetType().getURI()).toString());
if (state.getPhase() == BACCState.Phase.FIRST) {
state.setPhase(BACCState.Phase.SECOND);
stateManager.setStateForNeedUri(state.getURI(), URI.create(WON_TX.PHASE_SECOND.getURI().toString()), currentCon.getNeedURI(), currentCon.getRemoteNeedURI(), getFacetType().getURI());
storeBAStateForConnection(currentCon, state.getURI());
}
}
}
use of won.protocol.model.Connection in project webofneeds by researchstudio-sat.
the class BAAtomicPCCoordinatorFacetImpl method canFirstPhaseFinish.
private boolean canFirstPhaseFinish(Connection con) {
List<Connection> listOfCons = getAllCoordinatorParticipantConnections(con);
URI ownerUri = null;
URI needUri = null;
URI currentStateUri = null;
for (Connection tmpCon : listOfCons) {
ownerUri = tmpCon.getNeedURI();
needUri = tmpCon.getRemoteNeedURI();
currentStateUri = stateManager.getStateForNeedUri(ownerUri, needUri, getFacetType().getURI());
if (currentStateUri.toString().equals(WON_TX.STATE_ACTIVE.getURI().toString()))
return false;
}
return true;
}
use of won.protocol.model.Connection in project webofneeds by researchstudio-sat.
the class BAAtomicPCCoordinatorFacetImpl method propagateSecondPhase.
private void propagateSecondPhase(Connection con) {
List<Connection> listOfCons = getAllCoordinatorParticipantConnections(con);
BAPCState state;
for (Connection currentCon : listOfCons) {
state = BAPCState.parseString(stateManager.getStateForNeedUri(currentCon.getNeedURI(), currentCon.getRemoteNeedURI(), getFacetType().getURI()).toString());
BAPCState.Phase phase = BAPCState.parsePhase(stateManager.getStatePhaseForNeedUri(currentCon.getNeedURI(), currentCon.getRemoteNeedURI(), getFacetType().getURI()).toString());
if (BAPCState.getPhaseURI(phase).toString().equals(WON_TX.PHASE_FIRST.getURI().toString())) {
state.setPhase(BAPCState.Phase.SECOND);
stateManager.setStateForNeedUri(state.getURI(), URI.create(WON_TX.PHASE_SECOND.getURI().toString()), currentCon.getNeedURI(), currentCon.getRemoteNeedURI(), getFacetType().getURI());
storeBAStateForConnection(currentCon, state.getURI());
}
}
}
use of won.protocol.model.Connection 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.
}
Aggregations