Search in sources :

Example 1 with ConnectionStateChange

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);
    }
}
Also used : WonMessage(won.protocol.message.WonMessage) ConnectionStateChangeBuilder(won.node.camel.processor.general.ConnectionStateChangeBuilder) ConnectionStateChange(won.node.service.nodebehaviour.ConnectionStateChange) Connection(won.protocol.model.Connection) WonCamelHelper.getConnection(won.node.camel.service.WonCamelHelper.getConnection) Atom(won.protocol.model.Atom)

Aggregations

ConnectionStateChangeBuilder (won.node.camel.processor.general.ConnectionStateChangeBuilder)1 WonCamelHelper.getConnection (won.node.camel.service.WonCamelHelper.getConnection)1 ConnectionStateChange (won.node.service.nodebehaviour.ConnectionStateChange)1 WonMessage (won.protocol.message.WonMessage)1 Atom (won.protocol.model.Atom)1 Connection (won.protocol.model.Connection)1