use of won.node.service.nodebehaviour.ConnectionStateChange in project webofneeds by researchstudio-sat.
the class ConnectionStateChangeReactionProcessor method process.
@Override
public void process(Exchange exchange) throws Exception {
WonMessage wonMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER);
String msgTypeDir = "[message type: " + wonMessage.getMessageType() + ", direction: " + wonMessage.getEnvelopeType() + "]";
ConnectionStateChangeBuilder stateChangeBuilder = (ConnectionStateChangeBuilder) exchange.getIn().getHeader(WonCamelConstants.CONNECTION_STATE_CHANGE_BUILDER_HEADER);
if (stateChangeBuilder == null) {
if (logger.isDebugEnabled()) {
logger.debug("no stateChangeBuilder found in exchange header, cannot check for state change " + msgTypeDir);
}
return;
}
Optional<Connection> con = getConnection(exchange, connectionService);
if (con.isPresent()) {
if (!stateChangeBuilder.canBuild()) {
stateChangeBuilder.newState(con.get().getState());
}
}
// derivation service.
if (stateChangeBuilder.canBuild()) {
ConnectionStateChange connectionStateChange = stateChangeBuilder.build();
Atom atom = atomService.getAtomRequired(con.get().getAtomURI());
if ((connectionStateChange.isConnect() || connectionStateChange.isDisconnect()) && atom.getState() == AtomState.ACTIVE) {
// trigger rematch
matcherProtocolMatcherClient.atomModified(atom.getAtomURI(), null);
logger.debug("matchers notified of connection state change {}", msgTypeDir);
} else {
logger.debug("no relevant connection state change, not notifying matchers {}", msgTypeDir);
}
} else {
logger.debug("Could not collect ConnectionStateChange information, not checking for state change {}", msgTypeDir);
}
}
Aggregations